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 /lib | |
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 'lib')
-rw-r--r-- | lib/private/User/LazyUser.php | 8 | ||||
-rw-r--r-- | lib/private/User/User.php | 25 | ||||
-rw-r--r-- | lib/public/IUser.php | 17 |
3 files changed, 50 insertions, 0 deletions
diff --git a/lib/private/User/LazyUser.php b/lib/private/User/LazyUser.php index 5472cf6f2b4..396d3c252f1 100644 --- a/lib/private/User/LazyUser.php +++ b/lib/private/User/LazyUser.php @@ -159,4 +159,12 @@ class LazyUser implements IUser { public function setQuota($quota) { $this->getUser()->setQuota($quota); } + + public function getManagerUids(): array { + return $this->getUser()->getManagerUids(); + } + + public function setManagerUids(array $uids): void { + $this->getUser()->setManagerUids($uids); + } } diff --git a/lib/private/User/User.php b/lib/private/User/User.php index ff357a3badb..c68d4ee290a 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -59,8 +59,12 @@ use OCP\User\Backend\IGetHomeBackend; use OCP\UserInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\GenericEvent; +use function json_decode; +use function json_encode; class User implements IUser { + private const CONFIG_KEY_MANAGERS = 'manager'; + /** @var IAccountManager */ protected $accountManager; /** @var string */ @@ -532,6 +536,27 @@ class User implements IUser { \OC_Helper::clearStorageInfo('/' . $this->uid . '/files'); } + public function getManagerUids(): array { + $encodedUids = $this->config->getUserValue( + $this->uid, + 'settings', + self::CONFIG_KEY_MANAGERS, + '[]' + ); + return json_decode($encodedUids, false, 512, JSON_THROW_ON_ERROR); + } + + public function setManagerUids(array $uids): void { + $oldUids = $this->getManagerUids(); + $this->config->setUserValue( + $this->uid, + 'settings', + self::CONFIG_KEY_MANAGERS, + json_encode($uids, JSON_THROW_ON_ERROR) + ); + $this->triggerChange('managers', $uids, $oldUids); + } + /** * get the avatar image if it exists * diff --git a/lib/public/IUser.php b/lib/public/IUser.php index 3a7e6ab1f11..b326e6192c0 100644 --- a/lib/public/IUser.php +++ b/lib/public/IUser.php @@ -270,4 +270,21 @@ interface IUser { * @since 9.0.0 */ public function setQuota($quota); + + /** + * Get the user's manager UIDs + * + * @since 27.0.0 + * @return string[] + */ + public function getManagerUids(): array; + + /** + * Set the user's manager UIDs + * + * @param string[] $uids UIDs of all managers + * @return void + * @since 27.0.0 + */ + public function setManagerUids(array $uids): void; } |