diff options
author | Marc Hefter <marchefter@march42.net> | 2022-05-17 12:49:38 +0200 |
---|---|---|
committer | Marc Hefter <marchefter@gmail.com> | 2023-04-06 08:20:21 +0200 |
commit | 2315c177261a03a2047f9ba3d11dd96da4fef840 (patch) | |
tree | f53852d74d9232945fc38cb9d191a6f9db0f2171 /apps | |
parent | 7fa3c674de904b140575112f471c5753aa03a89c (diff) | |
download | nextcloud-server-2315c177261a03a2047f9ba3d11dd96da4fef840.tar.gz nextcloud-server-2315c177261a03a2047f9ba3d11dd96da4fef840.zip |
feature addition: [user_ldap] update user profile from LDAP
Signed-off-by: Marc Hefter <marchefter@march42.net>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/user_ldap/lib/User/User.php | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index e9437d61ab3..043f3b2d273 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -36,9 +36,12 @@ use OCA\User_LDAP\Access; use OCA\User_LDAP\Connection; use OCA\User_LDAP\Exceptions\AttributeNotSet; use OCA\User_LDAP\FilesystemHelper; +use OC\Accounts\AccountManager; use OCP\Accounts\IAccountManager; +use OCP\Accounts\PropertyDoesNotExistException; use OCP\IAvatarManager; use OCP\IConfig; +use OCP\IDBConnection; use OCP\ILogger; use OCP\Image; use OCP\IUser; @@ -575,28 +578,12 @@ class User { return $quotaValue === 'none' || $quotaValue === 'default' || \OC_Helper::computerFileSize($quotaValue) !== false; } -/* user profile settings and LDAP attributes - * *** - * interface IAccountManager - * public const PROPERTY_PHONE = 'phone'; - * public const PROPERTY_EMAIL = 'email'; - * public const PROPERTY_WEBSITE = 'website'; - * public const PROPERTY_ADDRESS = 'address'; - * public const PROPERTY_TWITTER = 'twitter'; - * public const PROPERTY_ORGANISATION = 'organisation'; - * public const PROPERTY_ROLE = 'role'; - * public const PROPERTY_HEADLINE = 'headline'; - * public const PROPERTY_BIOGRAPHY = 'biography'; - * public const PROPERTY_PROFILE_ENABLED = 'profile_enabled'; - * public function getAccount(IUser $user): IAccount; - * public function updateAccount(IAccount $account): void; - */ /** * fetches values from LDAP and stores it as Nextcloud user value * @param string $valueFromLDAP if known, to save an LDAP read request * @return null */ - public function updateProfile(string $property, $valueFromLDAP = null) { + private function updateProfile(string $property, $valueFromLDAP) { // check for valid property and set corresponding profile property $profileProperty = 'INVALID'; if (self::USER_PREFKEY_PHONE == $property) { @@ -616,10 +603,9 @@ class User { } elseif (self::USER_PREFKEY_BIOGRAPHY == $property) { $profileProperty = \OCP\Accounts\IAccountManager::PROPERTY_BIOGRAPHY; } else { - // TODO: throw exception for invalid property specified + // FIXME: throw exception for invalid property specified return; } - $this->logger->info('user profile data from LDAP '.$this->dn.' ('.$profileProperty.')', ['app' => 'user_ldap']); // check if this property was refreshed before if ($this->wasRefreshed($property)) { return; @@ -628,12 +614,28 @@ class User { //$propertyValue = (string)$valueFromLDAP; $propertyValue = [$valueFromLDAP]; } + $this->logger->debug('user profile data ('.$profileProperty.') from LDAP '.$this->dn.' ='.((string)$valueFromLDAP), ['app' => 'user_ldap']); if ($propertyValue && isset($propertyValue[0])) { $value = $propertyValue[0]; + try { + $user = $this->userManager->get($this->uid); + if (!is_null($user)) { + $currentValue = (string)$user->getProfilePropertyValue($profileProperty); + if ($currentValue !== $value) { + $user->setProfilePropertyValue($profileProperty,$value); + } + // setScope(IAccountManager::SCOPE_FEDERATED); + // setVerified(IAccountManager::VERIFIED); + } + } catch (PropertyDoesNotExistException $e) { + $this->logger->error('property does not exist: '.$profileProperty.' for user '.$userName.'', ['app' => 'user_ldap']); + return; + } + $this->logger->debug('property updated: '.$profileProperty.'='.$propertyValue.' for user '.$userName.'', ['app' => 'user_ldap']); $this->config->setUserValue($this->getUsername(), 'user_ldap', $property, $value); - // TODO: update user profile data; call \OCP\Accounts\IAccount::setProperty return $value; } else { + // FIXME: I decided, to leave profile untouched, if attribute gets removed from LDAP $this->config->deleteUserValue($this->getUsername(), 'user_ldap', $property); return ''; } |