summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap
diff options
context:
space:
mode:
authorMarc Hefter <marchefter@march42.net>2022-05-12 07:46:22 +0200
committerMarc Hefter <marchefter@gmail.com>2023-04-06 08:20:20 +0200
commit7fa3c674de904b140575112f471c5753aa03a89c (patch)
treed4e6289d93d15069bb78b74ae814c3af5a9094c9 /apps/user_ldap
parent404d26aa4a950e246f11ce421c48faef764fce31 (diff)
downloadnextcloud-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')
-rw-r--r--apps/user_ldap/js/wizard/wizardTabAdvanced.js13
-rw-r--r--apps/user_ldap/lib/Configuration.php3
-rw-r--r--apps/user_ldap/lib/Connection.php1
-rw-r--r--apps/user_ldap/lib/User/Manager.php1
-rw-r--r--apps/user_ldap/lib/User/User.php39
-rw-r--r--apps/user_ldap/templates/settings.php11
6 files changed, 64 insertions, 4 deletions
diff --git a/apps/user_ldap/js/wizard/wizardTabAdvanced.js b/apps/user_ldap/js/wizard/wizardTabAdvanced.js
index 26bcd15810e..d2c3b6d125d 100644
--- a/apps/user_ldap/js/wizard/wizardTabAdvanced.js
+++ b/apps/user_ldap/js/wizard/wizardTabAdvanced.js
@@ -139,6 +139,10 @@ OCA = OCA || {};
$element: $('#ldap_attr_address'),
setMethod: 'setAddressAttribute'
},
+ ldap_attr_twitter: {
+ $element: $('#ldap_attr_twitter'),
+ setMethod: 'setTwitterAttribute'
+ },
ldap_attr_organisation: {
$element: $('#ldap_attr_organisation'),
setMethod: 'setOrganisationAttribute'
@@ -424,6 +428,15 @@ OCA = OCA || {};
},
/**
+ * sets the attribute for the Nextcloud user profile twitter
+ *
+ * @param {string} attribute
+ */
+ setTwitterAttribute: function(attribute) {
+ this.setElementValue(this.managedItems.ldap_attr_twitter.$element, attribute);
+ },
+
+ /**
* sets the attribute for the Nextcloud user profile organisation
*
* @param {string} attribute
diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php
index 91780155251..e29bff4b8c5 100644
--- a/apps/user_ldap/lib/Configuration.php
+++ b/apps/user_ldap/lib/Configuration.php
@@ -127,6 +127,7 @@ class Configuration {
'ldapAttributePhone' => null,
'ldapAttributeWebsite' => null,
'ldapAttributeAddress' => null,
+ 'ldapAttributeTwitter' => null,
'ldapAttributeOrganisation' => null,
'ldapAttributeRole' => null,
'ldapAttributeHeadline' => null,
@@ -480,6 +481,7 @@ class Configuration {
'ldap_attr_phone' => '',
'ldap_attr_website' => '',
'ldap_attr_address' => '',
+ 'ldap_attr_twitter' => '',
'ldap_attr_organisation' => '',
'ldap_attr_role' => '',
'ldap_attr_headline' => '',
@@ -553,6 +555,7 @@ class Configuration {
'ldap_attr_phone' => 'ldapAttributePhone',
'ldap_attr_website' => 'ldapAttributeWebsite',
'ldap_attr_address' => 'ldapAttributeAddress',
+ 'ldap_attr_twitter' => 'ldapAttributeTwitter',
'ldap_attr_organisation' => 'ldapAttributeOrganisation',
'ldap_attr_role' => 'ldapAttributeRole',
'ldap_attr_headline' => 'ldapAttributeHeadline',
diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php
index 85c8b5ceda3..f899ee381c8 100644
--- a/apps/user_ldap/lib/Connection.php
+++ b/apps/user_ldap/lib/Connection.php
@@ -76,6 +76,7 @@ use Psr\Log\LoggerInterface;
* @property string ldapAttributePhone
* @property string ldapAttributeWebsite
* @property string ldapAttributeAddress
+ * @property string ldapAttributeTwitter
* @property string ldapAttributeOrganisation
* @property string ldapAttributeRole
* @property string ldapAttributeHeadline
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;
}
diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php
index a28ef55a306..b779cc1f6e5 100644
--- a/apps/user_ldap/templates/settings.php
+++ b/apps/user_ldap/templates/settings.php
@@ -120,6 +120,17 @@ style('user_ldap', 'settings');
<p><label for="home_folder_naming_rule"><?php p($l->t('User Home Folder Naming Rule'));?></label><input type="text" id="home_folder_naming_rule" name="home_folder_naming_rule" aria-describedby="home_folder_naming_rule_instructions" title="<?php p($l->t('Leave empty for username (default). Otherwise, specify an LDAP/AD attribute.'));?>" data-default="<?php p($_['home_folder_naming_rule_default']); ?>" /><p class="hidden-visually" id="home_folder_naming_rule_instructions"><?php p($l->t('Leave empty for username (default). Otherwise, specify an LDAP/AD attribute.'));?></p></p>
<p><label for="ldap_ext_storage_home_attribute"> <?php p($l->t('"$home" Placeholder Field')); ?></label><input type="text" id="ldap_ext_storage_home_attribute" name="ldap_ext_storage_home_attribute" aria-describedby="ldap_ext_storage_home_attribute_instructions" title="<?php p($l->t('$home in an external storage configuration will be replaced with the value of the specified attribute')); ?>" data-default="<?php p($_['ldap_ext_storage_home_attribute_default']); ?>"><p class="hidden-visually" id="ldap_ext_storage_home_attribute_instructions"><?php p($l->t('$home in an external storage configuration will be replaced with the value of the specified attribute')); ?></p></p>
</div>
+ <h3><?php p($l->t('User Profile Attributes'));?></h3>
+ <div>
+ <p><label for="ldap_attr_phone"> <?php p($l->t('Phone Field')); ?></label><input type="text" id="ldap_attr_phone" name="ldap_attr_phone" title="<?php p($l->t('User profile Phone will be set from the specified attribute')); ?>" data-default="<?php p($_['ldap_attr_phone_default']); ?>"></p>
+ <p><label for="ldap_attr_website"> <?php p($l->t('Website Field')); ?></label><input type="text" id="ldap_attr_website" name="ldap_attr_website" title="<?php p($l->t('User profile Website will be set from the specified attribute')); ?>" data-default="<?php p($_['ldap_attr_website_default']); ?>"></p>
+ <p><label for="ldap_attr_address"> <?php p($l->t('Address Field')); ?></label><input type="text" id="ldap_attr_address" name="ldap_attr_address" title="<?php p($l->t('User profile Address will be set from the specified attribute')); ?>" data-default="<?php p($_['ldap_attr_address_default']); ?>"></p>
+ <p><label for="ldap_attr_twitter"> <?php p($l->t('Twitter Field')); ?></label><input type="text" id="ldap_attr_twitter" name="ldap_attr_twitter" title="<?php p($l->t('User profile Twitter will be set from the specified attribute')); ?>" data-default="<?php p($_['ldap_attr_twitter_default']); ?>"></p>
+ <p><label for="ldap_attr_organisation"> <?php p($l->t('Organisation Field')); ?></label><input type="text" id="ldap_attr_organisation" name="ldap_attr_organisation" title="<?php p($l->t('User profile Organisation will be set from the specified attribute')); ?>" data-default="<?php p($_['ldap_attr_organisation_default']); ?>"></p>
+ <p><label for="ldap_attr_role"> <?php p($l->t('Role Field')); ?></label><input type="text" id="ldap_attr_role" name="ldap_attr_role" title="<?php p($l->t('User profile Role will be set from the specified attribute')); ?>" data-default="<?php p($_['ldap_attr_role_default']); ?>"></p>
+ <p><label for="ldap_attr_headline"> <?php p($l->t('Headline Field')); ?></label><input type="text" id="ldap_attr_headline" name="ldap_attr_headline" title="<?php p($l->t('User profile Headline will be set from the specified attribute')); ?>" data-default="<?php p($_['ldap_attr_headline_default']); ?>"></p>
+ <p><label for="ldap_attr_biography"> <?php p($l->t('Biography Field')); ?></label><input type="text" id="ldap_attr_biography" name="ldap_attr_biography" title="<?php p($l->t('User profile Biography will be set from the specified attribute')); ?>" data-default="<?php p($_['ldap_attr_biography_default']); ?>"></p>
+ </div>
</div>
<?php print_unescaped($_['settingControls']); ?>
</fieldset>