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