@@ -39,594 +39,594 @@ |
||
| 39 | 39 | |
| 40 | 40 | class Users { |
| 41 | 41 | |
| 42 | - /** @var IUserManager */ |
|
| 43 | - private $userManager; |
|
| 44 | - /** @var IConfig */ |
|
| 45 | - private $config; |
|
| 46 | - /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface |
|
| 47 | - private $groupManager; |
|
| 48 | - /** @var IUserSession */ |
|
| 49 | - private $userSession; |
|
| 50 | - /** @var ILogger */ |
|
| 51 | - private $logger; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param IUserManager $userManager |
|
| 55 | - * @param IConfig $config |
|
| 56 | - * @param IGroupManager $groupManager |
|
| 57 | - * @param IUserSession $userSession |
|
| 58 | - * @param ILogger $logger |
|
| 59 | - */ |
|
| 60 | - public function __construct(IUserManager $userManager, |
|
| 61 | - IConfig $config, |
|
| 62 | - IGroupManager $groupManager, |
|
| 63 | - IUserSession $userSession, |
|
| 64 | - ILogger $logger) { |
|
| 65 | - $this->userManager = $userManager; |
|
| 66 | - $this->config = $config; |
|
| 67 | - $this->groupManager = $groupManager; |
|
| 68 | - $this->userSession = $userSession; |
|
| 69 | - $this->logger = $logger; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * returns a list of users |
|
| 74 | - * |
|
| 75 | - * @return \OC\OCS\Result |
|
| 76 | - */ |
|
| 77 | - public function getUsers() { |
|
| 78 | - $search = !empty($_GET['search']) ? $_GET['search'] : ''; |
|
| 79 | - $limit = !empty($_GET['limit']) ? $_GET['limit'] : null; |
|
| 80 | - $offset = !empty($_GET['offset']) ? $_GET['offset'] : null; |
|
| 81 | - |
|
| 82 | - // Check if user is logged in |
|
| 83 | - $user = $this->userSession->getUser(); |
|
| 84 | - if ($user === null) { |
|
| 85 | - return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - // Admin? Or SubAdmin? |
|
| 89 | - $uid = $user->getUID(); |
|
| 90 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 91 | - if($this->groupManager->isAdmin($uid)){ |
|
| 92 | - $users = $this->userManager->search($search, $limit, $offset); |
|
| 93 | - } else if ($subAdminManager->isSubAdmin($user)) { |
|
| 94 | - $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
|
| 95 | - foreach ($subAdminOfGroups as $key => $group) { |
|
| 96 | - $subAdminOfGroups[$key] = $group->getGID(); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - if($offset === null) { |
|
| 100 | - $offset = 0; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - $users = []; |
|
| 104 | - foreach ($subAdminOfGroups as $group) { |
|
| 105 | - $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search)); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $users = array_slice($users, $offset, $limit); |
|
| 109 | - } else { |
|
| 110 | - return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 111 | - } |
|
| 112 | - $users = array_keys($users); |
|
| 113 | - |
|
| 114 | - return new \OC\OCS\Result([ |
|
| 115 | - 'users' => $users |
|
| 116 | - ]); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @return \OC\OCS\Result |
|
| 121 | - */ |
|
| 122 | - public function addUser() { |
|
| 123 | - $userId = isset($_POST['userid']) ? $_POST['userid'] : null; |
|
| 124 | - $password = isset($_POST['password']) ? $_POST['password'] : null; |
|
| 125 | - $groups = isset($_POST['groups']) ? $_POST['groups'] : null; |
|
| 126 | - $user = $this->userSession->getUser(); |
|
| 127 | - $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
| 128 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 129 | - |
|
| 130 | - if (!$isAdmin && !$subAdminManager->isSubAdmin($user)) { |
|
| 131 | - return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - if($this->userManager->userExists($userId)) { |
|
| 135 | - $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
|
| 136 | - return new \OC\OCS\Result(null, 102, 'User already exists'); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - if(is_array($groups)) { |
|
| 140 | - foreach ($groups as $group) { |
|
| 141 | - if(!$this->groupManager->groupExists($group)){ |
|
| 142 | - return new \OC\OCS\Result(null, 104, 'group '.$group.' does not exist'); |
|
| 143 | - } |
|
| 144 | - if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
| 145 | - return new \OC\OCS\Result(null, 105, 'insufficient privileges for group '. $group); |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - } else { |
|
| 149 | - if(!$isAdmin) { |
|
| 150 | - return new \OC\OCS\Result(null, 106, 'no group specified (required for subadmins)'); |
|
| 151 | - } |
|
| 152 | - } |
|
| 42 | + /** @var IUserManager */ |
|
| 43 | + private $userManager; |
|
| 44 | + /** @var IConfig */ |
|
| 45 | + private $config; |
|
| 46 | + /** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface |
|
| 47 | + private $groupManager; |
|
| 48 | + /** @var IUserSession */ |
|
| 49 | + private $userSession; |
|
| 50 | + /** @var ILogger */ |
|
| 51 | + private $logger; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param IUserManager $userManager |
|
| 55 | + * @param IConfig $config |
|
| 56 | + * @param IGroupManager $groupManager |
|
| 57 | + * @param IUserSession $userSession |
|
| 58 | + * @param ILogger $logger |
|
| 59 | + */ |
|
| 60 | + public function __construct(IUserManager $userManager, |
|
| 61 | + IConfig $config, |
|
| 62 | + IGroupManager $groupManager, |
|
| 63 | + IUserSession $userSession, |
|
| 64 | + ILogger $logger) { |
|
| 65 | + $this->userManager = $userManager; |
|
| 66 | + $this->config = $config; |
|
| 67 | + $this->groupManager = $groupManager; |
|
| 68 | + $this->userSession = $userSession; |
|
| 69 | + $this->logger = $logger; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * returns a list of users |
|
| 74 | + * |
|
| 75 | + * @return \OC\OCS\Result |
|
| 76 | + */ |
|
| 77 | + public function getUsers() { |
|
| 78 | + $search = !empty($_GET['search']) ? $_GET['search'] : ''; |
|
| 79 | + $limit = !empty($_GET['limit']) ? $_GET['limit'] : null; |
|
| 80 | + $offset = !empty($_GET['offset']) ? $_GET['offset'] : null; |
|
| 81 | + |
|
| 82 | + // Check if user is logged in |
|
| 83 | + $user = $this->userSession->getUser(); |
|
| 84 | + if ($user === null) { |
|
| 85 | + return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + // Admin? Or SubAdmin? |
|
| 89 | + $uid = $user->getUID(); |
|
| 90 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 91 | + if($this->groupManager->isAdmin($uid)){ |
|
| 92 | + $users = $this->userManager->search($search, $limit, $offset); |
|
| 93 | + } else if ($subAdminManager->isSubAdmin($user)) { |
|
| 94 | + $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
|
| 95 | + foreach ($subAdminOfGroups as $key => $group) { |
|
| 96 | + $subAdminOfGroups[$key] = $group->getGID(); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + if($offset === null) { |
|
| 100 | + $offset = 0; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + $users = []; |
|
| 104 | + foreach ($subAdminOfGroups as $group) { |
|
| 105 | + $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search)); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $users = array_slice($users, $offset, $limit); |
|
| 109 | + } else { |
|
| 110 | + return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 111 | + } |
|
| 112 | + $users = array_keys($users); |
|
| 113 | + |
|
| 114 | + return new \OC\OCS\Result([ |
|
| 115 | + 'users' => $users |
|
| 116 | + ]); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @return \OC\OCS\Result |
|
| 121 | + */ |
|
| 122 | + public function addUser() { |
|
| 123 | + $userId = isset($_POST['userid']) ? $_POST['userid'] : null; |
|
| 124 | + $password = isset($_POST['password']) ? $_POST['password'] : null; |
|
| 125 | + $groups = isset($_POST['groups']) ? $_POST['groups'] : null; |
|
| 126 | + $user = $this->userSession->getUser(); |
|
| 127 | + $isAdmin = $this->groupManager->isAdmin($user->getUID()); |
|
| 128 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 129 | + |
|
| 130 | + if (!$isAdmin && !$subAdminManager->isSubAdmin($user)) { |
|
| 131 | + return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + if($this->userManager->userExists($userId)) { |
|
| 135 | + $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
|
| 136 | + return new \OC\OCS\Result(null, 102, 'User already exists'); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + if(is_array($groups)) { |
|
| 140 | + foreach ($groups as $group) { |
|
| 141 | + if(!$this->groupManager->groupExists($group)){ |
|
| 142 | + return new \OC\OCS\Result(null, 104, 'group '.$group.' does not exist'); |
|
| 143 | + } |
|
| 144 | + if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
| 145 | + return new \OC\OCS\Result(null, 105, 'insufficient privileges for group '. $group); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + } else { |
|
| 149 | + if(!$isAdmin) { |
|
| 150 | + return new \OC\OCS\Result(null, 106, 'no group specified (required for subadmins)'); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - try { |
|
| 155 | - $newUser = $this->userManager->createUser($userId, $password); |
|
| 156 | - $this->logger->info('Successful addUser call with userid: '.$userId, ['app' => 'ocs_api']); |
|
| 157 | - |
|
| 158 | - if (is_array($groups)) { |
|
| 159 | - foreach ($groups as $group) { |
|
| 160 | - $this->groupManager->get($group)->addUser($newUser); |
|
| 161 | - $this->logger->info('Added userid '.$userId.' to group '.$group, ['app' => 'ocs_api']); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - return new \OC\OCS\Result(null, 100); |
|
| 165 | - } catch (\Exception $e) { |
|
| 166 | - $this->logger->error('Failed addUser attempt with exception: '.$e->getMessage(), ['app' => 'ocs_api']); |
|
| 167 | - return new \OC\OCS\Result(null, 101, 'Bad request'); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * gets user info |
|
| 173 | - * |
|
| 174 | - * @param array $parameters |
|
| 175 | - * @return \OC\OCS\Result |
|
| 176 | - */ |
|
| 177 | - public function getUser($parameters) { |
|
| 178 | - $userId = $parameters['userid']; |
|
| 179 | - |
|
| 180 | - // Check if user is logged in |
|
| 181 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 182 | - if ($currentLoggedInUser === null) { |
|
| 183 | - return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $data = []; |
|
| 187 | - |
|
| 188 | - // Check if the target user exists |
|
| 189 | - $targetUserObject = $this->userManager->get($userId); |
|
| 190 | - if($targetUserObject === null) { |
|
| 191 | - return new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested user could not be found'); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - // Admin? Or SubAdmin? |
|
| 195 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 196 | - || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
| 197 | - $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true'); |
|
| 198 | - } else { |
|
| 199 | - // Check they are looking up themselves |
|
| 200 | - if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 201 | - return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // Find the data |
|
| 206 | - $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); |
|
| 207 | - $data['email'] = $targetUserObject->getEMailAddress(); |
|
| 208 | - $data['displayname'] = $targetUserObject->getDisplayName(); |
|
| 209 | - |
|
| 210 | - return new \OC\OCS\Result($data); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * edit users |
|
| 215 | - * |
|
| 216 | - * @param array $parameters |
|
| 217 | - * @return \OC\OCS\Result |
|
| 218 | - */ |
|
| 219 | - public function editUser($parameters) { |
|
| 220 | - /** @var string $targetUserId */ |
|
| 221 | - $targetUserId = $parameters['userid']; |
|
| 222 | - |
|
| 223 | - // Check if user is logged in |
|
| 224 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 225 | - if ($currentLoggedInUser === null) { |
|
| 226 | - return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $targetUser = $this->userManager->get($targetUserId); |
|
| 230 | - if($targetUser === null) { |
|
| 231 | - return new \OC\OCS\Result(null, 997); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - $permittedFields = []; |
|
| 235 | - if($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 236 | - // Editing self (display, email) |
|
| 237 | - $permittedFields[] = 'display'; |
|
| 238 | - $permittedFields[] = 'email'; |
|
| 239 | - $permittedFields[] = 'password'; |
|
| 240 | - // If admin they can edit their own quota |
|
| 241 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 242 | - $permittedFields[] = 'quota'; |
|
| 243 | - } |
|
| 244 | - } else { |
|
| 245 | - // Check if admin / subadmin |
|
| 246 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 247 | - if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 248 | - || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 249 | - // They have permissions over the user |
|
| 250 | - $permittedFields[] = 'display'; |
|
| 251 | - $permittedFields[] = 'quota'; |
|
| 252 | - $permittedFields[] = 'password'; |
|
| 253 | - $permittedFields[] = 'email'; |
|
| 254 | - } else { |
|
| 255 | - // No rights |
|
| 256 | - return new \OC\OCS\Result(null, 997); |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - // Check if permitted to edit this field |
|
| 260 | - if(!in_array($parameters['_put']['key'], $permittedFields)) { |
|
| 261 | - return new \OC\OCS\Result(null, 997); |
|
| 262 | - } |
|
| 263 | - // Process the edit |
|
| 264 | - switch($parameters['_put']['key']) { |
|
| 265 | - case 'display': |
|
| 266 | - $targetUser->setDisplayName($parameters['_put']['value']); |
|
| 267 | - break; |
|
| 268 | - case 'quota': |
|
| 269 | - $quota = $parameters['_put']['value']; |
|
| 270 | - if($quota !== 'none' and $quota !== 'default') { |
|
| 271 | - if (is_numeric($quota)) { |
|
| 272 | - $quota = floatval($quota); |
|
| 273 | - } else { |
|
| 274 | - $quota = \OCP\Util::computerFileSize($quota); |
|
| 275 | - } |
|
| 276 | - if ($quota === false) { |
|
| 277 | - return new \OC\OCS\Result(null, 103, "Invalid quota value {$parameters['_put']['value']}"); |
|
| 278 | - } |
|
| 279 | - if($quota === 0) { |
|
| 280 | - $quota = 'default'; |
|
| 281 | - }else if($quota === -1) { |
|
| 282 | - $quota = 'none'; |
|
| 283 | - } else { |
|
| 284 | - $quota = \OCP\Util::humanFileSize($quota); |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - $targetUser->setQuota($quota); |
|
| 288 | - break; |
|
| 289 | - case 'password': |
|
| 290 | - $targetUser->setPassword($parameters['_put']['value']); |
|
| 291 | - break; |
|
| 292 | - case 'email': |
|
| 293 | - if(filter_var($parameters['_put']['value'], FILTER_VALIDATE_EMAIL)) { |
|
| 294 | - $targetUser->setEMailAddress($parameters['_put']['value']); |
|
| 295 | - } else { |
|
| 296 | - return new \OC\OCS\Result(null, 102); |
|
| 297 | - } |
|
| 298 | - break; |
|
| 299 | - default: |
|
| 300 | - return new \OC\OCS\Result(null, 103); |
|
| 301 | - } |
|
| 302 | - return new \OC\OCS\Result(null, 100); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * @param array $parameters |
|
| 307 | - * @return \OC\OCS\Result |
|
| 308 | - */ |
|
| 309 | - public function deleteUser($parameters) { |
|
| 310 | - // Check if user is logged in |
|
| 311 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 312 | - if ($currentLoggedInUser === null) { |
|
| 313 | - return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - $targetUser = $this->userManager->get($parameters['userid']); |
|
| 317 | - |
|
| 318 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 319 | - return new \OC\OCS\Result(null, 101); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - // If not permitted |
|
| 323 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 324 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 325 | - return new \OC\OCS\Result(null, 997); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - // Go ahead with the delete |
|
| 329 | - if($targetUser->delete()) { |
|
| 330 | - return new \OC\OCS\Result(null, 100); |
|
| 331 | - } else { |
|
| 332 | - return new \OC\OCS\Result(null, 101); |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * @param array $parameters |
|
| 338 | - * @return \OC\OCS\Result |
|
| 339 | - */ |
|
| 340 | - public function disableUser($parameters) { |
|
| 341 | - return $this->setEnabled($parameters, false); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * @param array $parameters |
|
| 346 | - * @return \OC\OCS\Result |
|
| 347 | - */ |
|
| 348 | - public function enableUser($parameters) { |
|
| 349 | - return $this->setEnabled($parameters, true); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * @param array $parameters |
|
| 354 | - * @param bool $value |
|
| 355 | - * @return \OC\OCS\Result |
|
| 356 | - */ |
|
| 357 | - private function setEnabled($parameters, $value) { |
|
| 358 | - // Check if user is logged in |
|
| 359 | - $currentLoggedInUser = $this->userSession->getUser(); |
|
| 360 | - if ($currentLoggedInUser === null) { |
|
| 361 | - return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - $targetUser = $this->userManager->get($parameters['userid']); |
|
| 365 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 366 | - return new \OC\OCS\Result(null, 101); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - // If not permitted |
|
| 370 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 371 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 372 | - return new \OC\OCS\Result(null, 997); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - // enable/disable the user now |
|
| 376 | - $targetUser->setEnabled($value); |
|
| 377 | - return new \OC\OCS\Result(null, 100); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * @param array $parameters |
|
| 382 | - * @return \OC\OCS\Result |
|
| 383 | - */ |
|
| 384 | - public function getUsersGroups($parameters) { |
|
| 385 | - // Check if user is logged in |
|
| 386 | - $loggedInUser = $this->userSession->getUser(); |
|
| 387 | - if ($loggedInUser === null) { |
|
| 388 | - return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - $targetUser = $this->userManager->get($parameters['userid']); |
|
| 392 | - if($targetUser === null) { |
|
| 393 | - return new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 397 | - // Self lookup or admin lookup |
|
| 398 | - return new \OC\OCS\Result([ |
|
| 399 | - 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
|
| 400 | - ]); |
|
| 401 | - } else { |
|
| 402 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 403 | - |
|
| 404 | - // Looking up someone else |
|
| 405 | - if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
| 406 | - // Return the group that the method caller is subadmin of for the user in question |
|
| 407 | - $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
| 408 | - foreach ($getSubAdminsGroups as $key => $group) { |
|
| 409 | - $getSubAdminsGroups[$key] = $group->getGID(); |
|
| 410 | - } |
|
| 411 | - $groups = array_intersect( |
|
| 412 | - $getSubAdminsGroups, |
|
| 413 | - $this->groupManager->getUserGroupIds($targetUser) |
|
| 414 | - ); |
|
| 415 | - return new \OC\OCS\Result(array('groups' => $groups)); |
|
| 416 | - } else { |
|
| 417 | - // Not permitted |
|
| 418 | - return new \OC\OCS\Result(null, 997); |
|
| 419 | - } |
|
| 420 | - } |
|
| 154 | + try { |
|
| 155 | + $newUser = $this->userManager->createUser($userId, $password); |
|
| 156 | + $this->logger->info('Successful addUser call with userid: '.$userId, ['app' => 'ocs_api']); |
|
| 157 | + |
|
| 158 | + if (is_array($groups)) { |
|
| 159 | + foreach ($groups as $group) { |
|
| 160 | + $this->groupManager->get($group)->addUser($newUser); |
|
| 161 | + $this->logger->info('Added userid '.$userId.' to group '.$group, ['app' => 'ocs_api']); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + return new \OC\OCS\Result(null, 100); |
|
| 165 | + } catch (\Exception $e) { |
|
| 166 | + $this->logger->error('Failed addUser attempt with exception: '.$e->getMessage(), ['app' => 'ocs_api']); |
|
| 167 | + return new \OC\OCS\Result(null, 101, 'Bad request'); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * gets user info |
|
| 173 | + * |
|
| 174 | + * @param array $parameters |
|
| 175 | + * @return \OC\OCS\Result |
|
| 176 | + */ |
|
| 177 | + public function getUser($parameters) { |
|
| 178 | + $userId = $parameters['userid']; |
|
| 179 | + |
|
| 180 | + // Check if user is logged in |
|
| 181 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 182 | + if ($currentLoggedInUser === null) { |
|
| 183 | + return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $data = []; |
|
| 187 | + |
|
| 188 | + // Check if the target user exists |
|
| 189 | + $targetUserObject = $this->userManager->get($userId); |
|
| 190 | + if($targetUserObject === null) { |
|
| 191 | + return new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested user could not be found'); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + // Admin? Or SubAdmin? |
|
| 195 | + if($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 196 | + || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
|
| 197 | + $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true'); |
|
| 198 | + } else { |
|
| 199 | + // Check they are looking up themselves |
|
| 200 | + if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 201 | + return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // Find the data |
|
| 206 | + $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID()); |
|
| 207 | + $data['email'] = $targetUserObject->getEMailAddress(); |
|
| 208 | + $data['displayname'] = $targetUserObject->getDisplayName(); |
|
| 209 | + |
|
| 210 | + return new \OC\OCS\Result($data); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * edit users |
|
| 215 | + * |
|
| 216 | + * @param array $parameters |
|
| 217 | + * @return \OC\OCS\Result |
|
| 218 | + */ |
|
| 219 | + public function editUser($parameters) { |
|
| 220 | + /** @var string $targetUserId */ |
|
| 221 | + $targetUserId = $parameters['userid']; |
|
| 222 | + |
|
| 223 | + // Check if user is logged in |
|
| 224 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 225 | + if ($currentLoggedInUser === null) { |
|
| 226 | + return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $targetUser = $this->userManager->get($targetUserId); |
|
| 230 | + if($targetUser === null) { |
|
| 231 | + return new \OC\OCS\Result(null, 997); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + $permittedFields = []; |
|
| 235 | + if($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 236 | + // Editing self (display, email) |
|
| 237 | + $permittedFields[] = 'display'; |
|
| 238 | + $permittedFields[] = 'email'; |
|
| 239 | + $permittedFields[] = 'password'; |
|
| 240 | + // If admin they can edit their own quota |
|
| 241 | + if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 242 | + $permittedFields[] = 'quota'; |
|
| 243 | + } |
|
| 244 | + } else { |
|
| 245 | + // Check if admin / subadmin |
|
| 246 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 247 | + if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 248 | + || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 249 | + // They have permissions over the user |
|
| 250 | + $permittedFields[] = 'display'; |
|
| 251 | + $permittedFields[] = 'quota'; |
|
| 252 | + $permittedFields[] = 'password'; |
|
| 253 | + $permittedFields[] = 'email'; |
|
| 254 | + } else { |
|
| 255 | + // No rights |
|
| 256 | + return new \OC\OCS\Result(null, 997); |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + // Check if permitted to edit this field |
|
| 260 | + if(!in_array($parameters['_put']['key'], $permittedFields)) { |
|
| 261 | + return new \OC\OCS\Result(null, 997); |
|
| 262 | + } |
|
| 263 | + // Process the edit |
|
| 264 | + switch($parameters['_put']['key']) { |
|
| 265 | + case 'display': |
|
| 266 | + $targetUser->setDisplayName($parameters['_put']['value']); |
|
| 267 | + break; |
|
| 268 | + case 'quota': |
|
| 269 | + $quota = $parameters['_put']['value']; |
|
| 270 | + if($quota !== 'none' and $quota !== 'default') { |
|
| 271 | + if (is_numeric($quota)) { |
|
| 272 | + $quota = floatval($quota); |
|
| 273 | + } else { |
|
| 274 | + $quota = \OCP\Util::computerFileSize($quota); |
|
| 275 | + } |
|
| 276 | + if ($quota === false) { |
|
| 277 | + return new \OC\OCS\Result(null, 103, "Invalid quota value {$parameters['_put']['value']}"); |
|
| 278 | + } |
|
| 279 | + if($quota === 0) { |
|
| 280 | + $quota = 'default'; |
|
| 281 | + }else if($quota === -1) { |
|
| 282 | + $quota = 'none'; |
|
| 283 | + } else { |
|
| 284 | + $quota = \OCP\Util::humanFileSize($quota); |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + $targetUser->setQuota($quota); |
|
| 288 | + break; |
|
| 289 | + case 'password': |
|
| 290 | + $targetUser->setPassword($parameters['_put']['value']); |
|
| 291 | + break; |
|
| 292 | + case 'email': |
|
| 293 | + if(filter_var($parameters['_put']['value'], FILTER_VALIDATE_EMAIL)) { |
|
| 294 | + $targetUser->setEMailAddress($parameters['_put']['value']); |
|
| 295 | + } else { |
|
| 296 | + return new \OC\OCS\Result(null, 102); |
|
| 297 | + } |
|
| 298 | + break; |
|
| 299 | + default: |
|
| 300 | + return new \OC\OCS\Result(null, 103); |
|
| 301 | + } |
|
| 302 | + return new \OC\OCS\Result(null, 100); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * @param array $parameters |
|
| 307 | + * @return \OC\OCS\Result |
|
| 308 | + */ |
|
| 309 | + public function deleteUser($parameters) { |
|
| 310 | + // Check if user is logged in |
|
| 311 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 312 | + if ($currentLoggedInUser === null) { |
|
| 313 | + return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + $targetUser = $this->userManager->get($parameters['userid']); |
|
| 317 | + |
|
| 318 | + if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 319 | + return new \OC\OCS\Result(null, 101); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + // If not permitted |
|
| 323 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 324 | + if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 325 | + return new \OC\OCS\Result(null, 997); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + // Go ahead with the delete |
|
| 329 | + if($targetUser->delete()) { |
|
| 330 | + return new \OC\OCS\Result(null, 100); |
|
| 331 | + } else { |
|
| 332 | + return new \OC\OCS\Result(null, 101); |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * @param array $parameters |
|
| 338 | + * @return \OC\OCS\Result |
|
| 339 | + */ |
|
| 340 | + public function disableUser($parameters) { |
|
| 341 | + return $this->setEnabled($parameters, false); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * @param array $parameters |
|
| 346 | + * @return \OC\OCS\Result |
|
| 347 | + */ |
|
| 348 | + public function enableUser($parameters) { |
|
| 349 | + return $this->setEnabled($parameters, true); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * @param array $parameters |
|
| 354 | + * @param bool $value |
|
| 355 | + * @return \OC\OCS\Result |
|
| 356 | + */ |
|
| 357 | + private function setEnabled($parameters, $value) { |
|
| 358 | + // Check if user is logged in |
|
| 359 | + $currentLoggedInUser = $this->userSession->getUser(); |
|
| 360 | + if ($currentLoggedInUser === null) { |
|
| 361 | + return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + $targetUser = $this->userManager->get($parameters['userid']); |
|
| 365 | + if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 366 | + return new \OC\OCS\Result(null, 101); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + // If not permitted |
|
| 370 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 371 | + if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 372 | + return new \OC\OCS\Result(null, 997); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + // enable/disable the user now |
|
| 376 | + $targetUser->setEnabled($value); |
|
| 377 | + return new \OC\OCS\Result(null, 100); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * @param array $parameters |
|
| 382 | + * @return \OC\OCS\Result |
|
| 383 | + */ |
|
| 384 | + public function getUsersGroups($parameters) { |
|
| 385 | + // Check if user is logged in |
|
| 386 | + $loggedInUser = $this->userSession->getUser(); |
|
| 387 | + if ($loggedInUser === null) { |
|
| 388 | + return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + $targetUser = $this->userManager->get($parameters['userid']); |
|
| 392 | + if($targetUser === null) { |
|
| 393 | + return new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 397 | + // Self lookup or admin lookup |
|
| 398 | + return new \OC\OCS\Result([ |
|
| 399 | + 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
|
| 400 | + ]); |
|
| 401 | + } else { |
|
| 402 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 403 | + |
|
| 404 | + // Looking up someone else |
|
| 405 | + if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
| 406 | + // Return the group that the method caller is subadmin of for the user in question |
|
| 407 | + $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
| 408 | + foreach ($getSubAdminsGroups as $key => $group) { |
|
| 409 | + $getSubAdminsGroups[$key] = $group->getGID(); |
|
| 410 | + } |
|
| 411 | + $groups = array_intersect( |
|
| 412 | + $getSubAdminsGroups, |
|
| 413 | + $this->groupManager->getUserGroupIds($targetUser) |
|
| 414 | + ); |
|
| 415 | + return new \OC\OCS\Result(array('groups' => $groups)); |
|
| 416 | + } else { |
|
| 417 | + // Not permitted |
|
| 418 | + return new \OC\OCS\Result(null, 997); |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | 421 | |
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * @param array $parameters |
|
| 426 | - * @return \OC\OCS\Result |
|
| 427 | - */ |
|
| 428 | - public function addToGroup($parameters) { |
|
| 429 | - // Check if user is logged in |
|
| 430 | - $user = $this->userSession->getUser(); |
|
| 431 | - if ($user === null) { |
|
| 432 | - return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - // Check they're an admin |
|
| 436 | - if(!$this->groupManager->isAdmin($user->getUID())) { |
|
| 437 | - // This user doesn't have rights to add a user to this group |
|
| 438 | - return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - $groupId = !empty($_POST['groupid']) ? $_POST['groupid'] : null; |
|
| 442 | - if($groupId === null) { |
|
| 443 | - return new \OC\OCS\Result(null, 101); |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - $group = $this->groupManager->get($groupId); |
|
| 447 | - $targetUser = $this->userManager->get($parameters['userid']); |
|
| 448 | - if($group === null) { |
|
| 449 | - return new \OC\OCS\Result(null, 102); |
|
| 450 | - } |
|
| 451 | - if($targetUser === null) { |
|
| 452 | - return new \OC\OCS\Result(null, 103); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - // Add user to group |
|
| 456 | - $group->addUser($targetUser); |
|
| 457 | - return new \OC\OCS\Result(null, 100); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * @param array $parameters |
|
| 462 | - * @return \OC\OCS\Result |
|
| 463 | - */ |
|
| 464 | - public function removeFromGroup($parameters) { |
|
| 465 | - // Check if user is logged in |
|
| 466 | - $loggedInUser = $this->userSession->getUser(); |
|
| 467 | - if ($loggedInUser === null) { |
|
| 468 | - return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - $group = !empty($parameters['_delete']['groupid']) ? $parameters['_delete']['groupid'] : null; |
|
| 472 | - if($group === null) { |
|
| 473 | - return new \OC\OCS\Result(null, 101); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - $group = $this->groupManager->get($group); |
|
| 477 | - if($group === null) { |
|
| 478 | - return new \OC\OCS\Result(null, 102); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - $targetUser = $this->userManager->get($parameters['userid']); |
|
| 482 | - if($targetUser === null) { |
|
| 483 | - return new \OC\OCS\Result(null, 103); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - // If they're not an admin, check they are a subadmin of the group in question |
|
| 487 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 488 | - if(!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminofGroup($loggedInUser, $group)) { |
|
| 489 | - return new \OC\OCS\Result(null, 104); |
|
| 490 | - } |
|
| 491 | - // Check they aren't removing themselves from 'admin' or their 'subadmin; group |
|
| 492 | - if($targetUser->getUID() === $loggedInUser->getUID()) { |
|
| 493 | - if($this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 494 | - if($group->getGID() === 'admin') { |
|
| 495 | - return new \OC\OCS\Result(null, 105, 'Cannot remove yourself from the admin group'); |
|
| 496 | - } |
|
| 497 | - } else { |
|
| 498 | - // Not an admin, check they are not removing themself from their subadmin group |
|
| 499 | - $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
| 500 | - foreach ($subAdminGroups as $key => $group) { |
|
| 501 | - $subAdminGroups[$key] = $group->getGID(); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - if(in_array($group->getGID(), $subAdminGroups, true)) { |
|
| 505 | - return new \OC\OCS\Result(null, 105, 'Cannot remove yourself from this group as you are a SubAdmin'); |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - // Remove user from group |
|
| 511 | - $group->removeUser($targetUser); |
|
| 512 | - return new \OC\OCS\Result(null, 100); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Creates a subadmin |
|
| 517 | - * |
|
| 518 | - * @param array $parameters |
|
| 519 | - * @return \OC\OCS\Result |
|
| 520 | - */ |
|
| 521 | - public function addSubAdmin($parameters) { |
|
| 522 | - $group = $this->groupManager->get($_POST['groupid']); |
|
| 523 | - $user = $this->userManager->get($parameters['userid']); |
|
| 524 | - |
|
| 525 | - // Check if the user exists |
|
| 526 | - if($user === null) { |
|
| 527 | - return new \OC\OCS\Result(null, 101, 'User does not exist'); |
|
| 528 | - } |
|
| 529 | - // Check if group exists |
|
| 530 | - if($group === null) { |
|
| 531 | - return new \OC\OCS\Result(null, 102, 'Group:'.$_POST['groupid'].' does not exist'); |
|
| 532 | - } |
|
| 533 | - // Check if trying to make subadmin of admin group |
|
| 534 | - if(strtolower($_POST['groupid']) === 'admin') { |
|
| 535 | - return new \OC\OCS\Result(null, 103, 'Cannot create subadmins for admin group'); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 539 | - |
|
| 540 | - // We cannot be subadmin twice |
|
| 541 | - if ($subAdminManager->isSubAdminofGroup($user, $group)) { |
|
| 542 | - return new \OC\OCS\Result(null, 100); |
|
| 543 | - } |
|
| 544 | - // Go |
|
| 545 | - if($subAdminManager->createSubAdmin($user, $group)) { |
|
| 546 | - return new \OC\OCS\Result(null, 100); |
|
| 547 | - } else { |
|
| 548 | - return new \OC\OCS\Result(null, 103, 'Unknown error occurred'); |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * Removes a subadmin from a group |
|
| 554 | - * |
|
| 555 | - * @param array $parameters |
|
| 556 | - * @return \OC\OCS\Result |
|
| 557 | - */ |
|
| 558 | - public function removeSubAdmin($parameters) { |
|
| 559 | - $group = $this->groupManager->get($parameters['_delete']['groupid']); |
|
| 560 | - $user = $this->userManager->get($parameters['userid']); |
|
| 561 | - $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 562 | - |
|
| 563 | - // Check if the user exists |
|
| 564 | - if($user === null) { |
|
| 565 | - return new \OC\OCS\Result(null, 101, 'User does not exist'); |
|
| 566 | - } |
|
| 567 | - // Check if the group exists |
|
| 568 | - if($group === null) { |
|
| 569 | - return new \OC\OCS\Result(null, 101, 'Group does not exist'); |
|
| 570 | - } |
|
| 571 | - // Check if they are a subadmin of this said group |
|
| 572 | - if(!$subAdminManager->isSubAdminofGroup($user, $group)) { |
|
| 573 | - return new \OC\OCS\Result(null, 102, 'User is not a subadmin of this group'); |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - // Go |
|
| 577 | - if($subAdminManager->deleteSubAdmin($user, $group)) { |
|
| 578 | - return new \OC\OCS\Result(null, 100); |
|
| 579 | - } else { |
|
| 580 | - return new \OC\OCS\Result(null, 103, 'Unknown error occurred'); |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * Get the groups a user is a subadmin of |
|
| 586 | - * |
|
| 587 | - * @param array $parameters |
|
| 588 | - * @return \OC\OCS\Result |
|
| 589 | - */ |
|
| 590 | - public function getUserSubAdminGroups($parameters) { |
|
| 591 | - $user = $this->userManager->get($parameters['userid']); |
|
| 592 | - // Check if the user exists |
|
| 593 | - if($user === null) { |
|
| 594 | - return new \OC\OCS\Result(null, 101, 'User does not exist'); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - // Get the subadmin groups |
|
| 598 | - $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
| 599 | - foreach ($groups as $key => $group) { |
|
| 600 | - $groups[$key] = $group->getGID(); |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - if(!$groups) { |
|
| 604 | - return new \OC\OCS\Result(null, 102, 'Unknown error occurred'); |
|
| 605 | - } else { |
|
| 606 | - return new \OC\OCS\Result($groups); |
|
| 607 | - } |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - /** |
|
| 611 | - * @param string $userId |
|
| 612 | - * @return array |
|
| 613 | - * @throws \OCP\Files\NotFoundException |
|
| 614 | - */ |
|
| 615 | - protected function fillStorageInfo($userId) { |
|
| 616 | - try { |
|
| 617 | - \OC_Util::tearDownFS(); |
|
| 618 | - \OC_Util::setupFS($userId); |
|
| 619 | - $storage = OC_Helper::getStorageInfo('/'); |
|
| 620 | - $data = [ |
|
| 621 | - 'free' => $storage['free'], |
|
| 622 | - 'used' => $storage['used'], |
|
| 623 | - 'total' => $storage['total'], |
|
| 624 | - 'relative' => $storage['relative'], |
|
| 625 | - 'quota' => $storage['quota'], |
|
| 626 | - ]; |
|
| 627 | - } catch (NotFoundException $ex) { |
|
| 628 | - $data = []; |
|
| 629 | - } |
|
| 630 | - return $data; |
|
| 631 | - } |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * @param array $parameters |
|
| 426 | + * @return \OC\OCS\Result |
|
| 427 | + */ |
|
| 428 | + public function addToGroup($parameters) { |
|
| 429 | + // Check if user is logged in |
|
| 430 | + $user = $this->userSession->getUser(); |
|
| 431 | + if ($user === null) { |
|
| 432 | + return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + // Check they're an admin |
|
| 436 | + if(!$this->groupManager->isAdmin($user->getUID())) { |
|
| 437 | + // This user doesn't have rights to add a user to this group |
|
| 438 | + return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + $groupId = !empty($_POST['groupid']) ? $_POST['groupid'] : null; |
|
| 442 | + if($groupId === null) { |
|
| 443 | + return new \OC\OCS\Result(null, 101); |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + $group = $this->groupManager->get($groupId); |
|
| 447 | + $targetUser = $this->userManager->get($parameters['userid']); |
|
| 448 | + if($group === null) { |
|
| 449 | + return new \OC\OCS\Result(null, 102); |
|
| 450 | + } |
|
| 451 | + if($targetUser === null) { |
|
| 452 | + return new \OC\OCS\Result(null, 103); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + // Add user to group |
|
| 456 | + $group->addUser($targetUser); |
|
| 457 | + return new \OC\OCS\Result(null, 100); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * @param array $parameters |
|
| 462 | + * @return \OC\OCS\Result |
|
| 463 | + */ |
|
| 464 | + public function removeFromGroup($parameters) { |
|
| 465 | + // Check if user is logged in |
|
| 466 | + $loggedInUser = $this->userSession->getUser(); |
|
| 467 | + if ($loggedInUser === null) { |
|
| 468 | + return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + $group = !empty($parameters['_delete']['groupid']) ? $parameters['_delete']['groupid'] : null; |
|
| 472 | + if($group === null) { |
|
| 473 | + return new \OC\OCS\Result(null, 101); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + $group = $this->groupManager->get($group); |
|
| 477 | + if($group === null) { |
|
| 478 | + return new \OC\OCS\Result(null, 102); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + $targetUser = $this->userManager->get($parameters['userid']); |
|
| 482 | + if($targetUser === null) { |
|
| 483 | + return new \OC\OCS\Result(null, 103); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + // If they're not an admin, check they are a subadmin of the group in question |
|
| 487 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 488 | + if(!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminofGroup($loggedInUser, $group)) { |
|
| 489 | + return new \OC\OCS\Result(null, 104); |
|
| 490 | + } |
|
| 491 | + // Check they aren't removing themselves from 'admin' or their 'subadmin; group |
|
| 492 | + if($targetUser->getUID() === $loggedInUser->getUID()) { |
|
| 493 | + if($this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 494 | + if($group->getGID() === 'admin') { |
|
| 495 | + return new \OC\OCS\Result(null, 105, 'Cannot remove yourself from the admin group'); |
|
| 496 | + } |
|
| 497 | + } else { |
|
| 498 | + // Not an admin, check they are not removing themself from their subadmin group |
|
| 499 | + $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
|
| 500 | + foreach ($subAdminGroups as $key => $group) { |
|
| 501 | + $subAdminGroups[$key] = $group->getGID(); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + if(in_array($group->getGID(), $subAdminGroups, true)) { |
|
| 505 | + return new \OC\OCS\Result(null, 105, 'Cannot remove yourself from this group as you are a SubAdmin'); |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + // Remove user from group |
|
| 511 | + $group->removeUser($targetUser); |
|
| 512 | + return new \OC\OCS\Result(null, 100); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Creates a subadmin |
|
| 517 | + * |
|
| 518 | + * @param array $parameters |
|
| 519 | + * @return \OC\OCS\Result |
|
| 520 | + */ |
|
| 521 | + public function addSubAdmin($parameters) { |
|
| 522 | + $group = $this->groupManager->get($_POST['groupid']); |
|
| 523 | + $user = $this->userManager->get($parameters['userid']); |
|
| 524 | + |
|
| 525 | + // Check if the user exists |
|
| 526 | + if($user === null) { |
|
| 527 | + return new \OC\OCS\Result(null, 101, 'User does not exist'); |
|
| 528 | + } |
|
| 529 | + // Check if group exists |
|
| 530 | + if($group === null) { |
|
| 531 | + return new \OC\OCS\Result(null, 102, 'Group:'.$_POST['groupid'].' does not exist'); |
|
| 532 | + } |
|
| 533 | + // Check if trying to make subadmin of admin group |
|
| 534 | + if(strtolower($_POST['groupid']) === 'admin') { |
|
| 535 | + return new \OC\OCS\Result(null, 103, 'Cannot create subadmins for admin group'); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 539 | + |
|
| 540 | + // We cannot be subadmin twice |
|
| 541 | + if ($subAdminManager->isSubAdminofGroup($user, $group)) { |
|
| 542 | + return new \OC\OCS\Result(null, 100); |
|
| 543 | + } |
|
| 544 | + // Go |
|
| 545 | + if($subAdminManager->createSubAdmin($user, $group)) { |
|
| 546 | + return new \OC\OCS\Result(null, 100); |
|
| 547 | + } else { |
|
| 548 | + return new \OC\OCS\Result(null, 103, 'Unknown error occurred'); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * Removes a subadmin from a group |
|
| 554 | + * |
|
| 555 | + * @param array $parameters |
|
| 556 | + * @return \OC\OCS\Result |
|
| 557 | + */ |
|
| 558 | + public function removeSubAdmin($parameters) { |
|
| 559 | + $group = $this->groupManager->get($parameters['_delete']['groupid']); |
|
| 560 | + $user = $this->userManager->get($parameters['userid']); |
|
| 561 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
|
| 562 | + |
|
| 563 | + // Check if the user exists |
|
| 564 | + if($user === null) { |
|
| 565 | + return new \OC\OCS\Result(null, 101, 'User does not exist'); |
|
| 566 | + } |
|
| 567 | + // Check if the group exists |
|
| 568 | + if($group === null) { |
|
| 569 | + return new \OC\OCS\Result(null, 101, 'Group does not exist'); |
|
| 570 | + } |
|
| 571 | + // Check if they are a subadmin of this said group |
|
| 572 | + if(!$subAdminManager->isSubAdminofGroup($user, $group)) { |
|
| 573 | + return new \OC\OCS\Result(null, 102, 'User is not a subadmin of this group'); |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + // Go |
|
| 577 | + if($subAdminManager->deleteSubAdmin($user, $group)) { |
|
| 578 | + return new \OC\OCS\Result(null, 100); |
|
| 579 | + } else { |
|
| 580 | + return new \OC\OCS\Result(null, 103, 'Unknown error occurred'); |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * Get the groups a user is a subadmin of |
|
| 586 | + * |
|
| 587 | + * @param array $parameters |
|
| 588 | + * @return \OC\OCS\Result |
|
| 589 | + */ |
|
| 590 | + public function getUserSubAdminGroups($parameters) { |
|
| 591 | + $user = $this->userManager->get($parameters['userid']); |
|
| 592 | + // Check if the user exists |
|
| 593 | + if($user === null) { |
|
| 594 | + return new \OC\OCS\Result(null, 101, 'User does not exist'); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + // Get the subadmin groups |
|
| 598 | + $groups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user); |
|
| 599 | + foreach ($groups as $key => $group) { |
|
| 600 | + $groups[$key] = $group->getGID(); |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + if(!$groups) { |
|
| 604 | + return new \OC\OCS\Result(null, 102, 'Unknown error occurred'); |
|
| 605 | + } else { |
|
| 606 | + return new \OC\OCS\Result($groups); |
|
| 607 | + } |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + /** |
|
| 611 | + * @param string $userId |
|
| 612 | + * @return array |
|
| 613 | + * @throws \OCP\Files\NotFoundException |
|
| 614 | + */ |
|
| 615 | + protected function fillStorageInfo($userId) { |
|
| 616 | + try { |
|
| 617 | + \OC_Util::tearDownFS(); |
|
| 618 | + \OC_Util::setupFS($userId); |
|
| 619 | + $storage = OC_Helper::getStorageInfo('/'); |
|
| 620 | + $data = [ |
|
| 621 | + 'free' => $storage['free'], |
|
| 622 | + 'used' => $storage['used'], |
|
| 623 | + 'total' => $storage['total'], |
|
| 624 | + 'relative' => $storage['relative'], |
|
| 625 | + 'quota' => $storage['quota'], |
|
| 626 | + ]; |
|
| 627 | + } catch (NotFoundException $ex) { |
|
| 628 | + $data = []; |
|
| 629 | + } |
|
| 630 | + return $data; |
|
| 631 | + } |
|
| 632 | 632 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | // Admin? Or SubAdmin? |
| 89 | 89 | $uid = $user->getUID(); |
| 90 | 90 | $subAdminManager = $this->groupManager->getSubAdmin(); |
| 91 | - if($this->groupManager->isAdmin($uid)){ |
|
| 91 | + if ($this->groupManager->isAdmin($uid)) { |
|
| 92 | 92 | $users = $this->userManager->search($search, $limit, $offset); |
| 93 | 93 | } else if ($subAdminManager->isSubAdmin($user)) { |
| 94 | 94 | $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user); |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | $subAdminOfGroups[$key] = $group->getGID(); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if($offset === null) { |
|
| 99 | + if ($offset === null) { |
|
| 100 | 100 | $offset = 0; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -131,22 +131,22 @@ discard block |
||
| 131 | 131 | return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - if($this->userManager->userExists($userId)) { |
|
| 134 | + if ($this->userManager->userExists($userId)) { |
|
| 135 | 135 | $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']); |
| 136 | 136 | return new \OC\OCS\Result(null, 102, 'User already exists'); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - if(is_array($groups)) { |
|
| 139 | + if (is_array($groups)) { |
|
| 140 | 140 | foreach ($groups as $group) { |
| 141 | - if(!$this->groupManager->groupExists($group)){ |
|
| 141 | + if (!$this->groupManager->groupExists($group)) { |
|
| 142 | 142 | return new \OC\OCS\Result(null, 104, 'group '.$group.' does not exist'); |
| 143 | 143 | } |
| 144 | - if(!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
| 145 | - return new \OC\OCS\Result(null, 105, 'insufficient privileges for group '. $group); |
|
| 144 | + if (!$isAdmin && !$subAdminManager->isSubAdminofGroup($user, $this->groupManager->get($group))) { |
|
| 145 | + return new \OC\OCS\Result(null, 105, 'insufficient privileges for group '.$group); |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | } else { |
| 149 | - if(!$isAdmin) { |
|
| 149 | + if (!$isAdmin) { |
|
| 150 | 150 | return new \OC\OCS\Result(null, 106, 'no group specified (required for subadmins)'); |
| 151 | 151 | } |
| 152 | 152 | } |
@@ -187,17 +187,17 @@ discard block |
||
| 187 | 187 | |
| 188 | 188 | // Check if the target user exists |
| 189 | 189 | $targetUserObject = $this->userManager->get($userId); |
| 190 | - if($targetUserObject === null) { |
|
| 190 | + if ($targetUserObject === null) { |
|
| 191 | 191 | return new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The requested user could not be found'); |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | // Admin? Or SubAdmin? |
| 195 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 195 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
|
| 196 | 196 | || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) { |
| 197 | 197 | $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true'); |
| 198 | 198 | } else { |
| 199 | 199 | // Check they are looking up themselves |
| 200 | - if($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 200 | + if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) { |
|
| 201 | 201 | return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
| 202 | 202 | } |
| 203 | 203 | } |
@@ -227,24 +227,24 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | $targetUser = $this->userManager->get($targetUserId); |
| 230 | - if($targetUser === null) { |
|
| 230 | + if ($targetUser === null) { |
|
| 231 | 231 | return new \OC\OCS\Result(null, 997); |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | $permittedFields = []; |
| 235 | - if($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 235 | + if ($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 236 | 236 | // Editing self (display, email) |
| 237 | 237 | $permittedFields[] = 'display'; |
| 238 | 238 | $permittedFields[] = 'email'; |
| 239 | 239 | $permittedFields[] = 'password'; |
| 240 | 240 | // If admin they can edit their own quota |
| 241 | - if($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 241 | + if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
|
| 242 | 242 | $permittedFields[] = 'quota'; |
| 243 | 243 | } |
| 244 | 244 | } else { |
| 245 | 245 | // Check if admin / subadmin |
| 246 | 246 | $subAdminManager = $this->groupManager->getSubAdmin(); |
| 247 | - if($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 247 | + if ($subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser) |
|
| 248 | 248 | || $this->groupManager->isAdmin($currentLoggedInUser->getUID())) { |
| 249 | 249 | // They have permissions over the user |
| 250 | 250 | $permittedFields[] = 'display'; |
@@ -257,17 +257,17 @@ discard block |
||
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | // Check if permitted to edit this field |
| 260 | - if(!in_array($parameters['_put']['key'], $permittedFields)) { |
|
| 260 | + if (!in_array($parameters['_put']['key'], $permittedFields)) { |
|
| 261 | 261 | return new \OC\OCS\Result(null, 997); |
| 262 | 262 | } |
| 263 | 263 | // Process the edit |
| 264 | - switch($parameters['_put']['key']) { |
|
| 264 | + switch ($parameters['_put']['key']) { |
|
| 265 | 265 | case 'display': |
| 266 | 266 | $targetUser->setDisplayName($parameters['_put']['value']); |
| 267 | 267 | break; |
| 268 | 268 | case 'quota': |
| 269 | 269 | $quota = $parameters['_put']['value']; |
| 270 | - if($quota !== 'none' and $quota !== 'default') { |
|
| 270 | + if ($quota !== 'none' and $quota !== 'default') { |
|
| 271 | 271 | if (is_numeric($quota)) { |
| 272 | 272 | $quota = floatval($quota); |
| 273 | 273 | } else { |
@@ -276,9 +276,9 @@ discard block |
||
| 276 | 276 | if ($quota === false) { |
| 277 | 277 | return new \OC\OCS\Result(null, 103, "Invalid quota value {$parameters['_put']['value']}"); |
| 278 | 278 | } |
| 279 | - if($quota === 0) { |
|
| 279 | + if ($quota === 0) { |
|
| 280 | 280 | $quota = 'default'; |
| 281 | - }else if($quota === -1) { |
|
| 281 | + } else if ($quota === -1) { |
|
| 282 | 282 | $quota = 'none'; |
| 283 | 283 | } else { |
| 284 | 284 | $quota = \OCP\Util::humanFileSize($quota); |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | $targetUser->setPassword($parameters['_put']['value']); |
| 291 | 291 | break; |
| 292 | 292 | case 'email': |
| 293 | - if(filter_var($parameters['_put']['value'], FILTER_VALIDATE_EMAIL)) { |
|
| 293 | + if (filter_var($parameters['_put']['value'], FILTER_VALIDATE_EMAIL)) { |
|
| 294 | 294 | $targetUser->setEMailAddress($parameters['_put']['value']); |
| 295 | 295 | } else { |
| 296 | 296 | return new \OC\OCS\Result(null, 102); |
@@ -315,18 +315,18 @@ discard block |
||
| 315 | 315 | |
| 316 | 316 | $targetUser = $this->userManager->get($parameters['userid']); |
| 317 | 317 | |
| 318 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 318 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 319 | 319 | return new \OC\OCS\Result(null, 101); |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | // If not permitted |
| 323 | 323 | $subAdminManager = $this->groupManager->getSubAdmin(); |
| 324 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 324 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 325 | 325 | return new \OC\OCS\Result(null, 997); |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | // Go ahead with the delete |
| 329 | - if($targetUser->delete()) { |
|
| 329 | + if ($targetUser->delete()) { |
|
| 330 | 330 | return new \OC\OCS\Result(null, 100); |
| 331 | 331 | } else { |
| 332 | 332 | return new \OC\OCS\Result(null, 101); |
@@ -362,13 +362,13 @@ discard block |
||
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | $targetUser = $this->userManager->get($parameters['userid']); |
| 365 | - if($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 365 | + if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) { |
|
| 366 | 366 | return new \OC\OCS\Result(null, 101); |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | // If not permitted |
| 370 | 370 | $subAdminManager = $this->groupManager->getSubAdmin(); |
| 371 | - if(!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 371 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
|
| 372 | 372 | return new \OC\OCS\Result(null, 997); |
| 373 | 373 | } |
| 374 | 374 | |
@@ -389,11 +389,11 @@ discard block |
||
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | $targetUser = $this->userManager->get($parameters['userid']); |
| 392 | - if($targetUser === null) { |
|
| 392 | + if ($targetUser === null) { |
|
| 393 | 393 | return new \OC\OCS\Result(null, \OCP\API::RESPOND_NOT_FOUND); |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - if($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 396 | + if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 397 | 397 | // Self lookup or admin lookup |
| 398 | 398 | return new \OC\OCS\Result([ |
| 399 | 399 | 'groups' => $this->groupManager->getUserGroupIds($targetUser) |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | $subAdminManager = $this->groupManager->getSubAdmin(); |
| 403 | 403 | |
| 404 | 404 | // Looking up someone else |
| 405 | - if($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
| 405 | + if ($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) { |
|
| 406 | 406 | // Return the group that the method caller is subadmin of for the user in question |
| 407 | 407 | $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser); |
| 408 | 408 | foreach ($getSubAdminsGroups as $key => $group) { |
@@ -433,22 +433,22 @@ discard block |
||
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | // Check they're an admin |
| 436 | - if(!$this->groupManager->isAdmin($user->getUID())) { |
|
| 436 | + if (!$this->groupManager->isAdmin($user->getUID())) { |
|
| 437 | 437 | // This user doesn't have rights to add a user to this group |
| 438 | 438 | return new \OC\OCS\Result(null, \OCP\API::RESPOND_UNAUTHORISED); |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | $groupId = !empty($_POST['groupid']) ? $_POST['groupid'] : null; |
| 442 | - if($groupId === null) { |
|
| 442 | + if ($groupId === null) { |
|
| 443 | 443 | return new \OC\OCS\Result(null, 101); |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | $group = $this->groupManager->get($groupId); |
| 447 | 447 | $targetUser = $this->userManager->get($parameters['userid']); |
| 448 | - if($group === null) { |
|
| 448 | + if ($group === null) { |
|
| 449 | 449 | return new \OC\OCS\Result(null, 102); |
| 450 | 450 | } |
| 451 | - if($targetUser === null) { |
|
| 451 | + if ($targetUser === null) { |
|
| 452 | 452 | return new \OC\OCS\Result(null, 103); |
| 453 | 453 | } |
| 454 | 454 | |
@@ -469,29 +469,29 @@ discard block |
||
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | $group = !empty($parameters['_delete']['groupid']) ? $parameters['_delete']['groupid'] : null; |
| 472 | - if($group === null) { |
|
| 472 | + if ($group === null) { |
|
| 473 | 473 | return new \OC\OCS\Result(null, 101); |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | $group = $this->groupManager->get($group); |
| 477 | - if($group === null) { |
|
| 477 | + if ($group === null) { |
|
| 478 | 478 | return new \OC\OCS\Result(null, 102); |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | $targetUser = $this->userManager->get($parameters['userid']); |
| 482 | - if($targetUser === null) { |
|
| 482 | + if ($targetUser === null) { |
|
| 483 | 483 | return new \OC\OCS\Result(null, 103); |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | // If they're not an admin, check they are a subadmin of the group in question |
| 487 | 487 | $subAdminManager = $this->groupManager->getSubAdmin(); |
| 488 | - if(!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminofGroup($loggedInUser, $group)) { |
|
| 488 | + if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminofGroup($loggedInUser, $group)) { |
|
| 489 | 489 | return new \OC\OCS\Result(null, 104); |
| 490 | 490 | } |
| 491 | 491 | // Check they aren't removing themselves from 'admin' or their 'subadmin; group |
| 492 | - if($targetUser->getUID() === $loggedInUser->getUID()) { |
|
| 493 | - if($this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 494 | - if($group->getGID() === 'admin') { |
|
| 492 | + if ($targetUser->getUID() === $loggedInUser->getUID()) { |
|
| 493 | + if ($this->groupManager->isAdmin($loggedInUser->getUID())) { |
|
| 494 | + if ($group->getGID() === 'admin') { |
|
| 495 | 495 | return new \OC\OCS\Result(null, 105, 'Cannot remove yourself from the admin group'); |
| 496 | 496 | } |
| 497 | 497 | } else { |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | $subAdminGroups[$key] = $group->getGID(); |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | - if(in_array($group->getGID(), $subAdminGroups, true)) { |
|
| 504 | + if (in_array($group->getGID(), $subAdminGroups, true)) { |
|
| 505 | 505 | return new \OC\OCS\Result(null, 105, 'Cannot remove yourself from this group as you are a SubAdmin'); |
| 506 | 506 | } |
| 507 | 507 | } |
@@ -523,15 +523,15 @@ discard block |
||
| 523 | 523 | $user = $this->userManager->get($parameters['userid']); |
| 524 | 524 | |
| 525 | 525 | // Check if the user exists |
| 526 | - if($user === null) { |
|
| 526 | + if ($user === null) { |
|
| 527 | 527 | return new \OC\OCS\Result(null, 101, 'User does not exist'); |
| 528 | 528 | } |
| 529 | 529 | // Check if group exists |
| 530 | - if($group === null) { |
|
| 530 | + if ($group === null) { |
|
| 531 | 531 | return new \OC\OCS\Result(null, 102, 'Group:'.$_POST['groupid'].' does not exist'); |
| 532 | 532 | } |
| 533 | 533 | // Check if trying to make subadmin of admin group |
| 534 | - if(strtolower($_POST['groupid']) === 'admin') { |
|
| 534 | + if (strtolower($_POST['groupid']) === 'admin') { |
|
| 535 | 535 | return new \OC\OCS\Result(null, 103, 'Cannot create subadmins for admin group'); |
| 536 | 536 | } |
| 537 | 537 | |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | return new \OC\OCS\Result(null, 100); |
| 543 | 543 | } |
| 544 | 544 | // Go |
| 545 | - if($subAdminManager->createSubAdmin($user, $group)) { |
|
| 545 | + if ($subAdminManager->createSubAdmin($user, $group)) { |
|
| 546 | 546 | return new \OC\OCS\Result(null, 100); |
| 547 | 547 | } else { |
| 548 | 548 | return new \OC\OCS\Result(null, 103, 'Unknown error occurred'); |
@@ -561,20 +561,20 @@ discard block |
||
| 561 | 561 | $subAdminManager = $this->groupManager->getSubAdmin(); |
| 562 | 562 | |
| 563 | 563 | // Check if the user exists |
| 564 | - if($user === null) { |
|
| 564 | + if ($user === null) { |
|
| 565 | 565 | return new \OC\OCS\Result(null, 101, 'User does not exist'); |
| 566 | 566 | } |
| 567 | 567 | // Check if the group exists |
| 568 | - if($group === null) { |
|
| 568 | + if ($group === null) { |
|
| 569 | 569 | return new \OC\OCS\Result(null, 101, 'Group does not exist'); |
| 570 | 570 | } |
| 571 | 571 | // Check if they are a subadmin of this said group |
| 572 | - if(!$subAdminManager->isSubAdminofGroup($user, $group)) { |
|
| 572 | + if (!$subAdminManager->isSubAdminofGroup($user, $group)) { |
|
| 573 | 573 | return new \OC\OCS\Result(null, 102, 'User is not a subadmin of this group'); |
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | // Go |
| 577 | - if($subAdminManager->deleteSubAdmin($user, $group)) { |
|
| 577 | + if ($subAdminManager->deleteSubAdmin($user, $group)) { |
|
| 578 | 578 | return new \OC\OCS\Result(null, 100); |
| 579 | 579 | } else { |
| 580 | 580 | return new \OC\OCS\Result(null, 103, 'Unknown error occurred'); |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | public function getUserSubAdminGroups($parameters) { |
| 591 | 591 | $user = $this->userManager->get($parameters['userid']); |
| 592 | 592 | // Check if the user exists |
| 593 | - if($user === null) { |
|
| 593 | + if ($user === null) { |
|
| 594 | 594 | return new \OC\OCS\Result(null, 101, 'User does not exist'); |
| 595 | 595 | } |
| 596 | 596 | |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | $groups[$key] = $group->getGID(); |
| 601 | 601 | } |
| 602 | 602 | |
| 603 | - if(!$groups) { |
|
| 603 | + if (!$groups) { |
|
| 604 | 604 | return new \OC\OCS\Result(null, 102, 'Unknown error occurred'); |
| 605 | 605 | } else { |
| 606 | 606 | return new \OC\OCS\Result($groups); |