@@ -53,17 +53,9 @@ protected function setUp(): void {
53
53
54
54
$ this ->user = $ this ->createMock (IUser::class);
55
55
$ this ->ruleManager = $ this ->createMock (RuleManager::class);
56
- $ rootMountPoint = $ this ->createMock (IMountPoint::class);
57
- $ rootMountPoint ->method ('getNumericStorageId ' )
58
- ->willReturn (1 );
59
- $ rootFolder = $ this ->createMock (IRootFolder::class);
60
- $ rootFolder ->method ('getMountPoint ' )
61
- ->willReturn ($ rootMountPoint );
62
56
$ this ->trashManager = $ this ->createMock (TrashManager::class);
63
- $ this ->aclManager = new ACLManager ($ this ->ruleManager , $ this ->trashManager , $ this ->user , function () use ($ rootFolder ) {
64
- return $ rootFolder ;
65
- });
66
- $ this ->dummyMapping = $ this ->createMock (IUserMapping::class);
57
+ $ this ->aclManager = $ this ->getAclManager ();
58
+ $ this ->dummyMapping = $ this ->createMapping ('dummy ' );
67
59
68
60
$ this ->ruleManager ->method ('getRulesForFilesByPath ' )
69
61
->willReturnCallback (function (IUser $ user , int $ storageId , array $ paths ) {
@@ -77,6 +69,27 @@ protected function setUp(): void {
77
69
});
78
70
}
79
71
72
+ private function createMapping (string $ id ): IUserMapping {
73
+ $ mapping = $ this ->createMock (IUserMapping::class);
74
+ $ mapping ->method ('getType ' )->willReturn ('dummy ' );
75
+ $ mapping ->method ('getId ' )->willReturn ($ id );
76
+ $ mapping ->method ('getDisplayName ' )->willReturn ("display name for $ id " );
77
+ return $ mapping ;
78
+ }
79
+
80
+ private function getAclManager (bool $ perUserMerge = false ) {
81
+ $ rootMountPoint = $ this ->createMock (IMountPoint::class);
82
+ $ rootMountPoint ->method ('getNumericStorageId ' )
83
+ ->willReturn (1 );
84
+ $ rootFolder = $ this ->createMock (IRootFolder::class);
85
+ $ rootFolder ->method ('getMountPoint ' )
86
+ ->willReturn ($ rootMountPoint );
87
+
88
+ return new ACLManager ($ this ->ruleManager , $ this ->trashManager , $ this ->user , function () use ($ rootFolder ) {
89
+ return $ rootFolder ;
90
+ }, null , $ perUserMerge );
91
+ }
92
+
80
93
public function testGetACLPermissionsForPathNoRules () {
81
94
$ this ->rules = [];
82
95
$ this ->assertEquals (Constants::PERMISSION_ALL , $ this ->aclManager ->getACLPermissionsForPath ('foo ' ));
@@ -85,19 +98,27 @@ public function testGetACLPermissionsForPathNoRules() {
85
98
public function testGetACLPermissionsForPath () {
86
99
$ this ->rules = [
87
100
'foo ' => [
88
- new Rule ($ this ->dummyMapping , 10 , Constants::PERMISSION_READ + Constants::PERMISSION_UPDATE , Constants::PERMISSION_READ ), // read only
89
- new Rule ($ this ->dummyMapping , 10 , Constants::PERMISSION_SHARE , 0 ) // deny share
101
+ new Rule ($ this ->createMapping ( ' 1 ' ) , 10 , Constants::PERMISSION_READ + Constants::PERMISSION_UPDATE , Constants::PERMISSION_READ ), // read only
102
+ new Rule ($ this ->createMapping ( ' 2 ' ) , 10 , Constants::PERMISSION_SHARE , 0 ) // deny share
90
103
],
91
104
'foo/bar ' => [
92
- new Rule ($ this ->dummyMapping , 10 , Constants::PERMISSION_UPDATE , Constants::PERMISSION_UPDATE ) // add write
105
+ new Rule ($ this ->createMapping ( ' 1 ' ) , 10 , Constants::PERMISSION_UPDATE , Constants::PERMISSION_UPDATE ) // add write
93
106
],
94
107
'foo/bar/sub ' => [
95
- new Rule ($ this ->dummyMapping , 10 , Constants::PERMISSION_SHARE , Constants::PERMISSION_SHARE ) // add share
96
- ]
108
+ new Rule ($ this ->createMapping ('1 ' ), 10 , Constants::PERMISSION_SHARE , Constants::PERMISSION_SHARE ) // add share
109
+ ],
110
+ 'foo/blocked ' => [
111
+ new Rule ($ this ->createMapping ('2 ' ), 10 , Constants::PERMISSION_READ , 0 ) // remove read
112
+ ],
113
+ 'foo/blocked2 ' => [
114
+ new Rule ($ this ->createMapping ('1 ' ), 10 , Constants::PERMISSION_READ , 0 ) // remove read
115
+ ],
97
116
];
98
117
$ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE - Constants::PERMISSION_UPDATE , $ this ->aclManager ->getACLPermissionsForPath ('foo ' ));
99
118
$ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE , $ this ->aclManager ->getACLPermissionsForPath ('foo/bar ' ));
100
119
$ this ->assertEquals (Constants::PERMISSION_ALL , $ this ->aclManager ->getACLPermissionsForPath ('foo/bar/sub ' ));
120
+ $ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE - Constants::PERMISSION_UPDATE - Constants::PERMISSION_READ , $ this ->aclManager ->getACLPermissionsForPath ('foo/blocked ' ));
121
+ $ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE - Constants::PERMISSION_UPDATE - Constants::PERMISSION_READ , $ this ->aclManager ->getACLPermissionsForPath ('foo/blocked2 ' ));
101
122
}
102
123
103
124
public function testGetACLPermissionsForPathInTrashbin () {
@@ -127,4 +148,33 @@ public function testGetACLPermissionsForPathInTrashbin() {
127
148
]);
128
149
$ this ->assertEquals (Constants::PERMISSION_ALL , $ this ->aclManager ->getACLPermissionsForPath ('__groupfolders/trash/1/subfolder2.d1700752274/coucou.md ' ));
129
150
}
151
+
152
+
153
+
154
+ public function testGetACLPermissionsForPathPerUserMerge () {
155
+ $ aclManager = $ this ->getAclManager (true );
156
+ $ this ->rules = [
157
+ 'foo ' => [
158
+ new Rule ($ this ->createMapping ('1 ' ), 10 , Constants::PERMISSION_READ + Constants::PERMISSION_UPDATE , Constants::PERMISSION_READ ), // read only
159
+ new Rule ($ this ->createMapping ('2 ' ), 10 , Constants::PERMISSION_SHARE , 0 ) // deny share
160
+ ],
161
+ 'foo/bar ' => [
162
+ new Rule ($ this ->createMapping ('1 ' ), 10 , Constants::PERMISSION_UPDATE , Constants::PERMISSION_UPDATE ) // add write
163
+ ],
164
+ 'foo/bar/sub ' => [
165
+ new Rule ($ this ->createMapping ('1 ' ), 10 , Constants::PERMISSION_SHARE , Constants::PERMISSION_SHARE ) // add share
166
+ ],
167
+ 'foo/blocked ' => [
168
+ new Rule ($ this ->createMapping ('2 ' ), 10 , Constants::PERMISSION_READ , 0 ) // remove read
169
+ ],
170
+ 'foo/blocked2 ' => [
171
+ new Rule ($ this ->createMapping ('1 ' ), 10 , Constants::PERMISSION_READ , 0 ) // remove read
172
+ ],
173
+ ];
174
+ $ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE - Constants::PERMISSION_UPDATE , $ aclManager ->getACLPermissionsForPath ('foo ' ));
175
+ $ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE , $ aclManager ->getACLPermissionsForPath ('foo/bar ' ));
176
+ $ this ->assertEquals (Constants::PERMISSION_ALL , $ aclManager ->getACLPermissionsForPath ('foo/bar/sub ' ));
177
+ $ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE - Constants::PERMISSION_UPDATE , $ aclManager ->getACLPermissionsForPath ('foo/blocked ' ));
178
+ $ this ->assertEquals (Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE - Constants::PERMISSION_UPDATE - Constants::PERMISSION_READ , $ aclManager ->getACLPermissionsForPath ('foo/blocked2 ' ));
179
+ }
130
180
}
0 commit comments