|
70 | 70 | use OCP\Security\ISecureRandom; |
71 | 71 | use OCP\Security\Events\GenerateSecurePasswordEvent; |
72 | 72 | use OCP\EventDispatcher\IEventDispatcher; |
| 73 | +use OCP\User\Backend\ISetDisplayNameBackend; |
73 | 74 | use Psr\Log\LoggerInterface; |
74 | 75 |
|
75 | 76 | class UsersController extends AUserData { |
@@ -538,13 +539,38 @@ public function getCurrentUser(): DataResponse { |
538 | 539 | /** |
539 | 540 | * @NoAdminRequired |
540 | 541 | * @NoSubAdminRequired |
| 542 | + * |
| 543 | + * @return DataResponse |
| 544 | + * @throws OCSException |
541 | 545 | */ |
542 | | - public function getEditableFields(): DataResponse { |
| 546 | + public function getEditableFields(?string $userId = null): DataResponse { |
| 547 | + $currentLoggedInUser = $this->userSession->getUser(); |
| 548 | + if (!$currentLoggedInUser instanceof IUser) { |
| 549 | + throw new OCSException('', OCSController::RESPOND_NOT_FOUND); |
| 550 | + } |
| 551 | + |
543 | 552 | $permittedFields = []; |
544 | 553 |
|
| 554 | + if ($userId !== $currentLoggedInUser->getUID()) { |
| 555 | + $targetUser = $this->userManager->get($userId); |
| 556 | + if (!$targetUser instanceof IUser) { |
| 557 | + throw new OCSException('', OCSController::RESPOND_NOT_FOUND); |
| 558 | + } |
| 559 | + |
| 560 | + $subAdminManager = $this->groupManager->getSubAdmin(); |
| 561 | + if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
| 562 | + && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
| 563 | + throw new OCSException('', OCSController::RESPOND_NOT_FOUND); |
| 564 | + } |
| 565 | + } else { |
| 566 | + $targetUser = $currentLoggedInUser->getUID(); |
| 567 | + } |
| 568 | + |
545 | 569 | // Editing self (display, email) |
546 | 570 | if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
547 | | - $permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME; |
| 571 | + if ($targetUser->getBackend() instanceof ISetDisplayNameBackend) { |
| 572 | + $permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME; |
| 573 | + } |
548 | 574 | $permittedFields[] = IAccountManager::PROPERTY_EMAIL; |
549 | 575 | } |
550 | 576 |
|
@@ -581,8 +607,10 @@ public function editUser(string $userId, string $key, string $value): DataRespon |
581 | 607 | if ($targetUser->getUID() === $currentLoggedInUser->getUID()) { |
582 | 608 | // Editing self (display, email) |
583 | 609 | if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) { |
584 | | - $permittedFields[] = 'display'; |
585 | | - $permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME; |
| 610 | + if ($targetUser->getBackend() instanceof ISetDisplayNameBackend) { |
| 611 | + $permittedFields[] = 'display'; |
| 612 | + $permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME; |
| 613 | + } |
586 | 614 | $permittedFields[] = IAccountManager::PROPERTY_EMAIL; |
587 | 615 | } |
588 | 616 |
|
@@ -621,8 +649,10 @@ public function editUser(string $userId, string $key, string $value): DataRespon |
621 | 649 | if ($this->groupManager->isAdmin($currentLoggedInUser->getUID()) |
622 | 650 | || $subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) { |
623 | 651 | // They have permissions over the user |
624 | | - $permittedFields[] = 'display'; |
625 | | - $permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME; |
| 652 | + if ($targetUser->getBackend() instanceof ISetDisplayNameBackend) { |
| 653 | + $permittedFields[] = 'display'; |
| 654 | + $permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME; |
| 655 | + } |
626 | 656 | $permittedFields[] = IAccountManager::PROPERTY_EMAIL; |
627 | 657 | $permittedFields[] = 'password'; |
628 | 658 | $permittedFields[] = 'language'; |
|
0 commit comments