@@ -18,300 +18,300 @@ |
||
| 18 | 18 | use Sabre\DAVACL\PrincipalBackend\BackendInterface; |
| 19 | 19 | |
| 20 | 20 | class GroupPrincipalBackend implements BackendInterface { |
| 21 | - public const PRINCIPAL_PREFIX = 'principals/groups'; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @param IGroupManager $groupManager |
|
| 25 | - * @param IUserSession $userSession |
|
| 26 | - * @param IShareManager $shareManager |
|
| 27 | - */ |
|
| 28 | - public function __construct( |
|
| 29 | - private IGroupManager $groupManager, |
|
| 30 | - private IUserSession $userSession, |
|
| 31 | - private IShareManager $shareManager, |
|
| 32 | - private IConfig $config, |
|
| 33 | - ) { |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Returns a list of principals based on a prefix. |
|
| 38 | - * |
|
| 39 | - * This prefix will often contain something like 'principals'. You are only |
|
| 40 | - * expected to return principals that are in this base path. |
|
| 41 | - * |
|
| 42 | - * You are expected to return at least a 'uri' for every user, you can |
|
| 43 | - * return any additional properties if you wish so. Common properties are: |
|
| 44 | - * {DAV:}displayname |
|
| 45 | - * |
|
| 46 | - * @param string $prefixPath |
|
| 47 | - * @return string[] |
|
| 48 | - */ |
|
| 49 | - public function getPrincipalsByPrefix($prefixPath) { |
|
| 50 | - $principals = []; |
|
| 51 | - |
|
| 52 | - if ($prefixPath === self::PRINCIPAL_PREFIX) { |
|
| 53 | - foreach ($this->groupManager->search('') as $group) { |
|
| 54 | - if (!$group->hideFromCollaboration()) { |
|
| 55 | - $principals[] = $this->groupToPrincipal($group); |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - return $principals; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Returns a specific principal, specified by it's path. |
|
| 65 | - * The returned structure should be the exact same as from |
|
| 66 | - * getPrincipalsByPrefix. |
|
| 67 | - * |
|
| 68 | - * @param string $path |
|
| 69 | - * @return array |
|
| 70 | - */ |
|
| 71 | - public function getPrincipalByPath($path) { |
|
| 72 | - $elements = explode('/', $path, 3); |
|
| 73 | - if ($elements[0] !== 'principals') { |
|
| 74 | - return null; |
|
| 75 | - } |
|
| 76 | - if ($elements[1] !== 'groups') { |
|
| 77 | - return null; |
|
| 78 | - } |
|
| 79 | - $name = urldecode($elements[2]); |
|
| 80 | - $group = $this->groupManager->get($name); |
|
| 81 | - |
|
| 82 | - if ($group !== null && !$group->hideFromCollaboration()) { |
|
| 83 | - return $this->groupToPrincipal($group); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - return null; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Returns the list of members for a group-principal |
|
| 91 | - * |
|
| 92 | - * @param string $principal |
|
| 93 | - * @return array |
|
| 94 | - * @throws Exception |
|
| 95 | - */ |
|
| 96 | - public function getGroupMemberSet($principal) { |
|
| 97 | - $elements = explode('/', $principal); |
|
| 98 | - if ($elements[0] !== 'principals') { |
|
| 99 | - return []; |
|
| 100 | - } |
|
| 101 | - if ($elements[1] !== 'groups') { |
|
| 102 | - return []; |
|
| 103 | - } |
|
| 104 | - $name = $elements[2]; |
|
| 105 | - $group = $this->groupManager->get($name); |
|
| 106 | - |
|
| 107 | - if (is_null($group)) { |
|
| 108 | - return []; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return array_map(function ($user) { |
|
| 112 | - return $this->userToPrincipal($user); |
|
| 113 | - }, $group->getUsers()); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Returns the list of groups a principal is a member of |
|
| 118 | - * |
|
| 119 | - * @param string $principal |
|
| 120 | - * @return array |
|
| 121 | - * @throws Exception |
|
| 122 | - */ |
|
| 123 | - public function getGroupMembership($principal) { |
|
| 124 | - return []; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Updates the list of group members for a group principal. |
|
| 129 | - * |
|
| 130 | - * The principals should be passed as a list of uri's. |
|
| 131 | - * |
|
| 132 | - * @param string $principal |
|
| 133 | - * @param string[] $members |
|
| 134 | - * @throws Exception |
|
| 135 | - */ |
|
| 136 | - public function setGroupMemberSet($principal, array $members) { |
|
| 137 | - throw new Exception('Setting members of the group is not supported yet'); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @param string $path |
|
| 142 | - * @param PropPatch $propPatch |
|
| 143 | - * @return int |
|
| 144 | - */ |
|
| 145 | - public function updatePrincipal($path, PropPatch $propPatch) { |
|
| 146 | - return 0; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param string $prefixPath |
|
| 151 | - * @param array $searchProperties |
|
| 152 | - * @param string $test |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 155 | - public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
| 156 | - $results = []; |
|
| 157 | - |
|
| 158 | - if (\count($searchProperties) === 0) { |
|
| 159 | - return []; |
|
| 160 | - } |
|
| 161 | - if ($prefixPath !== self::PRINCIPAL_PREFIX) { |
|
| 162 | - return []; |
|
| 163 | - } |
|
| 164 | - // If sharing or group sharing is disabled, return the empty array |
|
| 165 | - if (!$this->groupSharingEnabled()) { |
|
| 166 | - return []; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - // If sharing is restricted to group members only, |
|
| 170 | - // return only members that have groups in common |
|
| 171 | - $restrictGroups = false; |
|
| 172 | - if ($this->shareManager->shareWithGroupMembersOnly()) { |
|
| 173 | - $user = $this->userSession->getUser(); |
|
| 174 | - if (!$user) { |
|
| 175 | - return []; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - $restrictGroups = $this->groupManager->getUserGroupIds($user); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $searchLimit = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT); |
|
| 182 | - if ($searchLimit <= 0) { |
|
| 183 | - $searchLimit = null; |
|
| 184 | - } |
|
| 185 | - foreach ($searchProperties as $prop => $value) { |
|
| 186 | - switch ($prop) { |
|
| 187 | - case '{DAV:}displayname': |
|
| 188 | - $groups = $this->groupManager->search($value, $searchLimit); |
|
| 189 | - |
|
| 190 | - $results[] = array_reduce($groups, function (array $carry, IGroup $group) use ($restrictGroups) { |
|
| 191 | - if ($group->hideFromCollaboration()) { |
|
| 192 | - return $carry; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - $gid = $group->getGID(); |
|
| 196 | - // is sharing restricted to groups only? |
|
| 197 | - if ($restrictGroups !== false) { |
|
| 198 | - if (!\in_array($gid, $restrictGroups, true)) { |
|
| 199 | - return $carry; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - $carry[] = self::PRINCIPAL_PREFIX . '/' . urlencode($gid); |
|
| 204 | - return $carry; |
|
| 205 | - }, []); |
|
| 206 | - break; |
|
| 207 | - |
|
| 208 | - case '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set': |
|
| 209 | - // If you add support for more search properties that qualify as a user-address, |
|
| 210 | - // please also add them to the array below |
|
| 211 | - $results[] = $this->searchPrincipals(self::PRINCIPAL_PREFIX, [ |
|
| 212 | - ], 'anyof'); |
|
| 213 | - break; |
|
| 214 | - |
|
| 215 | - default: |
|
| 216 | - $results[] = []; |
|
| 217 | - break; |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - // results is an array of arrays, so this is not the first search result |
|
| 222 | - // but the results of the first searchProperty |
|
| 223 | - if (count($results) === 1) { |
|
| 224 | - return $results[0]; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - switch ($test) { |
|
| 228 | - case 'anyof': |
|
| 229 | - return array_values(array_unique(array_merge(...$results))); |
|
| 230 | - |
|
| 231 | - case 'allof': |
|
| 232 | - default: |
|
| 233 | - return array_values(array_intersect(...$results)); |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * @param string $uri |
|
| 239 | - * @param string $principalPrefix |
|
| 240 | - * @return string |
|
| 241 | - */ |
|
| 242 | - public function findByUri($uri, $principalPrefix) { |
|
| 243 | - // If sharing is disabled, return the empty array |
|
| 244 | - if (!$this->groupSharingEnabled()) { |
|
| 245 | - return null; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - // If sharing is restricted to group members only, |
|
| 249 | - // return only members that have groups in common |
|
| 250 | - $restrictGroups = false; |
|
| 251 | - if ($this->shareManager->shareWithGroupMembersOnly()) { |
|
| 252 | - $user = $this->userSession->getUser(); |
|
| 253 | - if (!$user) { |
|
| 254 | - return null; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - $restrictGroups = $this->groupManager->getUserGroupIds($user); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - if (str_starts_with($uri, 'principal:principals/groups/')) { |
|
| 261 | - $name = urlencode(substr($uri, 28)); |
|
| 262 | - if ($restrictGroups !== false && !\in_array($name, $restrictGroups, true)) { |
|
| 263 | - return null; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return substr($uri, 10); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - return null; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * @param IGroup $group |
|
| 274 | - * @return array |
|
| 275 | - */ |
|
| 276 | - protected function groupToPrincipal($group) { |
|
| 277 | - $groupId = $group->getGID(); |
|
| 278 | - // getDisplayName returns UID if none |
|
| 279 | - $displayName = $group->getDisplayName(); |
|
| 280 | - |
|
| 281 | - return [ |
|
| 282 | - 'uri' => 'principals/groups/' . urlencode($groupId), |
|
| 283 | - '{DAV:}displayname' => $displayName, |
|
| 284 | - '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'GROUP', |
|
| 285 | - ]; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * @param IUser $user |
|
| 290 | - * @return array |
|
| 291 | - */ |
|
| 292 | - protected function userToPrincipal($user) { |
|
| 293 | - $userId = $user->getUID(); |
|
| 294 | - // getDisplayName returns UID if none |
|
| 295 | - $displayName = $user->getDisplayName(); |
|
| 296 | - |
|
| 297 | - $principal = [ |
|
| 298 | - 'uri' => 'principals/users/' . $userId, |
|
| 299 | - '{DAV:}displayname' => $displayName, |
|
| 300 | - '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL', |
|
| 301 | - ]; |
|
| 302 | - |
|
| 303 | - $email = $user->getSystemEMailAddress(); |
|
| 304 | - if (!empty($email)) { |
|
| 305 | - $principal['{http://sabredav.org/ns}email-address'] = $email; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - return $principal; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * @return bool |
|
| 313 | - */ |
|
| 314 | - private function groupSharingEnabled(): bool { |
|
| 315 | - return $this->shareManager->shareApiEnabled() && $this->shareManager->allowGroupSharing(); |
|
| 316 | - } |
|
| 21 | + public const PRINCIPAL_PREFIX = 'principals/groups'; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @param IGroupManager $groupManager |
|
| 25 | + * @param IUserSession $userSession |
|
| 26 | + * @param IShareManager $shareManager |
|
| 27 | + */ |
|
| 28 | + public function __construct( |
|
| 29 | + private IGroupManager $groupManager, |
|
| 30 | + private IUserSession $userSession, |
|
| 31 | + private IShareManager $shareManager, |
|
| 32 | + private IConfig $config, |
|
| 33 | + ) { |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Returns a list of principals based on a prefix. |
|
| 38 | + * |
|
| 39 | + * This prefix will often contain something like 'principals'. You are only |
|
| 40 | + * expected to return principals that are in this base path. |
|
| 41 | + * |
|
| 42 | + * You are expected to return at least a 'uri' for every user, you can |
|
| 43 | + * return any additional properties if you wish so. Common properties are: |
|
| 44 | + * {DAV:}displayname |
|
| 45 | + * |
|
| 46 | + * @param string $prefixPath |
|
| 47 | + * @return string[] |
|
| 48 | + */ |
|
| 49 | + public function getPrincipalsByPrefix($prefixPath) { |
|
| 50 | + $principals = []; |
|
| 51 | + |
|
| 52 | + if ($prefixPath === self::PRINCIPAL_PREFIX) { |
|
| 53 | + foreach ($this->groupManager->search('') as $group) { |
|
| 54 | + if (!$group->hideFromCollaboration()) { |
|
| 55 | + $principals[] = $this->groupToPrincipal($group); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + return $principals; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Returns a specific principal, specified by it's path. |
|
| 65 | + * The returned structure should be the exact same as from |
|
| 66 | + * getPrincipalsByPrefix. |
|
| 67 | + * |
|
| 68 | + * @param string $path |
|
| 69 | + * @return array |
|
| 70 | + */ |
|
| 71 | + public function getPrincipalByPath($path) { |
|
| 72 | + $elements = explode('/', $path, 3); |
|
| 73 | + if ($elements[0] !== 'principals') { |
|
| 74 | + return null; |
|
| 75 | + } |
|
| 76 | + if ($elements[1] !== 'groups') { |
|
| 77 | + return null; |
|
| 78 | + } |
|
| 79 | + $name = urldecode($elements[2]); |
|
| 80 | + $group = $this->groupManager->get($name); |
|
| 81 | + |
|
| 82 | + if ($group !== null && !$group->hideFromCollaboration()) { |
|
| 83 | + return $this->groupToPrincipal($group); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + return null; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Returns the list of members for a group-principal |
|
| 91 | + * |
|
| 92 | + * @param string $principal |
|
| 93 | + * @return array |
|
| 94 | + * @throws Exception |
|
| 95 | + */ |
|
| 96 | + public function getGroupMemberSet($principal) { |
|
| 97 | + $elements = explode('/', $principal); |
|
| 98 | + if ($elements[0] !== 'principals') { |
|
| 99 | + return []; |
|
| 100 | + } |
|
| 101 | + if ($elements[1] !== 'groups') { |
|
| 102 | + return []; |
|
| 103 | + } |
|
| 104 | + $name = $elements[2]; |
|
| 105 | + $group = $this->groupManager->get($name); |
|
| 106 | + |
|
| 107 | + if (is_null($group)) { |
|
| 108 | + return []; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return array_map(function ($user) { |
|
| 112 | + return $this->userToPrincipal($user); |
|
| 113 | + }, $group->getUsers()); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Returns the list of groups a principal is a member of |
|
| 118 | + * |
|
| 119 | + * @param string $principal |
|
| 120 | + * @return array |
|
| 121 | + * @throws Exception |
|
| 122 | + */ |
|
| 123 | + public function getGroupMembership($principal) { |
|
| 124 | + return []; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Updates the list of group members for a group principal. |
|
| 129 | + * |
|
| 130 | + * The principals should be passed as a list of uri's. |
|
| 131 | + * |
|
| 132 | + * @param string $principal |
|
| 133 | + * @param string[] $members |
|
| 134 | + * @throws Exception |
|
| 135 | + */ |
|
| 136 | + public function setGroupMemberSet($principal, array $members) { |
|
| 137 | + throw new Exception('Setting members of the group is not supported yet'); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * @param string $path |
|
| 142 | + * @param PropPatch $propPatch |
|
| 143 | + * @return int |
|
| 144 | + */ |
|
| 145 | + public function updatePrincipal($path, PropPatch $propPatch) { |
|
| 146 | + return 0; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @param string $prefixPath |
|
| 151 | + * @param array $searchProperties |
|
| 152 | + * @param string $test |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | + public function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
| 156 | + $results = []; |
|
| 157 | + |
|
| 158 | + if (\count($searchProperties) === 0) { |
|
| 159 | + return []; |
|
| 160 | + } |
|
| 161 | + if ($prefixPath !== self::PRINCIPAL_PREFIX) { |
|
| 162 | + return []; |
|
| 163 | + } |
|
| 164 | + // If sharing or group sharing is disabled, return the empty array |
|
| 165 | + if (!$this->groupSharingEnabled()) { |
|
| 166 | + return []; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + // If sharing is restricted to group members only, |
|
| 170 | + // return only members that have groups in common |
|
| 171 | + $restrictGroups = false; |
|
| 172 | + if ($this->shareManager->shareWithGroupMembersOnly()) { |
|
| 173 | + $user = $this->userSession->getUser(); |
|
| 174 | + if (!$user) { |
|
| 175 | + return []; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + $restrictGroups = $this->groupManager->getUserGroupIds($user); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $searchLimit = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT); |
|
| 182 | + if ($searchLimit <= 0) { |
|
| 183 | + $searchLimit = null; |
|
| 184 | + } |
|
| 185 | + foreach ($searchProperties as $prop => $value) { |
|
| 186 | + switch ($prop) { |
|
| 187 | + case '{DAV:}displayname': |
|
| 188 | + $groups = $this->groupManager->search($value, $searchLimit); |
|
| 189 | + |
|
| 190 | + $results[] = array_reduce($groups, function (array $carry, IGroup $group) use ($restrictGroups) { |
|
| 191 | + if ($group->hideFromCollaboration()) { |
|
| 192 | + return $carry; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + $gid = $group->getGID(); |
|
| 196 | + // is sharing restricted to groups only? |
|
| 197 | + if ($restrictGroups !== false) { |
|
| 198 | + if (!\in_array($gid, $restrictGroups, true)) { |
|
| 199 | + return $carry; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + $carry[] = self::PRINCIPAL_PREFIX . '/' . urlencode($gid); |
|
| 204 | + return $carry; |
|
| 205 | + }, []); |
|
| 206 | + break; |
|
| 207 | + |
|
| 208 | + case '{urn:ietf:params:xml:ns:caldav}calendar-user-address-set': |
|
| 209 | + // If you add support for more search properties that qualify as a user-address, |
|
| 210 | + // please also add them to the array below |
|
| 211 | + $results[] = $this->searchPrincipals(self::PRINCIPAL_PREFIX, [ |
|
| 212 | + ], 'anyof'); |
|
| 213 | + break; |
|
| 214 | + |
|
| 215 | + default: |
|
| 216 | + $results[] = []; |
|
| 217 | + break; |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + // results is an array of arrays, so this is not the first search result |
|
| 222 | + // but the results of the first searchProperty |
|
| 223 | + if (count($results) === 1) { |
|
| 224 | + return $results[0]; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + switch ($test) { |
|
| 228 | + case 'anyof': |
|
| 229 | + return array_values(array_unique(array_merge(...$results))); |
|
| 230 | + |
|
| 231 | + case 'allof': |
|
| 232 | + default: |
|
| 233 | + return array_values(array_intersect(...$results)); |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * @param string $uri |
|
| 239 | + * @param string $principalPrefix |
|
| 240 | + * @return string |
|
| 241 | + */ |
|
| 242 | + public function findByUri($uri, $principalPrefix) { |
|
| 243 | + // If sharing is disabled, return the empty array |
|
| 244 | + if (!$this->groupSharingEnabled()) { |
|
| 245 | + return null; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + // If sharing is restricted to group members only, |
|
| 249 | + // return only members that have groups in common |
|
| 250 | + $restrictGroups = false; |
|
| 251 | + if ($this->shareManager->shareWithGroupMembersOnly()) { |
|
| 252 | + $user = $this->userSession->getUser(); |
|
| 253 | + if (!$user) { |
|
| 254 | + return null; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + $restrictGroups = $this->groupManager->getUserGroupIds($user); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + if (str_starts_with($uri, 'principal:principals/groups/')) { |
|
| 261 | + $name = urlencode(substr($uri, 28)); |
|
| 262 | + if ($restrictGroups !== false && !\in_array($name, $restrictGroups, true)) { |
|
| 263 | + return null; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return substr($uri, 10); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + return null; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * @param IGroup $group |
|
| 274 | + * @return array |
|
| 275 | + */ |
|
| 276 | + protected function groupToPrincipal($group) { |
|
| 277 | + $groupId = $group->getGID(); |
|
| 278 | + // getDisplayName returns UID if none |
|
| 279 | + $displayName = $group->getDisplayName(); |
|
| 280 | + |
|
| 281 | + return [ |
|
| 282 | + 'uri' => 'principals/groups/' . urlencode($groupId), |
|
| 283 | + '{DAV:}displayname' => $displayName, |
|
| 284 | + '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'GROUP', |
|
| 285 | + ]; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + /** |
|
| 289 | + * @param IUser $user |
|
| 290 | + * @return array |
|
| 291 | + */ |
|
| 292 | + protected function userToPrincipal($user) { |
|
| 293 | + $userId = $user->getUID(); |
|
| 294 | + // getDisplayName returns UID if none |
|
| 295 | + $displayName = $user->getDisplayName(); |
|
| 296 | + |
|
| 297 | + $principal = [ |
|
| 298 | + 'uri' => 'principals/users/' . $userId, |
|
| 299 | + '{DAV:}displayname' => $displayName, |
|
| 300 | + '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL', |
|
| 301 | + ]; |
|
| 302 | + |
|
| 303 | + $email = $user->getSystemEMailAddress(); |
|
| 304 | + if (!empty($email)) { |
|
| 305 | + $principal['{http://sabredav.org/ns}email-address'] = $email; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + return $principal; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * @return bool |
|
| 313 | + */ |
|
| 314 | + private function groupSharingEnabled(): bool { |
|
| 315 | + return $this->shareManager->shareApiEnabled() && $this->shareManager->allowGroupSharing(); |
|
| 316 | + } |
|
| 317 | 317 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | return []; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - return array_map(function ($user) { |
|
| 111 | + return array_map(function($user) { |
|
| 112 | 112 | return $this->userToPrincipal($user); |
| 113 | 113 | }, $group->getUsers()); |
| 114 | 114 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | case '{DAV:}displayname': |
| 188 | 188 | $groups = $this->groupManager->search($value, $searchLimit); |
| 189 | 189 | |
| 190 | - $results[] = array_reduce($groups, function (array $carry, IGroup $group) use ($restrictGroups) { |
|
| 190 | + $results[] = array_reduce($groups, function(array $carry, IGroup $group) use ($restrictGroups) { |
|
| 191 | 191 | if ($group->hideFromCollaboration()) { |
| 192 | 192 | return $carry; |
| 193 | 193 | } |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | } |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - $carry[] = self::PRINCIPAL_PREFIX . '/' . urlencode($gid); |
|
| 203 | + $carry[] = self::PRINCIPAL_PREFIX.'/'.urlencode($gid); |
|
| 204 | 204 | return $carry; |
| 205 | 205 | }, []); |
| 206 | 206 | break; |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | $displayName = $group->getDisplayName(); |
| 280 | 280 | |
| 281 | 281 | return [ |
| 282 | - 'uri' => 'principals/groups/' . urlencode($groupId), |
|
| 282 | + 'uri' => 'principals/groups/'.urlencode($groupId), |
|
| 283 | 283 | '{DAV:}displayname' => $displayName, |
| 284 | 284 | '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'GROUP', |
| 285 | 285 | ]; |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | $displayName = $user->getDisplayName(); |
| 296 | 296 | |
| 297 | 297 | $principal = [ |
| 298 | - 'uri' => 'principals/users/' . $userId, |
|
| 298 | + 'uri' => 'principals/users/'.$userId, |
|
| 299 | 299 | '{DAV:}displayname' => $displayName, |
| 300 | 300 | '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL', |
| 301 | 301 | ]; |
@@ -33,45 +33,45 @@ |
||
| 33 | 33 | use OCP\Settings\Events\DeclarativeSettingsSetValueEvent; |
| 34 | 34 | |
| 35 | 35 | class Application extends App implements IBootstrap { |
| 36 | - public const APP_ID = 'testing'; |
|
| 36 | + public const APP_ID = 'testing'; |
|
| 37 | 37 | |
| 38 | - public function __construct(array $urlParams = []) { |
|
| 39 | - parent::__construct(self::APP_ID, $urlParams); |
|
| 40 | - } |
|
| 38 | + public function __construct(array $urlParams = []) { |
|
| 39 | + parent::__construct(self::APP_ID, $urlParams); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function register(IRegistrationContext $context): void { |
|
| 43 | - $context->registerTranslationProvider(FakeTranslationProvider::class); |
|
| 44 | - $context->registerTextProcessingProvider(FakeTextProcessingProvider::class); |
|
| 45 | - $context->registerTextProcessingProvider(FakeTextProcessingProviderSync::class); |
|
| 46 | - $context->registerTextToImageProvider(FakeText2ImageProvider::class); |
|
| 42 | + public function register(IRegistrationContext $context): void { |
|
| 43 | + $context->registerTranslationProvider(FakeTranslationProvider::class); |
|
| 44 | + $context->registerTextProcessingProvider(FakeTextProcessingProvider::class); |
|
| 45 | + $context->registerTextProcessingProvider(FakeTextProcessingProviderSync::class); |
|
| 46 | + $context->registerTextToImageProvider(FakeText2ImageProvider::class); |
|
| 47 | 47 | |
| 48 | - $context->registerTaskProcessingProvider(FakeTextToTextProvider::class); |
|
| 49 | - $context->registerTaskProcessingProvider(FakeTextToTextSummaryProvider::class); |
|
| 50 | - $context->registerTaskProcessingProvider(FakeTextToImageProvider::class); |
|
| 51 | - $context->registerTaskProcessingProvider(FakeTranslateProvider::class); |
|
| 52 | - $context->registerTaskProcessingProvider(FakeTranscribeProvider::class); |
|
| 53 | - $context->registerTaskProcessingProvider(FakeContextWriteProvider::class); |
|
| 48 | + $context->registerTaskProcessingProvider(FakeTextToTextProvider::class); |
|
| 49 | + $context->registerTaskProcessingProvider(FakeTextToTextSummaryProvider::class); |
|
| 50 | + $context->registerTaskProcessingProvider(FakeTextToImageProvider::class); |
|
| 51 | + $context->registerTaskProcessingProvider(FakeTranslateProvider::class); |
|
| 52 | + $context->registerTaskProcessingProvider(FakeTranscribeProvider::class); |
|
| 53 | + $context->registerTaskProcessingProvider(FakeContextWriteProvider::class); |
|
| 54 | 54 | |
| 55 | - $context->registerFileConversionProvider(ConversionProvider::class); |
|
| 55 | + $context->registerFileConversionProvider(ConversionProvider::class); |
|
| 56 | 56 | |
| 57 | - $context->registerDeclarativeSettings(DeclarativeSettingsForm::class); |
|
| 58 | - $context->registerEventListener(DeclarativeSettingsRegisterFormEvent::class, RegisterDeclarativeSettingsListener::class); |
|
| 59 | - $context->registerEventListener(DeclarativeSettingsGetValueEvent::class, GetDeclarativeSettingsValueListener::class); |
|
| 60 | - $context->registerEventListener(DeclarativeSettingsSetValueEvent::class, SetDeclarativeSettingsValueListener::class); |
|
| 61 | - } |
|
| 57 | + $context->registerDeclarativeSettings(DeclarativeSettingsForm::class); |
|
| 58 | + $context->registerEventListener(DeclarativeSettingsRegisterFormEvent::class, RegisterDeclarativeSettingsListener::class); |
|
| 59 | + $context->registerEventListener(DeclarativeSettingsGetValueEvent::class, GetDeclarativeSettingsValueListener::class); |
|
| 60 | + $context->registerEventListener(DeclarativeSettingsSetValueEvent::class, SetDeclarativeSettingsValueListener::class); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - public function boot(IBootContext $context): void { |
|
| 64 | - $server = $context->getServerContainer(); |
|
| 65 | - $config = $server->getConfig(); |
|
| 66 | - if ($config->getAppValue(self::APP_ID, 'enable_alt_user_backend', 'no') === 'yes') { |
|
| 67 | - $userManager = $server->getUserManager(); |
|
| 63 | + public function boot(IBootContext $context): void { |
|
| 64 | + $server = $context->getServerContainer(); |
|
| 65 | + $config = $server->getConfig(); |
|
| 66 | + if ($config->getAppValue(self::APP_ID, 'enable_alt_user_backend', 'no') === 'yes') { |
|
| 67 | + $userManager = $server->getUserManager(); |
|
| 68 | 68 | |
| 69 | - // replace all user backends with this one |
|
| 70 | - $userManager->clearBackends(); |
|
| 71 | - $userManager->registerBackend($context->getAppContainer()->get(AlternativeHomeUserBackend::class)); |
|
| 72 | - } |
|
| 69 | + // replace all user backends with this one |
|
| 70 | + $userManager->clearBackends(); |
|
| 71 | + $userManager->registerBackend($context->getAppContainer()->get(AlternativeHomeUserBackend::class)); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - $groupManager = $server->get(IGroupManager::class); |
|
| 75 | - $groupManager->addBackend($server->get(HiddenGroupBackend::class)); |
|
| 76 | - } |
|
| 74 | + $groupManager = $server->get(IGroupManager::class); |
|
| 75 | + $groupManager->addBackend($server->get(HiddenGroupBackend::class)); |
|
| 76 | + } |
|
| 77 | 77 | } |
@@ -13,35 +13,35 @@ |
||
| 13 | 13 | use OCP\Group\Backend\IHideFromCollaborationBackend; |
| 14 | 14 | |
| 15 | 15 | class HiddenGroupBackend extends ABackend implements IHideFromCollaborationBackend { |
| 16 | - private string $groupName; |
|
| 16 | + private string $groupName; |
|
| 17 | 17 | |
| 18 | - public function __construct( |
|
| 19 | - string $groupName = 'hidden_group', |
|
| 20 | - ) { |
|
| 21 | - $this->groupName = $groupName; |
|
| 22 | - } |
|
| 18 | + public function __construct( |
|
| 19 | + string $groupName = 'hidden_group', |
|
| 20 | + ) { |
|
| 21 | + $this->groupName = $groupName; |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function inGroup($uid, $gid): bool { |
|
| 25 | - return false; |
|
| 26 | - } |
|
| 24 | + public function inGroup($uid, $gid): bool { |
|
| 25 | + return false; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - public function getUserGroups($uid): array { |
|
| 29 | - return []; |
|
| 30 | - } |
|
| 28 | + public function getUserGroups($uid): array { |
|
| 29 | + return []; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function getGroups($search = '', $limit = -1, $offset = 0): array { |
|
| 33 | - return $offset === 0 ? [$this->groupName] : []; |
|
| 34 | - } |
|
| 32 | + public function getGroups($search = '', $limit = -1, $offset = 0): array { |
|
| 33 | + return $offset === 0 ? [$this->groupName] : []; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public function groupExists($gid): bool { |
|
| 37 | - return $gid === $this->groupName; |
|
| 38 | - } |
|
| 36 | + public function groupExists($gid): bool { |
|
| 37 | + return $gid === $this->groupName; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0): array { |
|
| 41 | - return []; |
|
| 42 | - } |
|
| 40 | + public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0): array { |
|
| 41 | + return []; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function hideGroup(string $groupId): bool { |
|
| 45 | - return true; |
|
| 46 | - } |
|
| 44 | + public function hideGroup(string $groupId): bool { |
|
| 45 | + return true; |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -6,28 +6,28 @@ |
||
| 6 | 6 | $baseDir = $vendorDir; |
| 7 | 7 | |
| 8 | 8 | return array( |
| 9 | - 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', |
|
| 10 | - 'OCA\\Testing\\AlternativeHomeUserBackend' => $baseDir . '/../lib/AlternativeHomeUserBackend.php', |
|
| 11 | - 'OCA\\Testing\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', |
|
| 12 | - 'OCA\\Testing\\Controller\\ConfigController' => $baseDir . '/../lib/Controller/ConfigController.php', |
|
| 13 | - 'OCA\\Testing\\Controller\\LockingController' => $baseDir . '/../lib/Controller/LockingController.php', |
|
| 14 | - 'OCA\\Testing\\Controller\\RateLimitTestController' => $baseDir . '/../lib/Controller/RateLimitTestController.php', |
|
| 15 | - 'OCA\\Testing\\Conversion\\ConversionProvider' => $baseDir . '/../lib/Conversion/ConversionProvider.php', |
|
| 16 | - 'OCA\\Testing\\HiddenGroupBackend' => $baseDir . '/../lib/HiddenGroupBackend.php', |
|
| 17 | - 'OCA\\Testing\\Listener\\GetDeclarativeSettingsValueListener' => $baseDir . '/../lib/Listener/GetDeclarativeSettingsValueListener.php', |
|
| 18 | - 'OCA\\Testing\\Listener\\RegisterDeclarativeSettingsListener' => $baseDir . '/../lib/Listener/RegisterDeclarativeSettingsListener.php', |
|
| 19 | - 'OCA\\Testing\\Listener\\SetDeclarativeSettingsValueListener' => $baseDir . '/../lib/Listener/SetDeclarativeSettingsValueListener.php', |
|
| 20 | - 'OCA\\Testing\\Locking\\FakeDBLockingProvider' => $baseDir . '/../lib/Locking/FakeDBLockingProvider.php', |
|
| 21 | - 'OCA\\Testing\\Migration\\Version30000Date20240102030405' => $baseDir . '/../lib/Migration/Version30000Date20240102030405.php', |
|
| 22 | - 'OCA\\Testing\\Provider\\FakeText2ImageProvider' => $baseDir . '/../lib/Provider/FakeText2ImageProvider.php', |
|
| 23 | - 'OCA\\Testing\\Provider\\FakeTextProcessingProvider' => $baseDir . '/../lib/Provider/FakeTextProcessingProvider.php', |
|
| 24 | - 'OCA\\Testing\\Provider\\FakeTextProcessingProviderSync' => $baseDir . '/../lib/Provider/FakeTextProcessingProviderSync.php', |
|
| 25 | - 'OCA\\Testing\\Provider\\FakeTranslationProvider' => $baseDir . '/../lib/Provider/FakeTranslationProvider.php', |
|
| 26 | - 'OCA\\Testing\\Settings\\DeclarativeSettingsForm' => $baseDir . '/../lib/Settings/DeclarativeSettingsForm.php', |
|
| 27 | - 'OCA\\Testing\\TaskProcessing\\FakeContextWriteProvider' => $baseDir . '/../lib/TaskProcessing/FakeContextWriteProvider.php', |
|
| 28 | - 'OCA\\Testing\\TaskProcessing\\FakeTextToImageProvider' => $baseDir . '/../lib/TaskProcessing/FakeTextToImageProvider.php', |
|
| 29 | - 'OCA\\Testing\\TaskProcessing\\FakeTextToTextProvider' => $baseDir . '/../lib/TaskProcessing/FakeTextToTextProvider.php', |
|
| 30 | - 'OCA\\Testing\\TaskProcessing\\FakeTextToTextSummaryProvider' => $baseDir . '/../lib/TaskProcessing/FakeTextToTextSummaryProvider.php', |
|
| 31 | - 'OCA\\Testing\\TaskProcessing\\FakeTranscribeProvider' => $baseDir . '/../lib/TaskProcessing/FakeTranscribeProvider.php', |
|
| 32 | - 'OCA\\Testing\\TaskProcessing\\FakeTranslateProvider' => $baseDir . '/../lib/TaskProcessing/FakeTranslateProvider.php', |
|
| 9 | + 'Composer\\InstalledVersions' => $vendorDir.'/composer/InstalledVersions.php', |
|
| 10 | + 'OCA\\Testing\\AlternativeHomeUserBackend' => $baseDir.'/../lib/AlternativeHomeUserBackend.php', |
|
| 11 | + 'OCA\\Testing\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php', |
|
| 12 | + 'OCA\\Testing\\Controller\\ConfigController' => $baseDir.'/../lib/Controller/ConfigController.php', |
|
| 13 | + 'OCA\\Testing\\Controller\\LockingController' => $baseDir.'/../lib/Controller/LockingController.php', |
|
| 14 | + 'OCA\\Testing\\Controller\\RateLimitTestController' => $baseDir.'/../lib/Controller/RateLimitTestController.php', |
|
| 15 | + 'OCA\\Testing\\Conversion\\ConversionProvider' => $baseDir.'/../lib/Conversion/ConversionProvider.php', |
|
| 16 | + 'OCA\\Testing\\HiddenGroupBackend' => $baseDir.'/../lib/HiddenGroupBackend.php', |
|
| 17 | + 'OCA\\Testing\\Listener\\GetDeclarativeSettingsValueListener' => $baseDir.'/../lib/Listener/GetDeclarativeSettingsValueListener.php', |
|
| 18 | + 'OCA\\Testing\\Listener\\RegisterDeclarativeSettingsListener' => $baseDir.'/../lib/Listener/RegisterDeclarativeSettingsListener.php', |
|
| 19 | + 'OCA\\Testing\\Listener\\SetDeclarativeSettingsValueListener' => $baseDir.'/../lib/Listener/SetDeclarativeSettingsValueListener.php', |
|
| 20 | + 'OCA\\Testing\\Locking\\FakeDBLockingProvider' => $baseDir.'/../lib/Locking/FakeDBLockingProvider.php', |
|
| 21 | + 'OCA\\Testing\\Migration\\Version30000Date20240102030405' => $baseDir.'/../lib/Migration/Version30000Date20240102030405.php', |
|
| 22 | + 'OCA\\Testing\\Provider\\FakeText2ImageProvider' => $baseDir.'/../lib/Provider/FakeText2ImageProvider.php', |
|
| 23 | + 'OCA\\Testing\\Provider\\FakeTextProcessingProvider' => $baseDir.'/../lib/Provider/FakeTextProcessingProvider.php', |
|
| 24 | + 'OCA\\Testing\\Provider\\FakeTextProcessingProviderSync' => $baseDir.'/../lib/Provider/FakeTextProcessingProviderSync.php', |
|
| 25 | + 'OCA\\Testing\\Provider\\FakeTranslationProvider' => $baseDir.'/../lib/Provider/FakeTranslationProvider.php', |
|
| 26 | + 'OCA\\Testing\\Settings\\DeclarativeSettingsForm' => $baseDir.'/../lib/Settings/DeclarativeSettingsForm.php', |
|
| 27 | + 'OCA\\Testing\\TaskProcessing\\FakeContextWriteProvider' => $baseDir.'/../lib/TaskProcessing/FakeContextWriteProvider.php', |
|
| 28 | + 'OCA\\Testing\\TaskProcessing\\FakeTextToImageProvider' => $baseDir.'/../lib/TaskProcessing/FakeTextToImageProvider.php', |
|
| 29 | + 'OCA\\Testing\\TaskProcessing\\FakeTextToTextProvider' => $baseDir.'/../lib/TaskProcessing/FakeTextToTextProvider.php', |
|
| 30 | + 'OCA\\Testing\\TaskProcessing\\FakeTextToTextSummaryProvider' => $baseDir.'/../lib/TaskProcessing/FakeTextToTextSummaryProvider.php', |
|
| 31 | + 'OCA\\Testing\\TaskProcessing\\FakeTranscribeProvider' => $baseDir.'/../lib/TaskProcessing/FakeTranscribeProvider.php', |
|
| 32 | + 'OCA\\Testing\\TaskProcessing\\FakeTranslateProvider' => $baseDir.'/../lib/TaskProcessing/FakeTranslateProvider.php', |
|
| 33 | 33 | ); |
@@ -6,50 +6,50 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ComposerStaticInitTesting |
| 8 | 8 | { |
| 9 | - public static $prefixLengthsPsr4 = array ( |
|
| 9 | + public static $prefixLengthsPsr4 = array( |
|
| 10 | 10 | 'O' => |
| 11 | - array ( |
|
| 11 | + array( |
|
| 12 | 12 | 'OCA\\Testing\\' => 12, |
| 13 | 13 | ), |
| 14 | 14 | ); |
| 15 | 15 | |
| 16 | - public static $prefixDirsPsr4 = array ( |
|
| 16 | + public static $prefixDirsPsr4 = array( |
|
| 17 | 17 | 'OCA\\Testing\\' => |
| 18 | - array ( |
|
| 19 | - 0 => __DIR__ . '/..' . '/../lib', |
|
| 18 | + array( |
|
| 19 | + 0 => __DIR__.'/..'.'/../lib', |
|
| 20 | 20 | ), |
| 21 | 21 | ); |
| 22 | 22 | |
| 23 | - public static $classMap = array ( |
|
| 24 | - 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', |
|
| 25 | - 'OCA\\Testing\\AlternativeHomeUserBackend' => __DIR__ . '/..' . '/../lib/AlternativeHomeUserBackend.php', |
|
| 26 | - 'OCA\\Testing\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', |
|
| 27 | - 'OCA\\Testing\\Controller\\ConfigController' => __DIR__ . '/..' . '/../lib/Controller/ConfigController.php', |
|
| 28 | - 'OCA\\Testing\\Controller\\LockingController' => __DIR__ . '/..' . '/../lib/Controller/LockingController.php', |
|
| 29 | - 'OCA\\Testing\\Controller\\RateLimitTestController' => __DIR__ . '/..' . '/../lib/Controller/RateLimitTestController.php', |
|
| 30 | - 'OCA\\Testing\\Conversion\\ConversionProvider' => __DIR__ . '/..' . '/../lib/Conversion/ConversionProvider.php', |
|
| 31 | - 'OCA\\Testing\\HiddenGroupBackend' => __DIR__ . '/..' . '/../lib/HiddenGroupBackend.php', |
|
| 32 | - 'OCA\\Testing\\Listener\\GetDeclarativeSettingsValueListener' => __DIR__ . '/..' . '/../lib/Listener/GetDeclarativeSettingsValueListener.php', |
|
| 33 | - 'OCA\\Testing\\Listener\\RegisterDeclarativeSettingsListener' => __DIR__ . '/..' . '/../lib/Listener/RegisterDeclarativeSettingsListener.php', |
|
| 34 | - 'OCA\\Testing\\Listener\\SetDeclarativeSettingsValueListener' => __DIR__ . '/..' . '/../lib/Listener/SetDeclarativeSettingsValueListener.php', |
|
| 35 | - 'OCA\\Testing\\Locking\\FakeDBLockingProvider' => __DIR__ . '/..' . '/../lib/Locking/FakeDBLockingProvider.php', |
|
| 36 | - 'OCA\\Testing\\Migration\\Version30000Date20240102030405' => __DIR__ . '/..' . '/../lib/Migration/Version30000Date20240102030405.php', |
|
| 37 | - 'OCA\\Testing\\Provider\\FakeText2ImageProvider' => __DIR__ . '/..' . '/../lib/Provider/FakeText2ImageProvider.php', |
|
| 38 | - 'OCA\\Testing\\Provider\\FakeTextProcessingProvider' => __DIR__ . '/..' . '/../lib/Provider/FakeTextProcessingProvider.php', |
|
| 39 | - 'OCA\\Testing\\Provider\\FakeTextProcessingProviderSync' => __DIR__ . '/..' . '/../lib/Provider/FakeTextProcessingProviderSync.php', |
|
| 40 | - 'OCA\\Testing\\Provider\\FakeTranslationProvider' => __DIR__ . '/..' . '/../lib/Provider/FakeTranslationProvider.php', |
|
| 41 | - 'OCA\\Testing\\Settings\\DeclarativeSettingsForm' => __DIR__ . '/..' . '/../lib/Settings/DeclarativeSettingsForm.php', |
|
| 42 | - 'OCA\\Testing\\TaskProcessing\\FakeContextWriteProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeContextWriteProvider.php', |
|
| 43 | - 'OCA\\Testing\\TaskProcessing\\FakeTextToImageProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTextToImageProvider.php', |
|
| 44 | - 'OCA\\Testing\\TaskProcessing\\FakeTextToTextProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTextToTextProvider.php', |
|
| 45 | - 'OCA\\Testing\\TaskProcessing\\FakeTextToTextSummaryProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTextToTextSummaryProvider.php', |
|
| 46 | - 'OCA\\Testing\\TaskProcessing\\FakeTranscribeProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTranscribeProvider.php', |
|
| 47 | - 'OCA\\Testing\\TaskProcessing\\FakeTranslateProvider' => __DIR__ . '/..' . '/../lib/TaskProcessing/FakeTranslateProvider.php', |
|
| 23 | + public static $classMap = array( |
|
| 24 | + 'Composer\\InstalledVersions' => __DIR__.'/..'.'/composer/InstalledVersions.php', |
|
| 25 | + 'OCA\\Testing\\AlternativeHomeUserBackend' => __DIR__.'/..'.'/../lib/AlternativeHomeUserBackend.php', |
|
| 26 | + 'OCA\\Testing\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php', |
|
| 27 | + 'OCA\\Testing\\Controller\\ConfigController' => __DIR__.'/..'.'/../lib/Controller/ConfigController.php', |
|
| 28 | + 'OCA\\Testing\\Controller\\LockingController' => __DIR__.'/..'.'/../lib/Controller/LockingController.php', |
|
| 29 | + 'OCA\\Testing\\Controller\\RateLimitTestController' => __DIR__.'/..'.'/../lib/Controller/RateLimitTestController.php', |
|
| 30 | + 'OCA\\Testing\\Conversion\\ConversionProvider' => __DIR__.'/..'.'/../lib/Conversion/ConversionProvider.php', |
|
| 31 | + 'OCA\\Testing\\HiddenGroupBackend' => __DIR__.'/..'.'/../lib/HiddenGroupBackend.php', |
|
| 32 | + 'OCA\\Testing\\Listener\\GetDeclarativeSettingsValueListener' => __DIR__.'/..'.'/../lib/Listener/GetDeclarativeSettingsValueListener.php', |
|
| 33 | + 'OCA\\Testing\\Listener\\RegisterDeclarativeSettingsListener' => __DIR__.'/..'.'/../lib/Listener/RegisterDeclarativeSettingsListener.php', |
|
| 34 | + 'OCA\\Testing\\Listener\\SetDeclarativeSettingsValueListener' => __DIR__.'/..'.'/../lib/Listener/SetDeclarativeSettingsValueListener.php', |
|
| 35 | + 'OCA\\Testing\\Locking\\FakeDBLockingProvider' => __DIR__.'/..'.'/../lib/Locking/FakeDBLockingProvider.php', |
|
| 36 | + 'OCA\\Testing\\Migration\\Version30000Date20240102030405' => __DIR__.'/..'.'/../lib/Migration/Version30000Date20240102030405.php', |
|
| 37 | + 'OCA\\Testing\\Provider\\FakeText2ImageProvider' => __DIR__.'/..'.'/../lib/Provider/FakeText2ImageProvider.php', |
|
| 38 | + 'OCA\\Testing\\Provider\\FakeTextProcessingProvider' => __DIR__.'/..'.'/../lib/Provider/FakeTextProcessingProvider.php', |
|
| 39 | + 'OCA\\Testing\\Provider\\FakeTextProcessingProviderSync' => __DIR__.'/..'.'/../lib/Provider/FakeTextProcessingProviderSync.php', |
|
| 40 | + 'OCA\\Testing\\Provider\\FakeTranslationProvider' => __DIR__.'/..'.'/../lib/Provider/FakeTranslationProvider.php', |
|
| 41 | + 'OCA\\Testing\\Settings\\DeclarativeSettingsForm' => __DIR__.'/..'.'/../lib/Settings/DeclarativeSettingsForm.php', |
|
| 42 | + 'OCA\\Testing\\TaskProcessing\\FakeContextWriteProvider' => __DIR__.'/..'.'/../lib/TaskProcessing/FakeContextWriteProvider.php', |
|
| 43 | + 'OCA\\Testing\\TaskProcessing\\FakeTextToImageProvider' => __DIR__.'/..'.'/../lib/TaskProcessing/FakeTextToImageProvider.php', |
|
| 44 | + 'OCA\\Testing\\TaskProcessing\\FakeTextToTextProvider' => __DIR__.'/..'.'/../lib/TaskProcessing/FakeTextToTextProvider.php', |
|
| 45 | + 'OCA\\Testing\\TaskProcessing\\FakeTextToTextSummaryProvider' => __DIR__.'/..'.'/../lib/TaskProcessing/FakeTextToTextSummaryProvider.php', |
|
| 46 | + 'OCA\\Testing\\TaskProcessing\\FakeTranscribeProvider' => __DIR__.'/..'.'/../lib/TaskProcessing/FakeTranscribeProvider.php', |
|
| 47 | + 'OCA\\Testing\\TaskProcessing\\FakeTranslateProvider' => __DIR__.'/..'.'/../lib/TaskProcessing/FakeTranslateProvider.php', |
|
| 48 | 48 | ); |
| 49 | 49 | |
| 50 | 50 | public static function getInitializer(ClassLoader $loader) |
| 51 | 51 | { |
| 52 | - return \Closure::bind(function () use ($loader) { |
|
| 52 | + return \Closure::bind(function() use ($loader) { |
|
| 53 | 53 | $loader->prefixLengthsPsr4 = ComposerStaticInitTesting::$prefixLengthsPsr4; |
| 54 | 54 | $loader->prefixDirsPsr4 = ComposerStaticInitTesting::$prefixDirsPsr4; |
| 55 | 55 | $loader->classMap = ComposerStaticInitTesting::$classMap; |
@@ -15,55 +15,55 @@ discard block |
||
| 15 | 15 | use Psr\Http\Message\ResponseInterface; |
| 16 | 16 | |
| 17 | 17 | class PrincipalPropertySearchContext implements Context { |
| 18 | - private string $baseUrl; |
|
| 19 | - private Client $client; |
|
| 20 | - private ResponseInterface $response; |
|
| 18 | + private string $baseUrl; |
|
| 19 | + private Client $client; |
|
| 20 | + private ResponseInterface $response; |
|
| 21 | 21 | |
| 22 | - public function __construct(string $baseUrl) { |
|
| 23 | - $this->baseUrl = $baseUrl; |
|
| 22 | + public function __construct(string $baseUrl) { |
|
| 23 | + $this->baseUrl = $baseUrl; |
|
| 24 | 24 | |
| 25 | - // in case of ci deployment we take the server url from the environment |
|
| 26 | - $testServerUrl = getenv('TEST_SERVER_URL'); |
|
| 27 | - if ($testServerUrl !== false) { |
|
| 28 | - $this->baseUrl = substr($testServerUrl, 0, -5); |
|
| 29 | - } |
|
| 30 | - } |
|
| 25 | + // in case of ci deployment we take the server url from the environment |
|
| 26 | + $testServerUrl = getenv('TEST_SERVER_URL'); |
|
| 27 | + if ($testServerUrl !== false) { |
|
| 28 | + $this->baseUrl = substr($testServerUrl, 0, -5); |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** @BeforeScenario */ |
|
| 33 | - public function setUpScenario(): void { |
|
| 34 | - $this->client = $this->createGuzzleInstance(); |
|
| 35 | - } |
|
| 32 | + /** @BeforeScenario */ |
|
| 33 | + public function setUpScenario(): void { |
|
| 34 | + $this->client = $this->createGuzzleInstance(); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Create a Guzzle client with a higher truncateAt value to read full error responses. |
|
| 39 | - */ |
|
| 40 | - private function createGuzzleInstance(): Client { |
|
| 41 | - $bodySummarizer = new BodySummarizer(2048); |
|
| 37 | + /** |
|
| 38 | + * Create a Guzzle client with a higher truncateAt value to read full error responses. |
|
| 39 | + */ |
|
| 40 | + private function createGuzzleInstance(): Client { |
|
| 41 | + $bodySummarizer = new BodySummarizer(2048); |
|
| 42 | 42 | |
| 43 | - $stack = new HandlerStack(Utils::chooseHandler()); |
|
| 44 | - $stack->push(Middleware::httpErrors($bodySummarizer), 'http_errors'); |
|
| 45 | - $stack->push(Middleware::redirect(), 'allow_redirects'); |
|
| 46 | - $stack->push(Middleware::cookies(), 'cookies'); |
|
| 47 | - $stack->push(Middleware::prepareBody(), 'prepare_body'); |
|
| 43 | + $stack = new HandlerStack(Utils::chooseHandler()); |
|
| 44 | + $stack->push(Middleware::httpErrors($bodySummarizer), 'http_errors'); |
|
| 45 | + $stack->push(Middleware::redirect(), 'allow_redirects'); |
|
| 46 | + $stack->push(Middleware::cookies(), 'cookies'); |
|
| 47 | + $stack->push(Middleware::prepareBody(), 'prepare_body'); |
|
| 48 | 48 | |
| 49 | - return new Client(['handler' => $stack]); |
|
| 50 | - } |
|
| 49 | + return new Client(['handler' => $stack]); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @When searching for a principal matching :match |
|
| 54 | - * @param string $match |
|
| 55 | - * @throws \Exception |
|
| 56 | - */ |
|
| 57 | - public function principalPropertySearch(string $match) { |
|
| 58 | - $davUrl = $this->baseUrl . '/remote.php/dav/'; |
|
| 59 | - $user = 'admin'; |
|
| 60 | - $password = 'admin'; |
|
| 52 | + /** |
|
| 53 | + * @When searching for a principal matching :match |
|
| 54 | + * @param string $match |
|
| 55 | + * @throws \Exception |
|
| 56 | + */ |
|
| 57 | + public function principalPropertySearch(string $match) { |
|
| 58 | + $davUrl = $this->baseUrl . '/remote.php/dav/'; |
|
| 59 | + $user = 'admin'; |
|
| 60 | + $password = 'admin'; |
|
| 61 | 61 | |
| 62 | - $this->response = $this->client->request( |
|
| 63 | - 'REPORT', |
|
| 64 | - $davUrl, |
|
| 65 | - [ |
|
| 66 | - 'body' => '<x0:principal-property-search xmlns:x0="DAV:" test="anyof"> |
|
| 62 | + $this->response = $this->client->request( |
|
| 63 | + 'REPORT', |
|
| 64 | + $davUrl, |
|
| 65 | + [ |
|
| 66 | + 'body' => '<x0:principal-property-search xmlns:x0="DAV:" test="anyof"> |
|
| 67 | 67 | <x0:property-search> |
| 68 | 68 | <x0:prop> |
| 69 | 69 | <x0:displayname/> |
@@ -102,39 +102,39 @@ discard block |
||
| 102 | 102 | <x0:apply-to-principal-collection-set/> |
| 103 | 103 | </x0:principal-property-search> |
| 104 | 104 | ', |
| 105 | - 'auth' => [ |
|
| 106 | - $user, |
|
| 107 | - $password, |
|
| 108 | - ], |
|
| 109 | - 'headers' => [ |
|
| 110 | - 'Content-Type' => 'application/xml; charset=UTF-8', |
|
| 111 | - 'Depth' => '0', |
|
| 112 | - ], |
|
| 113 | - ] |
|
| 114 | - ); |
|
| 115 | - } |
|
| 105 | + 'auth' => [ |
|
| 106 | + $user, |
|
| 107 | + $password, |
|
| 108 | + ], |
|
| 109 | + 'headers' => [ |
|
| 110 | + 'Content-Type' => 'application/xml; charset=UTF-8', |
|
| 111 | + 'Depth' => '0', |
|
| 112 | + ], |
|
| 113 | + ] |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * @Then The search HTTP status code should be :code |
|
| 119 | - * @param string $code |
|
| 120 | - * @throws \Exception |
|
| 121 | - */ |
|
| 122 | - public function theHttpStatusCodeShouldBe(string $code): void { |
|
| 123 | - if ((int)$code !== $this->response->getStatusCode()) { |
|
| 124 | - throw new \Exception('Expected ' . (int)$code . ' got ' . $this->response->getStatusCode()); |
|
| 125 | - } |
|
| 126 | - } |
|
| 117 | + /** |
|
| 118 | + * @Then The search HTTP status code should be :code |
|
| 119 | + * @param string $code |
|
| 120 | + * @throws \Exception |
|
| 121 | + */ |
|
| 122 | + public function theHttpStatusCodeShouldBe(string $code): void { |
|
| 123 | + if ((int)$code !== $this->response->getStatusCode()) { |
|
| 124 | + throw new \Exception('Expected ' . (int)$code . ' got ' . $this->response->getStatusCode()); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * @Then The search response should contain :needle |
|
| 130 | - * @param string $needle |
|
| 131 | - * @throws \Exception |
|
| 132 | - */ |
|
| 133 | - public function theResponseShouldContain(string $needle): void { |
|
| 134 | - $body = $this->response->getBody()->getContents(); |
|
| 128 | + /** |
|
| 129 | + * @Then The search response should contain :needle |
|
| 130 | + * @param string $needle |
|
| 131 | + * @throws \Exception |
|
| 132 | + */ |
|
| 133 | + public function theResponseShouldContain(string $needle): void { |
|
| 134 | + $body = $this->response->getBody()->getContents(); |
|
| 135 | 135 | |
| 136 | - if (str_contains($body, $needle) === false) { |
|
| 137 | - throw new \Exception('Response does not contain "' . $needle . '"'); |
|
| 138 | - } |
|
| 139 | - } |
|
| 136 | + if (str_contains($body, $needle) === false) { |
|
| 137 | + throw new \Exception('Response does not contain "' . $needle . '"'); |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -require __DIR__ . '/../../vendor/autoload.php'; |
|
| 7 | +require __DIR__.'/../../vendor/autoload.php'; |
|
| 8 | 8 | |
| 9 | 9 | use Behat\Behat\Context\Context; |
| 10 | 10 | use GuzzleHttp\BodySummarizer; |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @throws \Exception |
| 56 | 56 | */ |
| 57 | 57 | public function principalPropertySearch(string $match) { |
| 58 | - $davUrl = $this->baseUrl . '/remote.php/dav/'; |
|
| 58 | + $davUrl = $this->baseUrl.'/remote.php/dav/'; |
|
| 59 | 59 | $user = 'admin'; |
| 60 | 60 | $password = 'admin'; |
| 61 | 61 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | <x0:displayname/> |
| 70 | 70 | <x2:email-address xmlns:x2="http://sabredav.org/ns"/> |
| 71 | 71 | </x0:prop> |
| 72 | - <x0:match>' . $match . '</x0:match> |
|
| 72 | + <x0:match>' . $match.'</x0:match> |
|
| 73 | 73 | </x0:property-search> |
| 74 | 74 | <x0:prop> |
| 75 | 75 | <x0:displayname/> |
@@ -120,8 +120,8 @@ discard block |
||
| 120 | 120 | * @throws \Exception |
| 121 | 121 | */ |
| 122 | 122 | public function theHttpStatusCodeShouldBe(string $code): void { |
| 123 | - if ((int)$code !== $this->response->getStatusCode()) { |
|
| 124 | - throw new \Exception('Expected ' . (int)$code . ' got ' . $this->response->getStatusCode()); |
|
| 123 | + if ((int) $code !== $this->response->getStatusCode()) { |
|
| 124 | + throw new \Exception('Expected '.(int) $code.' got '.$this->response->getStatusCode()); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | $body = $this->response->getBody()->getContents(); |
| 135 | 135 | |
| 136 | 136 | if (str_contains($body, $needle) === false) { |
| 137 | - throw new \Exception('Response does not contain "' . $needle . '"'); |
|
| 137 | + throw new \Exception('Response does not contain "'.$needle.'"'); |
|
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | } |