@@ -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); |