From eee0275dc5b3cfec8f1470bf9efca357e7d3ca68 Mon Sep 17 00:00:00 2001 From: Marc Hefter Date: Tue, 17 May 2022 18:05:37 +0200 Subject: added user profile scope setting Signed-off-by: Marc Hefter Signed-off-by: Marc Hefter --- apps/user_ldap/js/wizard/wizardTabAdvanced.js | 13 +++++++++++++ apps/user_ldap/lib/Configuration.php | 3 +++ apps/user_ldap/lib/Connection.php | 1 + apps/user_ldap/lib/User/User.php | 25 +++++++++++++++---------- apps/user_ldap/templates/settings.php | 1 + 5 files changed, 33 insertions(+), 10 deletions(-) (limited to 'apps') diff --git a/apps/user_ldap/js/wizard/wizardTabAdvanced.js b/apps/user_ldap/js/wizard/wizardTabAdvanced.js index d2c3b6d125d..031f2bf2a9d 100644 --- a/apps/user_ldap/js/wizard/wizardTabAdvanced.js +++ b/apps/user_ldap/js/wizard/wizardTabAdvanced.js @@ -159,6 +159,10 @@ OCA = OCA || {}; $element: $('#ldap_attr_biography'), setMethod: 'setBiographyAttribute' }, + ldap_profile_scope: { + $element: $('#ldap_profile_scope'), + setMethod: 'setProfileScope' + }, }; this.setManagedItems(items); }, @@ -472,6 +476,15 @@ OCA = OCA || {}; this.setElementValue(this.managedItems.ldap_attr_biography.$element, attribute); }, + /** + * sets the visibility scope for the Nextcloud user profile properties + * + * @param {string} scope + */ + setProfileScope: function(scope) { + this.setElementValue(this.managedItems.ldap_profile_scope.$element, scope); + }, + /** * deals with the result of the Test Connection test * diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php index e29bff4b8c5..2b42dd9992b 100644 --- a/apps/user_ldap/lib/Configuration.php +++ b/apps/user_ldap/lib/Configuration.php @@ -132,6 +132,7 @@ class Configuration { 'ldapAttributeRole' => null, 'ldapAttributeHeadline' => null, 'ldapAttributeBiography' => null, + 'ldapProfileScope' => null, ]; public function __construct(string $configPrefix, bool $autoRead = true) { @@ -486,6 +487,7 @@ class Configuration { 'ldap_attr_role' => '', 'ldap_attr_headline' => '', 'ldap_attr_biography' => '', + 'ldap_profile_scope' => '', ]; } @@ -560,6 +562,7 @@ class Configuration { 'ldap_attr_role' => 'ldapAttributeRole', 'ldap_attr_headline' => 'ldapAttributeHeadline', 'ldap_attr_biography' => 'ldapAttributeBiography', + 'ldap_profile_scope' => 'ldapProfileScope', ]; return $array; } diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php index f899ee381c8..11aaaec13dd 100644 --- a/apps/user_ldap/lib/Connection.php +++ b/apps/user_ldap/lib/Connection.php @@ -81,6 +81,7 @@ use Psr\Log\LoggerInterface; * @property string ldapAttributeRole * @property string ldapAttributeHeadline * @property string ldapAttributeBiography + * @property string ldapProfileScope */ class Connection extends LDAPUtility { /** diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index 043f3b2d273..1f044c6ddd6 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -248,52 +248,57 @@ class User { } unset($attr); + //User profile visibility + $profileScope = $this->connection->ldapProfileScope; + if (is_null($profileScope) || '' === $profileScope || 'unset' === $profileScope) { + $profileScope = null; + } //User Profile Field - Phone number $attr = strtolower($this->connection->ldapAttributePhone); if (isset($ldapEntry[$attr])) { - $this->updateProfile(self::USER_PREFKEY_PHONE, $ldapEntry[$attr][0]); + $this->updateProfile(self::USER_PREFKEY_PHONE, $ldapEntry[$attr][0], $profileScope); } unset($attr); //User Profile Field - website $attr = strtolower($this->connection->ldapAttributeWebsite); if (isset($ldapEntry[$attr])) { - $this->updateProfile(self::USER_PREFKEY_WEBSITE, $ldapEntry[$attr][0]); + $this->updateProfile(self::USER_PREFKEY_WEBSITE, $ldapEntry[$attr][0], $profileScope); } unset($attr); //User Profile Field - Address $attr = strtolower($this->connection->ldapAttributeAddress); if (isset($ldapEntry[$attr])) { - $this->updateProfile(self::USER_PREFKEY_ADDRESS, $ldapEntry[$attr][0]); + $this->updateProfile(self::USER_PREFKEY_ADDRESS, $ldapEntry[$attr][0], $profileScope); } unset($attr); //User Profile Field - Twitter $attr = strtolower($this->connection->ldapAttributeTwitter); if (isset($ldapEntry[$attr])) { - $this->updateProfile(self::USER_PREFKEY_TWITTER, $ldapEntry[$attr][0]); + $this->updateProfile(self::USER_PREFKEY_TWITTER, $ldapEntry[$attr][0], $profileScope); } unset($attr); //User Profile Field - organisation $attr = strtolower($this->connection->ldapAttributeOrganisation); if (isset($ldapEntry[$attr])) { - $this->updateProfile(self::USER_PREFKEY_ORGANISATION, $ldapEntry[$attr][0]); + $this->updateProfile(self::USER_PREFKEY_ORGANISATION, $ldapEntry[$attr][0], $profileScope); } unset($attr); //User Profile Field - role $attr = strtolower($this->connection->ldapAttributeRole); if (isset($ldapEntry[$attr])) { - $this->updateProfile(self::USER_PREFKEY_ROLE, $ldapEntry[$attr][0]); + $this->updateProfile(self::USER_PREFKEY_ROLE, $ldapEntry[$attr][0], $profileScope); } unset($attr); //User Profile Field - headline $attr = strtolower($this->connection->ldapAttributeHeadline); if (isset($ldapEntry[$attr])) { - $this->updateProfile(self::USER_PREFKEY_HEADLINE, $ldapEntry[$attr][0]); + $this->updateProfile(self::USER_PREFKEY_HEADLINE, $ldapEntry[$attr][0], $profileScope); } unset($attr); //User Profile Field - biography $attr = strtolower($this->connection->ldapAttributeBiography); if (isset($ldapEntry[$attr])) { - $this->updateProfile(self::USER_PREFKEY_BIOGRAPHY, $ldapEntry[$attr][0]); + $this->updateProfile(self::USER_PREFKEY_BIOGRAPHY, $ldapEntry[$attr][0], $profileScope); } unset($attr); @@ -583,7 +588,7 @@ class User { * @param string $valueFromLDAP if known, to save an LDAP read request * @return null */ - private function updateProfile(string $property, $valueFromLDAP) { + private function updateProfile(string $property, $valueFromLDAP, $scope=null) { // check for valid property and set corresponding profile property $profileProperty = 'INVALID'; if (self::USER_PREFKEY_PHONE == $property) { @@ -622,7 +627,7 @@ class User { if (!is_null($user)) { $currentValue = (string)$user->getProfilePropertyValue($profileProperty); if ($currentValue !== $value) { - $user->setProfilePropertyValue($profileProperty,$value); + $user->setProfileProperty($profileProperty,$value,$scope,null); } // setScope(IAccountManager::SCOPE_FEDERATED); // setVerified(IAccountManager::VERIFIED); diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php index b779cc1f6e5..aee48f85ed0 100644 --- a/apps/user_ldap/templates/settings.php +++ b/apps/user_ldap/templates/settings.php @@ -130,6 +130,7 @@ style('user_ldap', 'settings');

+

-- cgit v1.2.3