diff options
author | Marc Hefter <marchefter@march42.net> | 2022-05-12 07:46:22 +0200 |
---|---|---|
committer | Marc Hefter <marchefter@gmail.com> | 2023-04-06 08:20:20 +0200 |
commit | 7fa3c674de904b140575112f471c5753aa03a89c (patch) | |
tree | d4e6289d93d15069bb78b74ae814c3af5a9094c9 /apps/user_ldap/lib/User | |
parent | 404d26aa4a950e246f11ce421c48faef764fce31 (diff) | |
download | nextcloud-server-7fa3c674de904b140575112f471c5753aa03a89c.tar.gz nextcloud-server-7fa3c674de904b140575112f471c5753aa03a89c.zip |
feature addition: [user_ldap] update user profile from LDAP; WIP; fixing some uggly copy-and-paste errors; testing functionality; preparing and editing the documentation
Signed-off-by: Marc Hefter <marchefter@march42.net>
Signed-off-by: Marc Hefter <marchefter@gmail.com>
Diffstat (limited to 'apps/user_ldap/lib/User')
-rw-r--r-- | apps/user_ldap/lib/User/Manager.php | 1 | ||||
-rw-r--r-- | apps/user_ldap/lib/User/User.php | 39 |
2 files changed, 36 insertions, 4 deletions
diff --git a/apps/user_ldap/lib/User/Manager.php b/apps/user_ldap/lib/User/Manager.php index 8e0ad9c5df9..8942563a0d5 100644 --- a/apps/user_ldap/lib/User/Manager.php +++ b/apps/user_ldap/lib/User/Manager.php @@ -156,6 +156,7 @@ class Manager { $this->access->getConnection()->ldapAttributePhone, $this->access->getConnection()->ldapAttributeWebsite, $this->access->getConnection()->ldapAttributeAddress, + $this->access->getConnection()->ldapAttributeTwitter, $this->access->getConnection()->ldapAttributeOrganisation, $this->access->getConnection()->ldapAttributeRole, $this->access->getConnection()->ldapAttributeHeadline, diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index 81ced78dab9..e9437d61ab3 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -116,6 +116,7 @@ class User { public const USER_PREFKEY_PHONE = 'profile_phone'; public const USER_PREFKEY_WEBSITE = 'profile_website'; public const USER_PREFKEY_ADDRESS = 'profile_address'; + public const USER_PREFKEY_TWITTER = 'profile_twitter'; public const USER_PREFKEY_ORGANISATION = 'profile_organisation'; public const USER_PREFKEY_ROLE = 'profile_role'; public const USER_PREFKEY_HEADLINE = 'profile_headline'; @@ -262,26 +263,32 @@ class User { $this->updateProfile(self::USER_PREFKEY_ADDRESS, $ldapEntry[$attr][0]); } unset($attr); + //User Profile Field - Twitter + $attr = strtolower($this->connection->ldapAttributeTwitter); + if (isset($ldapEntry[$attr])) { + $this->updateProfile(self::USER_PREFKEY_TWITTER, $ldapEntry[$attr][0]); + } + unset($attr); //User Profile Field - organisation - $attr = strtolower($this->connection->ldapAttributeAddress); + $attr = strtolower($this->connection->ldapAttributeOrganisation); if (isset($ldapEntry[$attr])) { $this->updateProfile(self::USER_PREFKEY_ORGANISATION, $ldapEntry[$attr][0]); } unset($attr); //User Profile Field - role - $attr = strtolower($this->connection->ldapAttributeAddress); + $attr = strtolower($this->connection->ldapAttributeRole); if (isset($ldapEntry[$attr])) { $this->updateProfile(self::USER_PREFKEY_ROLE, $ldapEntry[$attr][0]); } unset($attr); //User Profile Field - headline - $attr = strtolower($this->connection->ldapAttributeAddress); + $attr = strtolower($this->connection->ldapAttributeHeadline); if (isset($ldapEntry[$attr])) { $this->updateProfile(self::USER_PREFKEY_HEADLINE, $ldapEntry[$attr][0]); } unset($attr); //User Profile Field - biography - $attr = strtolower($this->connection->ldapAttributeAddress); + $attr = strtolower($this->connection->ldapAttributeBiography); if (isset($ldapEntry[$attr])) { $this->updateProfile(self::USER_PREFKEY_BIOGRAPHY, $ldapEntry[$attr][0]); } @@ -590,6 +597,30 @@ class User { * @return null */ public function updateProfile(string $property, $valueFromLDAP = null) { + // check for valid property and set corresponding profile property + $profileProperty = 'INVALID'; + if (self::USER_PREFKEY_PHONE == $property) { + $profileProperty = \OCP\Accounts\IAccountManager::PROPERTY_PHONE; + } elseif (self::USER_PREFKEY_WEBSITE == $property) { + $profileProperty = \OCP\Accounts\IAccountManager::PROPERTY_WEBSITE; + } elseif (self::USER_PREFKEY_ADDRESS == $property) { + $profileProperty = \OCP\Accounts\IAccountManager::PROPERTY_ADDRESS; + } elseif (self::USER_PREFKEY_TWITTER == $property) { + $profileProperty = \OCP\Accounts\IAccountManager::PROPERTY_TWITTER; + } elseif (self::USER_PREFKEY_ORGANISATION == $property) { + $profileProperty = \OCP\Accounts\IAccountManager::PROPERTY_ORGANISATION; + } elseif (self::USER_PREFKEY_ROLE == $property) { + $profileProperty = \OCP\Accounts\IAccountManager::PROPERTY_ROLE; + } elseif (self::USER_PREFKEY_HEADLINE == $property) { + $profileProperty = \OCP\Accounts\IAccountManager::PROPERTY_HEADLINE; + } elseif (self::USER_PREFKEY_BIOGRAPHY == $property) { + $profileProperty = \OCP\Accounts\IAccountManager::PROPERTY_BIOGRAPHY; + } else { + // TODO: 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; } |