From e83520617d19833e8b85424c7cb51f5773ec20d0 Mon Sep 17 00:00:00 2001 From: Marc Hefter Date: Fri, 21 Apr 2023 10:35:44 +0200 Subject: [PATCH 1/3] removed profile data from LDAP will get removed If attribute mapping is configured and no value present in LDAP, the according profile field is emptied. Removing an attribute e.g. phone from LDAP will cause the phone number being removed from profile. Signed-off-by: Marc Hefter --- apps/user_ldap/lib/User/User.php | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index f6a3bf7079218..20a7baa66dd21 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -249,9 +249,9 @@ public function processAttributes($ldapEntry) { $profileValues = array(); //User Profile Field - Phone number $attr = strtolower($this->connection->ldapAttributePhone); - if (isset($ldapEntry[$attr])) { + if (!empty($attr)) { // attribute configured $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_PHONE] - = $ldapEntry[$attr][0]; + = (isset($ldapEntry[$attr]) ? $ldapEntry[$attr][0] : ""); } //User Profile Field - website $attr = strtolower($this->connection->ldapAttributeWebsite); @@ -265,6 +265,8 @@ public function processAttributes($ldapEntry) { $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_WEBSITE] = $ldapEntry[$attr][0]; } + } elseif (!empty($attr)) { // configured, but not defined + $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_WEBSITE] = ""; } //User Profile Field - Address $attr = strtolower($this->connection->ldapAttributeAddress); @@ -277,36 +279,38 @@ public function processAttributes($ldapEntry) { $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_ADDRESS] = $ldapEntry[$attr][0]; } + } elseif (!empty($attr)) { // configured, but not defined + $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_ADDRESS] = ""; } //User Profile Field - Twitter $attr = strtolower($this->connection->ldapAttributeTwitter); - if (isset($ldapEntry[$attr])) { + if (!empty($attr)) { $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_TWITTER] - = $ldapEntry[$attr][0]; + = (isset($ldapEntry[$attr]) ? $ldapEntry[$attr][0] : ""); } //User Profile Field - fediverse $attr = strtolower($this->connection->ldapAttributeFediverse); - if (isset($ldapEntry[$attr])) { + if (!empty($attr)) { $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_FEDIVERSE] - = $ldapEntry[$attr][0]; + = (isset($ldapEntry[$attr]) ? $ldapEntry[$attr][0] : ""); } //User Profile Field - organisation $attr = strtolower($this->connection->ldapAttributeOrganisation); - if (isset($ldapEntry[$attr])) { + if (!empty($attr)) { $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_ORGANISATION] - = $ldapEntry[$attr][0]; + = (isset($ldapEntry[$attr]) ? $ldapEntry[$attr][0] : ""); } //User Profile Field - role $attr = strtolower($this->connection->ldapAttributeRole); - if (isset($ldapEntry[$attr])) { + if (!empty($attr)) { $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_ROLE] - = $ldapEntry[$attr][0]; + = (isset($ldapEntry[$attr]) ? $ldapEntry[$attr][0] : ""); } //User Profile Field - headline $attr = strtolower($this->connection->ldapAttributeHeadline); - if (isset($ldapEntry[$attr])) { + if (!empty($attr)) { $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_HEADLINE] - = $ldapEntry[$attr][0]; + = (isset($ldapEntry[$attr]) ? $ldapEntry[$attr][0] : ""); } //User Profile Field - biography $attr = strtolower($this->connection->ldapAttributeBiography); @@ -319,6 +323,8 @@ public function processAttributes($ldapEntry) { $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_BIOGRAPHY] = $ldapEntry[$attr][0]; } + } elseif (!empty($attr)) { // configured, but not defined + $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_BIOGRAPHY] = ""; } // check for changed data and cache just for TTL checking $checksum = hash('sha256', json_encode($profileValues)); From aa210365ec5e3d16b1275c1895d1a56780aeafaf Mon Sep 17 00:00:00 2001 From: Marc Hefter Date: Mon, 24 Apr 2023 10:14:17 +0200 Subject: [PATCH 2/3] Update apps/user_ldap/lib/User/User.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Marc Hefter --- apps/user_ldap/lib/User/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index 20a7baa66dd21..c79c2b76f4191 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -251,7 +251,7 @@ public function processAttributes($ldapEntry) { $attr = strtolower($this->connection->ldapAttributePhone); if (!empty($attr)) { // attribute configured $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_PHONE] - = (isset($ldapEntry[$attr]) ? $ldapEntry[$attr][0] : ""); + = $ldapEntry[$attr][0] ?? ""; } //User Profile Field - website $attr = strtolower($this->connection->ldapAttributeWebsite); From 621c6c3c56453360599190cbbf248a5e5ad23500 Mon Sep 17 00:00:00 2001 From: Marc Hefter Date: Mon, 24 Apr 2023 10:21:45 +0200 Subject: [PATCH 3/3] code styling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Marc Hefter --- apps/user_ldap/lib/User/User.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index c79c2b76f4191..f85e4206efffb 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -286,31 +286,31 @@ public function processAttributes($ldapEntry) { $attr = strtolower($this->connection->ldapAttributeTwitter); if (!empty($attr)) { $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_TWITTER] - = (isset($ldapEntry[$attr]) ? $ldapEntry[$attr][0] : ""); + = $ldapEntry[$attr][0] ?? ""; } //User Profile Field - fediverse $attr = strtolower($this->connection->ldapAttributeFediverse); if (!empty($attr)) { $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_FEDIVERSE] - = (isset($ldapEntry[$attr]) ? $ldapEntry[$attr][0] : ""); + = $ldapEntry[$attr][0] ?? ""; } //User Profile Field - organisation $attr = strtolower($this->connection->ldapAttributeOrganisation); if (!empty($attr)) { $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_ORGANISATION] - = (isset($ldapEntry[$attr]) ? $ldapEntry[$attr][0] : ""); + = $ldapEntry[$attr][0] ?? ""; } //User Profile Field - role $attr = strtolower($this->connection->ldapAttributeRole); if (!empty($attr)) { $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_ROLE] - = (isset($ldapEntry[$attr]) ? $ldapEntry[$attr][0] : ""); + = $ldapEntry[$attr][0] ?? ""; } //User Profile Field - headline $attr = strtolower($this->connection->ldapAttributeHeadline); if (!empty($attr)) { $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_HEADLINE] - = (isset($ldapEntry[$attr]) ? $ldapEntry[$attr][0] : ""); + = $ldapEntry[$attr][0] ?? ""; } //User Profile Field - biography $attr = strtolower($this->connection->ldapAttributeBiography);