@@ -35,292 +35,292 @@ |
||
| 35 | 35 | use OCP\Group\Backend\ICountDisabledInGroup; |
| 36 | 36 | |
| 37 | 37 | class Group implements IGroup { |
| 38 | - /** @var null|string */ |
|
| 39 | - protected $displayName; |
|
| 38 | + /** @var null|string */ |
|
| 39 | + protected $displayName; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var string $id |
|
| 43 | - */ |
|
| 44 | - private $gid; |
|
| 41 | + /** |
|
| 42 | + * @var string $id |
|
| 43 | + */ |
|
| 44 | + private $gid; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var \OC\User\User[] $users |
|
| 48 | - */ |
|
| 49 | - private $users = array(); |
|
| 46 | + /** |
|
| 47 | + * @var \OC\User\User[] $users |
|
| 48 | + */ |
|
| 49 | + private $users = array(); |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var bool $usersLoaded |
|
| 53 | - */ |
|
| 54 | - private $usersLoaded; |
|
| 51 | + /** |
|
| 52 | + * @var bool $usersLoaded |
|
| 53 | + */ |
|
| 54 | + private $usersLoaded; |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var \OC\Group\Backend[]|\OC\Group\Database[] $backend |
|
| 58 | - */ |
|
| 59 | - private $backends; |
|
| 56 | + /** |
|
| 57 | + * @var \OC\Group\Backend[]|\OC\Group\Database[] $backend |
|
| 58 | + */ |
|
| 59 | + private $backends; |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @var \OC\Hooks\PublicEmitter $emitter |
|
| 63 | - */ |
|
| 64 | - private $emitter; |
|
| 61 | + /** |
|
| 62 | + * @var \OC\Hooks\PublicEmitter $emitter |
|
| 63 | + */ |
|
| 64 | + private $emitter; |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @var \OC\User\Manager $userManager |
|
| 68 | - */ |
|
| 69 | - private $userManager; |
|
| 66 | + /** |
|
| 67 | + * @var \OC\User\Manager $userManager |
|
| 68 | + */ |
|
| 69 | + private $userManager; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @param string $gid |
|
| 73 | - * @param \OC\Group\Backend[] $backends |
|
| 74 | - * @param \OC\User\Manager $userManager |
|
| 75 | - * @param \OC\Hooks\PublicEmitter $emitter |
|
| 76 | - * @param string $displayName |
|
| 77 | - */ |
|
| 78 | - public function __construct($gid, $backends, $userManager, $emitter = null, $displayName = null) { |
|
| 79 | - $this->gid = $gid; |
|
| 80 | - $this->backends = $backends; |
|
| 81 | - $this->userManager = $userManager; |
|
| 82 | - $this->emitter = $emitter; |
|
| 83 | - $this->displayName = $displayName; |
|
| 84 | - } |
|
| 71 | + /** |
|
| 72 | + * @param string $gid |
|
| 73 | + * @param \OC\Group\Backend[] $backends |
|
| 74 | + * @param \OC\User\Manager $userManager |
|
| 75 | + * @param \OC\Hooks\PublicEmitter $emitter |
|
| 76 | + * @param string $displayName |
|
| 77 | + */ |
|
| 78 | + public function __construct($gid, $backends, $userManager, $emitter = null, $displayName = null) { |
|
| 79 | + $this->gid = $gid; |
|
| 80 | + $this->backends = $backends; |
|
| 81 | + $this->userManager = $userManager; |
|
| 82 | + $this->emitter = $emitter; |
|
| 83 | + $this->displayName = $displayName; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - public function getGID() { |
|
| 87 | - return $this->gid; |
|
| 88 | - } |
|
| 86 | + public function getGID() { |
|
| 87 | + return $this->gid; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - public function getDisplayName() { |
|
| 91 | - if (is_null($this->displayName)) { |
|
| 92 | - return $this->gid; |
|
| 93 | - } |
|
| 94 | - return $this->displayName; |
|
| 95 | - } |
|
| 90 | + public function getDisplayName() { |
|
| 91 | + if (is_null($this->displayName)) { |
|
| 92 | + return $this->gid; |
|
| 93 | + } |
|
| 94 | + return $this->displayName; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * get all users in the group |
|
| 99 | - * |
|
| 100 | - * @return \OC\User\User[] |
|
| 101 | - */ |
|
| 102 | - public function getUsers() { |
|
| 103 | - if ($this->usersLoaded) { |
|
| 104 | - return $this->users; |
|
| 105 | - } |
|
| 97 | + /** |
|
| 98 | + * get all users in the group |
|
| 99 | + * |
|
| 100 | + * @return \OC\User\User[] |
|
| 101 | + */ |
|
| 102 | + public function getUsers() { |
|
| 103 | + if ($this->usersLoaded) { |
|
| 104 | + return $this->users; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - $userIds = array(); |
|
| 108 | - foreach ($this->backends as $backend) { |
|
| 109 | - $diff = array_diff( |
|
| 110 | - $backend->usersInGroup($this->gid), |
|
| 111 | - $userIds |
|
| 112 | - ); |
|
| 113 | - if ($diff) { |
|
| 114 | - $userIds = array_merge($userIds, $diff); |
|
| 115 | - } |
|
| 116 | - } |
|
| 107 | + $userIds = array(); |
|
| 108 | + foreach ($this->backends as $backend) { |
|
| 109 | + $diff = array_diff( |
|
| 110 | + $backend->usersInGroup($this->gid), |
|
| 111 | + $userIds |
|
| 112 | + ); |
|
| 113 | + if ($diff) { |
|
| 114 | + $userIds = array_merge($userIds, $diff); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - $this->users = $this->getVerifiedUsers($userIds); |
|
| 119 | - $this->usersLoaded = true; |
|
| 120 | - return $this->users; |
|
| 121 | - } |
|
| 118 | + $this->users = $this->getVerifiedUsers($userIds); |
|
| 119 | + $this->usersLoaded = true; |
|
| 120 | + return $this->users; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * check if a user is in the group |
|
| 125 | - * |
|
| 126 | - * @param IUser $user |
|
| 127 | - * @return bool |
|
| 128 | - */ |
|
| 129 | - public function inGroup(IUser $user) { |
|
| 130 | - if (isset($this->users[$user->getUID()])) { |
|
| 131 | - return true; |
|
| 132 | - } |
|
| 133 | - foreach ($this->backends as $backend) { |
|
| 134 | - if ($backend->inGroup($user->getUID(), $this->gid)) { |
|
| 135 | - $this->users[$user->getUID()] = $user; |
|
| 136 | - return true; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - return false; |
|
| 140 | - } |
|
| 123 | + /** |
|
| 124 | + * check if a user is in the group |
|
| 125 | + * |
|
| 126 | + * @param IUser $user |
|
| 127 | + * @return bool |
|
| 128 | + */ |
|
| 129 | + public function inGroup(IUser $user) { |
|
| 130 | + if (isset($this->users[$user->getUID()])) { |
|
| 131 | + return true; |
|
| 132 | + } |
|
| 133 | + foreach ($this->backends as $backend) { |
|
| 134 | + if ($backend->inGroup($user->getUID(), $this->gid)) { |
|
| 135 | + $this->users[$user->getUID()] = $user; |
|
| 136 | + return true; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + return false; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * add a user to the group |
|
| 144 | - * |
|
| 145 | - * @param IUser $user |
|
| 146 | - */ |
|
| 147 | - public function addUser(IUser $user) { |
|
| 148 | - if ($this->inGroup($user)) { |
|
| 149 | - return; |
|
| 150 | - } |
|
| 142 | + /** |
|
| 143 | + * add a user to the group |
|
| 144 | + * |
|
| 145 | + * @param IUser $user |
|
| 146 | + */ |
|
| 147 | + public function addUser(IUser $user) { |
|
| 148 | + if ($this->inGroup($user)) { |
|
| 149 | + return; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - if ($this->emitter) { |
|
| 153 | - $this->emitter->emit('\OC\Group', 'preAddUser', array($this, $user)); |
|
| 154 | - } |
|
| 155 | - foreach ($this->backends as $backend) { |
|
| 156 | - if ($backend->implementsActions(\OC\Group\Backend::ADD_TO_GROUP)) { |
|
| 157 | - $backend->addToGroup($user->getUID(), $this->gid); |
|
| 158 | - if ($this->users) { |
|
| 159 | - $this->users[$user->getUID()] = $user; |
|
| 160 | - } |
|
| 161 | - if ($this->emitter) { |
|
| 162 | - $this->emitter->emit('\OC\Group', 'postAddUser', array($this, $user)); |
|
| 163 | - } |
|
| 164 | - return; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - } |
|
| 152 | + if ($this->emitter) { |
|
| 153 | + $this->emitter->emit('\OC\Group', 'preAddUser', array($this, $user)); |
|
| 154 | + } |
|
| 155 | + foreach ($this->backends as $backend) { |
|
| 156 | + if ($backend->implementsActions(\OC\Group\Backend::ADD_TO_GROUP)) { |
|
| 157 | + $backend->addToGroup($user->getUID(), $this->gid); |
|
| 158 | + if ($this->users) { |
|
| 159 | + $this->users[$user->getUID()] = $user; |
|
| 160 | + } |
|
| 161 | + if ($this->emitter) { |
|
| 162 | + $this->emitter->emit('\OC\Group', 'postAddUser', array($this, $user)); |
|
| 163 | + } |
|
| 164 | + return; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * remove a user from the group |
|
| 171 | - * |
|
| 172 | - * @param \OC\User\User $user |
|
| 173 | - */ |
|
| 174 | - public function removeUser($user) { |
|
| 175 | - $result = false; |
|
| 176 | - if ($this->emitter) { |
|
| 177 | - $this->emitter->emit('\OC\Group', 'preRemoveUser', array($this, $user)); |
|
| 178 | - } |
|
| 179 | - foreach ($this->backends as $backend) { |
|
| 180 | - if ($backend->implementsActions(\OC\Group\Backend::REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) { |
|
| 181 | - $backend->removeFromGroup($user->getUID(), $this->gid); |
|
| 182 | - $result = true; |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - if ($result) { |
|
| 186 | - if ($this->emitter) { |
|
| 187 | - $this->emitter->emit('\OC\Group', 'postRemoveUser', array($this, $user)); |
|
| 188 | - } |
|
| 189 | - if ($this->users) { |
|
| 190 | - foreach ($this->users as $index => $groupUser) { |
|
| 191 | - if ($groupUser->getUID() === $user->getUID()) { |
|
| 192 | - unset($this->users[$index]); |
|
| 193 | - return; |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 169 | + /** |
|
| 170 | + * remove a user from the group |
|
| 171 | + * |
|
| 172 | + * @param \OC\User\User $user |
|
| 173 | + */ |
|
| 174 | + public function removeUser($user) { |
|
| 175 | + $result = false; |
|
| 176 | + if ($this->emitter) { |
|
| 177 | + $this->emitter->emit('\OC\Group', 'preRemoveUser', array($this, $user)); |
|
| 178 | + } |
|
| 179 | + foreach ($this->backends as $backend) { |
|
| 180 | + if ($backend->implementsActions(\OC\Group\Backend::REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) { |
|
| 181 | + $backend->removeFromGroup($user->getUID(), $this->gid); |
|
| 182 | + $result = true; |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + if ($result) { |
|
| 186 | + if ($this->emitter) { |
|
| 187 | + $this->emitter->emit('\OC\Group', 'postRemoveUser', array($this, $user)); |
|
| 188 | + } |
|
| 189 | + if ($this->users) { |
|
| 190 | + foreach ($this->users as $index => $groupUser) { |
|
| 191 | + if ($groupUser->getUID() === $user->getUID()) { |
|
| 192 | + unset($this->users[$index]); |
|
| 193 | + return; |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - /** |
|
| 201 | - * search for users in the group by userid |
|
| 202 | - * |
|
| 203 | - * @param string $search |
|
| 204 | - * @param int $limit |
|
| 205 | - * @param int $offset |
|
| 206 | - * @return \OC\User\User[] |
|
| 207 | - */ |
|
| 208 | - public function searchUsers($search, $limit = null, $offset = null) { |
|
| 209 | - $users = array(); |
|
| 210 | - foreach ($this->backends as $backend) { |
|
| 211 | - $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); |
|
| 212 | - $users += $this->getVerifiedUsers($userIds); |
|
| 213 | - if (!is_null($limit) and $limit <= 0) { |
|
| 214 | - return $users; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - return $users; |
|
| 218 | - } |
|
| 200 | + /** |
|
| 201 | + * search for users in the group by userid |
|
| 202 | + * |
|
| 203 | + * @param string $search |
|
| 204 | + * @param int $limit |
|
| 205 | + * @param int $offset |
|
| 206 | + * @return \OC\User\User[] |
|
| 207 | + */ |
|
| 208 | + public function searchUsers($search, $limit = null, $offset = null) { |
|
| 209 | + $users = array(); |
|
| 210 | + foreach ($this->backends as $backend) { |
|
| 211 | + $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); |
|
| 212 | + $users += $this->getVerifiedUsers($userIds); |
|
| 213 | + if (!is_null($limit) and $limit <= 0) { |
|
| 214 | + return $users; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + return $users; |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * returns the number of users matching the search string |
|
| 222 | - * |
|
| 223 | - * @param string $search |
|
| 224 | - * @return int|bool |
|
| 225 | - */ |
|
| 226 | - public function count($search = '') { |
|
| 227 | - $users = false; |
|
| 228 | - foreach ($this->backends as $backend) { |
|
| 229 | - if($backend->implementsActions(\OC\Group\Backend::COUNT_USERS)) { |
|
| 230 | - if($users === false) { |
|
| 231 | - //we could directly add to a bool variable, but this would |
|
| 232 | - //be ugly |
|
| 233 | - $users = 0; |
|
| 234 | - } |
|
| 235 | - $users += $backend->countUsersInGroup($this->gid, $search); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - return $users; |
|
| 239 | - } |
|
| 220 | + /** |
|
| 221 | + * returns the number of users matching the search string |
|
| 222 | + * |
|
| 223 | + * @param string $search |
|
| 224 | + * @return int|bool |
|
| 225 | + */ |
|
| 226 | + public function count($search = '') { |
|
| 227 | + $users = false; |
|
| 228 | + foreach ($this->backends as $backend) { |
|
| 229 | + if($backend->implementsActions(\OC\Group\Backend::COUNT_USERS)) { |
|
| 230 | + if($users === false) { |
|
| 231 | + //we could directly add to a bool variable, but this would |
|
| 232 | + //be ugly |
|
| 233 | + $users = 0; |
|
| 234 | + } |
|
| 235 | + $users += $backend->countUsersInGroup($this->gid, $search); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + return $users; |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | - /** |
|
| 242 | - * returns the number of disabled users |
|
| 243 | - * |
|
| 244 | - * @return int|bool |
|
| 245 | - */ |
|
| 246 | - public function countDisabled() { |
|
| 247 | - $users = false; |
|
| 248 | - foreach ($this->backends as $backend) { |
|
| 249 | - if($backend instanceOf ICountDisabledInGroup) { |
|
| 250 | - if($users === false) { |
|
| 251 | - //we could directly add to a bool variable, but this would |
|
| 252 | - //be ugly |
|
| 253 | - $users = 0; |
|
| 254 | - } |
|
| 255 | - $users += $backend->countDisabledInGroup($this->gid); |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - return $users; |
|
| 259 | - } |
|
| 241 | + /** |
|
| 242 | + * returns the number of disabled users |
|
| 243 | + * |
|
| 244 | + * @return int|bool |
|
| 245 | + */ |
|
| 246 | + public function countDisabled() { |
|
| 247 | + $users = false; |
|
| 248 | + foreach ($this->backends as $backend) { |
|
| 249 | + if($backend instanceOf ICountDisabledInGroup) { |
|
| 250 | + if($users === false) { |
|
| 251 | + //we could directly add to a bool variable, but this would |
|
| 252 | + //be ugly |
|
| 253 | + $users = 0; |
|
| 254 | + } |
|
| 255 | + $users += $backend->countDisabledInGroup($this->gid); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + return $users; |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * search for users in the group by displayname |
|
| 263 | - * |
|
| 264 | - * @param string $search |
|
| 265 | - * @param int $limit |
|
| 266 | - * @param int $offset |
|
| 267 | - * @return \OC\User\User[] |
|
| 268 | - */ |
|
| 269 | - public function searchDisplayName($search, $limit = null, $offset = null) { |
|
| 270 | - $users = array(); |
|
| 271 | - foreach ($this->backends as $backend) { |
|
| 272 | - $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); |
|
| 273 | - $users = $this->getVerifiedUsers($userIds); |
|
| 274 | - if (!is_null($limit) and $limit <= 0) { |
|
| 275 | - return array_values($users); |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - return array_values($users); |
|
| 279 | - } |
|
| 261 | + /** |
|
| 262 | + * search for users in the group by displayname |
|
| 263 | + * |
|
| 264 | + * @param string $search |
|
| 265 | + * @param int $limit |
|
| 266 | + * @param int $offset |
|
| 267 | + * @return \OC\User\User[] |
|
| 268 | + */ |
|
| 269 | + public function searchDisplayName($search, $limit = null, $offset = null) { |
|
| 270 | + $users = array(); |
|
| 271 | + foreach ($this->backends as $backend) { |
|
| 272 | + $userIds = $backend->usersInGroup($this->gid, $search, $limit, $offset); |
|
| 273 | + $users = $this->getVerifiedUsers($userIds); |
|
| 274 | + if (!is_null($limit) and $limit <= 0) { |
|
| 275 | + return array_values($users); |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + return array_values($users); |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * delete the group |
|
| 283 | - * |
|
| 284 | - * @return bool |
|
| 285 | - */ |
|
| 286 | - public function delete() { |
|
| 287 | - // Prevent users from deleting group admin |
|
| 288 | - if ($this->getGID() === 'admin') { |
|
| 289 | - return false; |
|
| 290 | - } |
|
| 281 | + /** |
|
| 282 | + * delete the group |
|
| 283 | + * |
|
| 284 | + * @return bool |
|
| 285 | + */ |
|
| 286 | + public function delete() { |
|
| 287 | + // Prevent users from deleting group admin |
|
| 288 | + if ($this->getGID() === 'admin') { |
|
| 289 | + return false; |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | - $result = false; |
|
| 293 | - if ($this->emitter) { |
|
| 294 | - $this->emitter->emit('\OC\Group', 'preDelete', array($this)); |
|
| 295 | - } |
|
| 296 | - foreach ($this->backends as $backend) { |
|
| 297 | - if ($backend->implementsActions(\OC\Group\Backend::DELETE_GROUP)) { |
|
| 298 | - $result = true; |
|
| 299 | - $backend->deleteGroup($this->gid); |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - if ($result and $this->emitter) { |
|
| 303 | - $this->emitter->emit('\OC\Group', 'postDelete', array($this)); |
|
| 304 | - } |
|
| 305 | - return $result; |
|
| 306 | - } |
|
| 292 | + $result = false; |
|
| 293 | + if ($this->emitter) { |
|
| 294 | + $this->emitter->emit('\OC\Group', 'preDelete', array($this)); |
|
| 295 | + } |
|
| 296 | + foreach ($this->backends as $backend) { |
|
| 297 | + if ($backend->implementsActions(\OC\Group\Backend::DELETE_GROUP)) { |
|
| 298 | + $result = true; |
|
| 299 | + $backend->deleteGroup($this->gid); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + if ($result and $this->emitter) { |
|
| 303 | + $this->emitter->emit('\OC\Group', 'postDelete', array($this)); |
|
| 304 | + } |
|
| 305 | + return $result; |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - /** |
|
| 309 | - * returns all the Users from an array that really exists |
|
| 310 | - * @param string[] $userIds an array containing user IDs |
|
| 311 | - * @return \OC\User\User[] an Array with the userId as Key and \OC\User\User as value |
|
| 312 | - */ |
|
| 313 | - private function getVerifiedUsers($userIds) { |
|
| 314 | - if (!is_array($userIds)) { |
|
| 315 | - return array(); |
|
| 316 | - } |
|
| 317 | - $users = array(); |
|
| 318 | - foreach ($userIds as $userId) { |
|
| 319 | - $user = $this->userManager->get($userId); |
|
| 320 | - if (!is_null($user)) { |
|
| 321 | - $users[$userId] = $user; |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - return $users; |
|
| 325 | - } |
|
| 308 | + /** |
|
| 309 | + * returns all the Users from an array that really exists |
|
| 310 | + * @param string[] $userIds an array containing user IDs |
|
| 311 | + * @return \OC\User\User[] an Array with the userId as Key and \OC\User\User as value |
|
| 312 | + */ |
|
| 313 | + private function getVerifiedUsers($userIds) { |
|
| 314 | + if (!is_array($userIds)) { |
|
| 315 | + return array(); |
|
| 316 | + } |
|
| 317 | + $users = array(); |
|
| 318 | + foreach ($userIds as $userId) { |
|
| 319 | + $user = $this->userManager->get($userId); |
|
| 320 | + if (!is_null($user)) { |
|
| 321 | + $users[$userId] = $user; |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + return $users; |
|
| 325 | + } |
|
| 326 | 326 | } |
@@ -44,245 +44,245 @@ |
||
| 44 | 44 | |
| 45 | 45 | class GroupsController extends AUserData { |
| 46 | 46 | |
| 47 | - /** @var ILogger */ |
|
| 48 | - private $logger; |
|
| 47 | + /** @var ILogger */ |
|
| 48 | + private $logger; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param string $appName |
|
| 52 | - * @param IRequest $request |
|
| 53 | - * @param IUserManager $userManager |
|
| 54 | - * @param IConfig $config |
|
| 55 | - * @param IGroupManager $groupManager |
|
| 56 | - * @param IUserSession $userSession |
|
| 57 | - * @param AccountManager $accountManager |
|
| 58 | - * @param ILogger $logger |
|
| 59 | - * @param UsersController $userController |
|
| 60 | - */ |
|
| 61 | - public function __construct(string $appName, |
|
| 62 | - IRequest $request, |
|
| 63 | - IUserManager $userManager, |
|
| 64 | - IConfig $config, |
|
| 65 | - IGroupManager $groupManager, |
|
| 66 | - IUserSession $userSession, |
|
| 67 | - AccountManager $accountManager, |
|
| 68 | - ILogger $logger) { |
|
| 69 | - parent::__construct($appName, |
|
| 70 | - $request, |
|
| 71 | - $userManager, |
|
| 72 | - $config, |
|
| 73 | - $groupManager, |
|
| 74 | - $userSession, |
|
| 75 | - $accountManager); |
|
| 50 | + /** |
|
| 51 | + * @param string $appName |
|
| 52 | + * @param IRequest $request |
|
| 53 | + * @param IUserManager $userManager |
|
| 54 | + * @param IConfig $config |
|
| 55 | + * @param IGroupManager $groupManager |
|
| 56 | + * @param IUserSession $userSession |
|
| 57 | + * @param AccountManager $accountManager |
|
| 58 | + * @param ILogger $logger |
|
| 59 | + * @param UsersController $userController |
|
| 60 | + */ |
|
| 61 | + public function __construct(string $appName, |
|
| 62 | + IRequest $request, |
|
| 63 | + IUserManager $userManager, |
|
| 64 | + IConfig $config, |
|
| 65 | + IGroupManager $groupManager, |
|
| 66 | + IUserSession $userSession, |
|
| 67 | + AccountManager $accountManager, |
|
| 68 | + ILogger $logger) { |
|
| 69 | + parent::__construct($appName, |
|
| 70 | + $request, |
|
| 71 | + $userManager, |
|
| 72 | + $config, |
|
| 73 | + $groupManager, |
|
| 74 | + $userSession, |
|
| 75 | + $accountManager); |
|
| 76 | 76 | |
| 77 | - $this->logger = $logger; |
|
| 78 | - } |
|
| 77 | + $this->logger = $logger; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * returns a list of groups |
|
| 82 | - * |
|
| 83 | - * @NoAdminRequired |
|
| 84 | - * |
|
| 85 | - * @param string $search |
|
| 86 | - * @param int $limit |
|
| 87 | - * @param int $offset |
|
| 88 | - * @return DataResponse |
|
| 89 | - */ |
|
| 90 | - public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
| 91 | - $groups = $this->groupManager->search($search, $limit, $offset); |
|
| 92 | - $groups = array_map(function($group) { |
|
| 93 | - /** @var IGroup $group */ |
|
| 94 | - return $group->getGID(); |
|
| 95 | - }, $groups); |
|
| 80 | + /** |
|
| 81 | + * returns a list of groups |
|
| 82 | + * |
|
| 83 | + * @NoAdminRequired |
|
| 84 | + * |
|
| 85 | + * @param string $search |
|
| 86 | + * @param int $limit |
|
| 87 | + * @param int $offset |
|
| 88 | + * @return DataResponse |
|
| 89 | + */ |
|
| 90 | + public function getGroups(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
| 91 | + $groups = $this->groupManager->search($search, $limit, $offset); |
|
| 92 | + $groups = array_map(function($group) { |
|
| 93 | + /** @var IGroup $group */ |
|
| 94 | + return $group->getGID(); |
|
| 95 | + }, $groups); |
|
| 96 | 96 | |
| 97 | - return new DataResponse(['groups' => $groups]); |
|
| 98 | - } |
|
| 97 | + return new DataResponse(['groups' => $groups]); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * returns a list of groups details with ids and displaynames |
|
| 102 | - * |
|
| 103 | - * @NoAdminRequired |
|
| 104 | - * |
|
| 105 | - * @param string $search |
|
| 106 | - * @param int $limit |
|
| 107 | - * @param int $offset |
|
| 108 | - * @return DataResponse |
|
| 109 | - */ |
|
| 110 | - public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
| 111 | - $groups = $this->groupManager->search($search, $limit, $offset); |
|
| 112 | - $groups = array_map(function($group) { |
|
| 113 | - /** @var IGroup $group */ |
|
| 114 | - return [ |
|
| 115 | - 'id' => $group->getGID(), |
|
| 116 | - 'displayname' => $group->getDisplayName(), |
|
| 117 | - 'usercount' => $group->count(), |
|
| 118 | - 'disabled' => $group->countDisabled() |
|
| 119 | - ]; |
|
| 120 | - }, $groups); |
|
| 100 | + /** |
|
| 101 | + * returns a list of groups details with ids and displaynames |
|
| 102 | + * |
|
| 103 | + * @NoAdminRequired |
|
| 104 | + * |
|
| 105 | + * @param string $search |
|
| 106 | + * @param int $limit |
|
| 107 | + * @param int $offset |
|
| 108 | + * @return DataResponse |
|
| 109 | + */ |
|
| 110 | + public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
| 111 | + $groups = $this->groupManager->search($search, $limit, $offset); |
|
| 112 | + $groups = array_map(function($group) { |
|
| 113 | + /** @var IGroup $group */ |
|
| 114 | + return [ |
|
| 115 | + 'id' => $group->getGID(), |
|
| 116 | + 'displayname' => $group->getDisplayName(), |
|
| 117 | + 'usercount' => $group->count(), |
|
| 118 | + 'disabled' => $group->countDisabled() |
|
| 119 | + ]; |
|
| 120 | + }, $groups); |
|
| 121 | 121 | |
| 122 | - return new DataResponse(['groups' => $groups]); |
|
| 123 | - } |
|
| 122 | + return new DataResponse(['groups' => $groups]); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * @NoAdminRequired |
|
| 127 | - * |
|
| 128 | - * @param string $groupId |
|
| 129 | - * @return DataResponse |
|
| 130 | - * @throws OCSException |
|
| 131 | - * |
|
| 132 | - * @deprecated 14 Use getGroupUsers |
|
| 133 | - */ |
|
| 134 | - public function getGroup(string $groupId): DataResponse { |
|
| 135 | - return $this->getGroupUsers($groupId); |
|
| 136 | - } |
|
| 125 | + /** |
|
| 126 | + * @NoAdminRequired |
|
| 127 | + * |
|
| 128 | + * @param string $groupId |
|
| 129 | + * @return DataResponse |
|
| 130 | + * @throws OCSException |
|
| 131 | + * |
|
| 132 | + * @deprecated 14 Use getGroupUsers |
|
| 133 | + */ |
|
| 134 | + public function getGroup(string $groupId): DataResponse { |
|
| 135 | + return $this->getGroupUsers($groupId); |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * returns an array of users in the specified group |
|
| 140 | - * |
|
| 141 | - * @NoAdminRequired |
|
| 142 | - * |
|
| 143 | - * @param string $groupId |
|
| 144 | - * @return DataResponse |
|
| 145 | - * @throws OCSException |
|
| 146 | - */ |
|
| 147 | - public function getGroupUsers(string $groupId): DataResponse { |
|
| 148 | - $user = $this->userSession->getUser(); |
|
| 149 | - $isSubadminOfGroup = false; |
|
| 138 | + /** |
|
| 139 | + * returns an array of users in the specified group |
|
| 140 | + * |
|
| 141 | + * @NoAdminRequired |
|
| 142 | + * |
|
| 143 | + * @param string $groupId |
|
| 144 | + * @return DataResponse |
|
| 145 | + * @throws OCSException |
|
| 146 | + */ |
|
| 147 | + public function getGroupUsers(string $groupId): DataResponse { |
|
| 148 | + $user = $this->userSession->getUser(); |
|
| 149 | + $isSubadminOfGroup = false; |
|
| 150 | 150 | |
| 151 | - // Check the group exists |
|
| 152 | - $group = $this->groupManager->get($groupId); |
|
| 153 | - if ($group !== null) { |
|
| 154 | - $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); |
|
| 155 | - } else { |
|
| 156 | - throw new OCSNotFoundException('The requested group could not be found'); |
|
| 157 | - } |
|
| 151 | + // Check the group exists |
|
| 152 | + $group = $this->groupManager->get($groupId); |
|
| 153 | + if ($group !== null) { |
|
| 154 | + $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); |
|
| 155 | + } else { |
|
| 156 | + throw new OCSNotFoundException('The requested group could not be found'); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - // Check subadmin has access to this group |
|
| 160 | - if($this->groupManager->isAdmin($user->getUID()) |
|
| 161 | - || $isSubadminOfGroup) { |
|
| 162 | - $users = $this->groupManager->get($groupId)->getUsers(); |
|
| 163 | - $users = array_map(function($user) { |
|
| 164 | - /** @var IUser $user */ |
|
| 165 | - return $user->getUID(); |
|
| 166 | - }, $users); |
|
| 167 | - $users = array_values($users); |
|
| 168 | - return new DataResponse(['users' => $users]); |
|
| 169 | - } |
|
| 159 | + // Check subadmin has access to this group |
|
| 160 | + if($this->groupManager->isAdmin($user->getUID()) |
|
| 161 | + || $isSubadminOfGroup) { |
|
| 162 | + $users = $this->groupManager->get($groupId)->getUsers(); |
|
| 163 | + $users = array_map(function($user) { |
|
| 164 | + /** @var IUser $user */ |
|
| 165 | + return $user->getUID(); |
|
| 166 | + }, $users); |
|
| 167 | + $users = array_values($users); |
|
| 168 | + return new DataResponse(['users' => $users]); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - throw new OCSForbiddenException(); |
|
| 172 | - } |
|
| 171 | + throw new OCSForbiddenException(); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - /** |
|
| 175 | - * returns an array of users details in the specified group |
|
| 176 | - * |
|
| 177 | - * @NoAdminRequired |
|
| 178 | - * |
|
| 179 | - * @param string $groupId |
|
| 180 | - * @param string $search |
|
| 181 | - * @param int $limit |
|
| 182 | - * @param int $offset |
|
| 183 | - * @return DataResponse |
|
| 184 | - * @throws OCSException |
|
| 185 | - */ |
|
| 186 | - public function getGroupUsersDetails(string $groupId, string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
| 187 | - $user = $this->userSession->getUser(); |
|
| 188 | - $isSubadminOfGroup = false; |
|
| 174 | + /** |
|
| 175 | + * returns an array of users details in the specified group |
|
| 176 | + * |
|
| 177 | + * @NoAdminRequired |
|
| 178 | + * |
|
| 179 | + * @param string $groupId |
|
| 180 | + * @param string $search |
|
| 181 | + * @param int $limit |
|
| 182 | + * @param int $offset |
|
| 183 | + * @return DataResponse |
|
| 184 | + * @throws OCSException |
|
| 185 | + */ |
|
| 186 | + public function getGroupUsersDetails(string $groupId, string $search = '', int $limit = null, int $offset = 0): DataResponse { |
|
| 187 | + $user = $this->userSession->getUser(); |
|
| 188 | + $isSubadminOfGroup = false; |
|
| 189 | 189 | |
| 190 | - // Check the group exists |
|
| 191 | - $group = $this->groupManager->get($groupId); |
|
| 192 | - if ($group !== null) { |
|
| 193 | - $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); |
|
| 194 | - } else { |
|
| 195 | - throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND); |
|
| 196 | - } |
|
| 190 | + // Check the group exists |
|
| 191 | + $group = $this->groupManager->get($groupId); |
|
| 192 | + if ($group !== null) { |
|
| 193 | + $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); |
|
| 194 | + } else { |
|
| 195 | + throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND); |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - // Check subadmin has access to this group |
|
| 199 | - if($this->groupManager->isAdmin($user->getUID()) |
|
| 200 | - || $isSubadminOfGroup) { |
|
| 201 | - $users = $this->groupManager->get($groupId)->searchUsers($search, $limit, $offset); |
|
| 198 | + // Check subadmin has access to this group |
|
| 199 | + if($this->groupManager->isAdmin($user->getUID()) |
|
| 200 | + || $isSubadminOfGroup) { |
|
| 201 | + $users = $this->groupManager->get($groupId)->searchUsers($search, $limit, $offset); |
|
| 202 | 202 | |
| 203 | - // Extract required number |
|
| 204 | - $users = array_keys($users); |
|
| 205 | - $usersDetails = []; |
|
| 206 | - foreach ($users as $userId) { |
|
| 207 | - $userData = $this->getUserData($userId); |
|
| 208 | - // Do not insert empty entry |
|
| 209 | - if(!empty($userData)) { |
|
| 210 | - $usersDetails[$userId] = $userData; |
|
| 211 | - } else { |
|
| 212 | - // Logged user does not have permissions to see this user |
|
| 213 | - // only showing its id |
|
| 214 | - $usersDetails[$userId] = ['id' => $userId]; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - return new DataResponse(['users' => $usersDetails]); |
|
| 218 | - } |
|
| 203 | + // Extract required number |
|
| 204 | + $users = array_keys($users); |
|
| 205 | + $usersDetails = []; |
|
| 206 | + foreach ($users as $userId) { |
|
| 207 | + $userData = $this->getUserData($userId); |
|
| 208 | + // Do not insert empty entry |
|
| 209 | + if(!empty($userData)) { |
|
| 210 | + $usersDetails[$userId] = $userData; |
|
| 211 | + } else { |
|
| 212 | + // Logged user does not have permissions to see this user |
|
| 213 | + // only showing its id |
|
| 214 | + $usersDetails[$userId] = ['id' => $userId]; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + return new DataResponse(['users' => $usersDetails]); |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 221 | - } |
|
| 220 | + throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED); |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * creates a new group |
|
| 225 | - * |
|
| 226 | - * @PasswordConfirmationRequired |
|
| 227 | - * |
|
| 228 | - * @param string $groupid |
|
| 229 | - * @return DataResponse |
|
| 230 | - * @throws OCSException |
|
| 231 | - */ |
|
| 232 | - public function addGroup(string $groupid): DataResponse { |
|
| 233 | - // Validate name |
|
| 234 | - if(empty($groupid)) { |
|
| 235 | - $this->logger->error('Group name not supplied', ['app' => 'provisioning_api']); |
|
| 236 | - throw new OCSException('Invalid group name', 101); |
|
| 237 | - } |
|
| 238 | - // Check if it exists |
|
| 239 | - if($this->groupManager->groupExists($groupid)){ |
|
| 240 | - throw new OCSException('', 102); |
|
| 241 | - } |
|
| 242 | - $this->groupManager->createGroup($groupid); |
|
| 243 | - return new DataResponse(); |
|
| 244 | - } |
|
| 223 | + /** |
|
| 224 | + * creates a new group |
|
| 225 | + * |
|
| 226 | + * @PasswordConfirmationRequired |
|
| 227 | + * |
|
| 228 | + * @param string $groupid |
|
| 229 | + * @return DataResponse |
|
| 230 | + * @throws OCSException |
|
| 231 | + */ |
|
| 232 | + public function addGroup(string $groupid): DataResponse { |
|
| 233 | + // Validate name |
|
| 234 | + if(empty($groupid)) { |
|
| 235 | + $this->logger->error('Group name not supplied', ['app' => 'provisioning_api']); |
|
| 236 | + throw new OCSException('Invalid group name', 101); |
|
| 237 | + } |
|
| 238 | + // Check if it exists |
|
| 239 | + if($this->groupManager->groupExists($groupid)){ |
|
| 240 | + throw new OCSException('', 102); |
|
| 241 | + } |
|
| 242 | + $this->groupManager->createGroup($groupid); |
|
| 243 | + return new DataResponse(); |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - /** |
|
| 247 | - * @PasswordConfirmationRequired |
|
| 248 | - * |
|
| 249 | - * @param string $groupId |
|
| 250 | - * @return DataResponse |
|
| 251 | - * @throws OCSException |
|
| 252 | - */ |
|
| 253 | - public function deleteGroup(string $groupId): DataResponse { |
|
| 254 | - // Check it exists |
|
| 255 | - if(!$this->groupManager->groupExists($groupId)){ |
|
| 256 | - throw new OCSException('', 101); |
|
| 257 | - } else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){ |
|
| 258 | - // Cannot delete admin group |
|
| 259 | - throw new OCSException('', 102); |
|
| 260 | - } |
|
| 246 | + /** |
|
| 247 | + * @PasswordConfirmationRequired |
|
| 248 | + * |
|
| 249 | + * @param string $groupId |
|
| 250 | + * @return DataResponse |
|
| 251 | + * @throws OCSException |
|
| 252 | + */ |
|
| 253 | + public function deleteGroup(string $groupId): DataResponse { |
|
| 254 | + // Check it exists |
|
| 255 | + if(!$this->groupManager->groupExists($groupId)){ |
|
| 256 | + throw new OCSException('', 101); |
|
| 257 | + } else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){ |
|
| 258 | + // Cannot delete admin group |
|
| 259 | + throw new OCSException('', 102); |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - return new DataResponse(); |
|
| 263 | - } |
|
| 262 | + return new DataResponse(); |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - /** |
|
| 266 | - * @param string $groupId |
|
| 267 | - * @return DataResponse |
|
| 268 | - * @throws OCSException |
|
| 269 | - */ |
|
| 270 | - public function getSubAdminsOfGroup(string $groupId): DataResponse { |
|
| 271 | - // Check group exists |
|
| 272 | - $targetGroup = $this->groupManager->get($groupId); |
|
| 273 | - if($targetGroup === null) { |
|
| 274 | - throw new OCSException('Group does not exist', 101); |
|
| 275 | - } |
|
| 265 | + /** |
|
| 266 | + * @param string $groupId |
|
| 267 | + * @return DataResponse |
|
| 268 | + * @throws OCSException |
|
| 269 | + */ |
|
| 270 | + public function getSubAdminsOfGroup(string $groupId): DataResponse { |
|
| 271 | + // Check group exists |
|
| 272 | + $targetGroup = $this->groupManager->get($groupId); |
|
| 273 | + if($targetGroup === null) { |
|
| 274 | + throw new OCSException('Group does not exist', 101); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - /** @var IUser[] $subadmins */ |
|
| 278 | - $subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup); |
|
| 279 | - // New class returns IUser[] so convert back |
|
| 280 | - $uids = []; |
|
| 281 | - foreach ($subadmins as $user) { |
|
| 282 | - $uids[] = $user->getUID(); |
|
| 283 | - } |
|
| 277 | + /** @var IUser[] $subadmins */ |
|
| 278 | + $subadmins = $this->groupManager->getSubAdmin()->getGroupsSubAdmins($targetGroup); |
|
| 279 | + // New class returns IUser[] so convert back |
|
| 280 | + $uids = []; |
|
| 281 | + foreach ($subadmins as $user) { |
|
| 282 | + $uids[] = $user->getUID(); |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - return new DataResponse($uids); |
|
| 286 | - } |
|
| 285 | + return new DataResponse($uids); |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | 288 | } |
@@ -151,16 +151,16 @@ discard block |
||
| 151 | 151 | // Check the group exists |
| 152 | 152 | $group = $this->groupManager->get($groupId); |
| 153 | 153 | if ($group !== null) { |
| 154 | - $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); |
|
| 154 | + $isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); |
|
| 155 | 155 | } else { |
| 156 | 156 | throw new OCSNotFoundException('The requested group could not be found'); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | // Check subadmin has access to this group |
| 160 | - if($this->groupManager->isAdmin($user->getUID()) |
|
| 160 | + if ($this->groupManager->isAdmin($user->getUID()) |
|
| 161 | 161 | || $isSubadminOfGroup) { |
| 162 | 162 | $users = $this->groupManager->get($groupId)->getUsers(); |
| 163 | - $users = array_map(function($user) { |
|
| 163 | + $users = array_map(function($user) { |
|
| 164 | 164 | /** @var IUser $user */ |
| 165 | 165 | return $user->getUID(); |
| 166 | 166 | }, $users); |
@@ -190,13 +190,13 @@ discard block |
||
| 190 | 190 | // Check the group exists |
| 191 | 191 | $group = $this->groupManager->get($groupId); |
| 192 | 192 | if ($group !== null) { |
| 193 | - $isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); |
|
| 193 | + $isSubadminOfGroup = $this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group); |
|
| 194 | 194 | } else { |
| 195 | 195 | throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND); |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | // Check subadmin has access to this group |
| 199 | - if($this->groupManager->isAdmin($user->getUID()) |
|
| 199 | + if ($this->groupManager->isAdmin($user->getUID()) |
|
| 200 | 200 | || $isSubadminOfGroup) { |
| 201 | 201 | $users = $this->groupManager->get($groupId)->searchUsers($search, $limit, $offset); |
| 202 | 202 | |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | foreach ($users as $userId) { |
| 207 | 207 | $userData = $this->getUserData($userId); |
| 208 | 208 | // Do not insert empty entry |
| 209 | - if(!empty($userData)) { |
|
| 209 | + if (!empty($userData)) { |
|
| 210 | 210 | $usersDetails[$userId] = $userData; |
| 211 | 211 | } else { |
| 212 | 212 | // Logged user does not have permissions to see this user |
@@ -231,12 +231,12 @@ discard block |
||
| 231 | 231 | */ |
| 232 | 232 | public function addGroup(string $groupid): DataResponse { |
| 233 | 233 | // Validate name |
| 234 | - if(empty($groupid)) { |
|
| 234 | + if (empty($groupid)) { |
|
| 235 | 235 | $this->logger->error('Group name not supplied', ['app' => 'provisioning_api']); |
| 236 | 236 | throw new OCSException('Invalid group name', 101); |
| 237 | 237 | } |
| 238 | 238 | // Check if it exists |
| 239 | - if($this->groupManager->groupExists($groupid)){ |
|
| 239 | + if ($this->groupManager->groupExists($groupid)) { |
|
| 240 | 240 | throw new OCSException('', 102); |
| 241 | 241 | } |
| 242 | 242 | $this->groupManager->createGroup($groupid); |
@@ -252,9 +252,9 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | public function deleteGroup(string $groupId): DataResponse { |
| 254 | 254 | // Check it exists |
| 255 | - if(!$this->groupManager->groupExists($groupId)){ |
|
| 255 | + if (!$this->groupManager->groupExists($groupId)) { |
|
| 256 | 256 | throw new OCSException('', 101); |
| 257 | - } else if($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()){ |
|
| 257 | + } else if ($groupId === 'admin' || !$this->groupManager->get($groupId)->delete()) { |
|
| 258 | 258 | // Cannot delete admin group |
| 259 | 259 | throw new OCSException('', 102); |
| 260 | 260 | } |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | public function getSubAdminsOfGroup(string $groupId): DataResponse { |
| 271 | 271 | // Check group exists |
| 272 | 272 | $targetGroup = $this->groupManager->get($groupId); |
| 273 | - if($targetGroup === null) { |
|
| 273 | + if ($targetGroup === null) { |
|
| 274 | 274 | throw new OCSException('Group does not exist', 101); |
| 275 | 275 | } |
| 276 | 276 | |