diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2023-05-02 08:59:46 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2023-05-12 13:56:48 +0200 |
commit | 1381c4c157f3174917c994038ab74074a42a2aa8 (patch) | |
tree | fe70c5181a99330f4f3292ca217b386a2c6ff354 /apps/provisioning_api/lib/Controller | |
parent | 1399c88ee178d9fd60f3e9356f1d8c498c6c97e1 (diff) | |
download | nextcloud-server-1381c4c157f3174917c994038ab74074a42a2aa8.tar.gz nextcloud-server-1381c4c157f3174917c994038ab74074a42a2aa8.zip |
feat(users): Store and load a user's manager
Co-Authored-By: hamza221 <hamzamahjoubi221@gmail.com>
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/provisioning_api/lib/Controller')
-rw-r--r-- | apps/provisioning_api/lib/Controller/AUserData.php | 3 | ||||
-rw-r--r-- | apps/provisioning_api/lib/Controller/UsersController.php | 20 |
2 files changed, 21 insertions, 2 deletions
diff --git a/apps/provisioning_api/lib/Controller/AUserData.php b/apps/provisioning_api/lib/Controller/AUserData.php index e7496c6c5ed..128fda588e2 100644 --- a/apps/provisioning_api/lib/Controller/AUserData.php +++ b/apps/provisioning_api/lib/Controller/AUserData.php @@ -60,6 +60,7 @@ abstract class AUserData extends OCSController { public const USER_FIELD_LOCALE = 'locale'; public const USER_FIELD_PASSWORD = 'password'; public const USER_FIELD_QUOTA = 'quota'; + public const USER_FIELD_MANAGER = 'manager'; public const USER_FIELD_NOTIFICATION_EMAIL = 'notify_email'; /** @var IUserManager */ @@ -151,6 +152,8 @@ abstract class AUserData extends OCSController { $data['backend'] = $targetUserObject->getBackendClassName(); $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID()); $data[self::USER_FIELD_QUOTA] = $this->fillStorageInfo($targetUserObject->getUID()); + $managerUids = $targetUserObject->getManagerUids(); + $data[self::USER_FIELD_MANAGER] = empty($managerUids) ? '' : $managerUids[0]; try { if ($includeScopes) { diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index b005acc4d7f..7dfdea991e5 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -338,7 +338,8 @@ class UsersController extends AUserData { array $groups = [], array $subadmin = [], string $quota = '', - string $language = '' + string $language = '', + ?string $manager = null, ): DataResponse { $user = $this->userSession->getUser(); $isAdmin = $this->groupManager->isAdmin($user->getUID()); @@ -447,6 +448,15 @@ class UsersController extends AUserData { $this->editUser($userid, self::USER_FIELD_LANGUAGE, $language); } + /** + * null -> nothing sent + * '' -> unset manager + * else -> set manager + */ + if ($manager !== null) { + $this->editUser($userid, self::USER_FIELD_MANAGER, $manager); + } + // Send new user mail only if a mail is set if ($email !== '') { $newUser->setEMailAddress($email); @@ -800,9 +810,11 @@ class UsersController extends AUserData { $permittedFields[] = IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX; - // If admin they can edit their own quota + // If admin they can edit their own quota and manager if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) { $permittedFields[] = self::USER_FIELD_QUOTA; + $permittedFields[] = self::USER_FIELD_MANAGER; + } } else { // Check if admin / subadmin @@ -836,6 +848,7 @@ class UsersController extends AUserData { $permittedFields[] = IAccountManager::PROPERTY_PROFILE_ENABLED; $permittedFields[] = self::USER_FIELD_QUOTA; $permittedFields[] = self::USER_FIELD_NOTIFICATION_EMAIL; + $permittedFields[] = self::USER_FIELD_MANAGER; } else { // No rights throw new OCSException('', OCSController::RESPOND_NOT_FOUND); @@ -885,6 +898,9 @@ class UsersController extends AUserData { } $targetUser->setQuota($quota); break; + case self::USER_FIELD_MANAGER: + $targetUser->setManagerUids([$value]); + break; case self::USER_FIELD_PASSWORD: try { if (strlen($value) > IUserManager::MAX_PASSWORD_LENGTH) { |