@@ -50,6 +50,13 @@ protected function setUp(): void {
50
50
51
51
return array_merge ($ rules , $ actualRules );
52
52
});
53
+
54
+ $ this ->ruleManager ->method ('getRulesForPrefix ' )
55
+ ->willReturnCallback (function (IUser $ user , int $ storageId , string $ prefix ) {
56
+ return array_filter ($ this ->rules , function (string $ path ) use ($ prefix ) {
57
+ return $ prefix === $ path || str_starts_with ($ path , $ prefix . '/ ' );
58
+ }, ARRAY_FILTER_USE_KEY );
59
+ });
53
60
}
54
61
55
62
private function createMapping (string $ id ): IUserMapping {
@@ -160,4 +167,67 @@ public function testGetACLPermissionsForPathPerUserMerge(): void {
160
167
$ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE - Constants::PERMISSION_UPDATE , $ aclManager ->getACLPermissionsForPath ('foo/blocked ' ));
161
168
$ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE - Constants::PERMISSION_UPDATE - Constants::PERMISSION_READ , $ aclManager ->getACLPermissionsForPath ('foo/blocked2 ' ));
162
169
}
170
+
171
+ public function testGetPermissionsForTree (): void {
172
+ $ perUserAclManager = $ this ->getAclManager (true );
173
+
174
+ $ this ->rules = [
175
+ 'foo ' => [
176
+ new Rule ($ this ->createMapping ('1 ' ), 10 , Constants::PERMISSION_ALL , Constants::PERMISSION_ALL ),
177
+ ],
178
+ 'foo/bar ' => [
179
+ new Rule ($ this ->createMapping ('2 ' ), 10 , Constants::PERMISSION_DELETE , 0 ) // remove delete
180
+ ],
181
+ 'foo/bar/asd ' => [
182
+ new Rule ($ this ->createMapping ('2 ' ), 10 , Constants::PERMISSION_DELETE , Constants::PERMISSION_DELETE ) // re-add delete
183
+ ],
184
+ ];
185
+ $ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE , $ this ->aclManager ->getPermissionsForTree ('foo ' ));
186
+ $ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE , $ this ->aclManager ->getPermissionsForTree ('foo/bar ' ));
187
+
188
+ $ this ->assertEquals (Constants::PERMISSION_ALL , $ perUserAclManager ->getACLPermissionsForPath ('foo ' ));
189
+ $ this ->assertEquals (Constants::PERMISSION_ALL , $ perUserAclManager ->getACLPermissionsForPath ('foo/bar ' ));
190
+ $ this ->assertEquals (Constants::PERMISSION_ALL , $ perUserAclManager ->getACLPermissionsForPath ('foo/bar/asd ' ));
191
+
192
+ $ this ->assertEquals (Constants::PERMISSION_ALL , $ perUserAclManager ->getPermissionsForTree ('foo ' ));
193
+ $ this ->assertEquals (Constants::PERMISSION_ALL , $ perUserAclManager ->getPermissionsForTree ('foo/bar ' ));
194
+
195
+ $ this ->rules = [
196
+ 'foo2 ' => [
197
+ new Rule ($ this ->createMapping ('1 ' ), 10 , Constants::PERMISSION_ALL , Constants::PERMISSION_ALL ),
198
+ ],
199
+ 'foo2/bar ' => [
200
+ new Rule ($ this ->createMapping ('1 ' ), 10 , Constants::PERMISSION_DELETE , 0 ) // remove delete
201
+ ],
202
+ 'foo2/bar/asd ' => [
203
+ new Rule ($ this ->createMapping ('2 ' ), 10 , Constants::PERMISSION_DELETE , Constants::PERMISSION_DELETE ) // re-add delete
204
+ ],
205
+ ];
206
+
207
+ $ this ->assertEquals (Constants::PERMISSION_ALL , $ perUserAclManager ->getACLPermissionsForPath ('foo2 ' ));
208
+ $ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE , $ perUserAclManager ->getACLPermissionsForPath ('foo2/bar ' ));
209
+ $ this ->assertEquals (Constants::PERMISSION_ALL , $ perUserAclManager ->getACLPermissionsForPath ('foo2/bar/asd ' ));
210
+
211
+ $ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE , $ perUserAclManager ->getPermissionsForTree ('foo2 ' ));
212
+ $ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE , $ perUserAclManager ->getPermissionsForTree ('foo2/bar ' ));
213
+
214
+ $ this ->rules = [
215
+ 'foo3 ' => [
216
+ new Rule ($ this ->createMapping ('1 ' ), 10 , Constants::PERMISSION_ALL , Constants::PERMISSION_ALL ),
217
+ ],
218
+ 'foo3/bar ' => [
219
+ new Rule ($ this ->createMapping ('1 ' ), 10 , Constants::PERMISSION_DELETE , 0 ) // remove delete
220
+ ],
221
+ 'foo3/bar/asd ' => [
222
+ new Rule ($ this ->createMapping ('1 ' ), 10 , Constants::PERMISSION_DELETE , Constants::PERMISSION_DELETE ) // re-add delete
223
+ ],
224
+ ];
225
+
226
+ $ this ->assertEquals (Constants::PERMISSION_ALL , $ perUserAclManager ->getACLPermissionsForPath ('foo3 ' ));
227
+ $ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE , $ perUserAclManager ->getACLPermissionsForPath ('foo3/bar ' ));
228
+ $ this ->assertEquals (Constants::PERMISSION_ALL , $ perUserAclManager ->getACLPermissionsForPath ('foo3/bar/asd ' ));
229
+
230
+ $ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE , $ perUserAclManager ->getPermissionsForTree ('foo3 ' ));
231
+ $ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE , $ perUserAclManager ->getPermissionsForTree ('foo3/bar ' ));
232
+ }
163
233
}
0 commit comments