mirror of
https://github.com/nextcloud/server.git
synced 2026-06-15 19:49:38 -04:00
feature addition: [user_ldap] update user profile from LDAP; WIP work-in-progress; TODO update profile
Signed-off-by: Marc Hefter <marchefter@march42.net>
This commit is contained in:
parent
e63a6f5cdb
commit
404d26aa4a
5 changed files with 226 additions and 0 deletions
|
|
@ -125,6 +125,36 @@ OCA = OCA || {};
|
|||
$element: $('#ldap_ext_storage_home_attribute'),
|
||||
setMethod: 'setExternalStorageHomeAttribute'
|
||||
},
|
||||
|
||||
//User Profile Attributes
|
||||
ldap_attr_phone: {
|
||||
$element: $('#ldap_attr_phone'),
|
||||
setMethod: 'setPhoneAttribute'
|
||||
},
|
||||
ldap_attr_website: {
|
||||
$element: $('#ldap_attr_website'),
|
||||
setMethod: 'setWebsiteAttribute'
|
||||
},
|
||||
ldap_attr_address: {
|
||||
$element: $('#ldap_attr_address'),
|
||||
setMethod: 'setAddressAttribute'
|
||||
},
|
||||
ldap_attr_organisation: {
|
||||
$element: $('#ldap_attr_organisation'),
|
||||
setMethod: 'setOrganisationAttribute'
|
||||
},
|
||||
ldap_attr_role: {
|
||||
$element: $('#ldap_attr_role'),
|
||||
setMethod: 'setRoleAttribute'
|
||||
},
|
||||
ldap_attr_headline: {
|
||||
$element: $('#ldap_attr_headline'),
|
||||
setMethod: 'setHeadlineAttribute'
|
||||
},
|
||||
ldap_attr_biography: {
|
||||
$element: $('#ldap_attr_biography'),
|
||||
setMethod: 'setBiographyAttribute'
|
||||
},
|
||||
};
|
||||
this.setManagedItems(items);
|
||||
},
|
||||
|
|
@ -366,6 +396,69 @@ OCA = OCA || {};
|
|||
this.setElementValue(this.managedItems.home_folder_naming_rule.$element, attribute);
|
||||
},
|
||||
|
||||
/**
|
||||
* sets the attribute for the Nextcloud user profile phone Number
|
||||
*
|
||||
* @param {string} attribute
|
||||
*/
|
||||
setPhoneAttribute: function(attribute) {
|
||||
this.setElementValue(this.managedItems.ldap_attr_phone.$element, attribute);
|
||||
},
|
||||
|
||||
/**
|
||||
* sets the attribute for the Nextcloud user profile website
|
||||
*
|
||||
* @param {string} attribute
|
||||
*/
|
||||
setWebsiteAttribute: function(attribute) {
|
||||
this.setElementValue(this.managedItems.ldap_attr_website.$element, attribute);
|
||||
},
|
||||
|
||||
/**
|
||||
* sets the attribute for the Nextcloud user profile postal address
|
||||
*
|
||||
* @param {string} attribute
|
||||
*/
|
||||
setAddressAttribute: function(attribute) {
|
||||
this.setElementValue(this.managedItems.ldap_attr_address.$element, attribute);
|
||||
},
|
||||
|
||||
/**
|
||||
* sets the attribute for the Nextcloud user profile organisation
|
||||
*
|
||||
* @param {string} attribute
|
||||
*/
|
||||
setOrganisationAttribute: function(attribute) {
|
||||
this.setElementValue(this.managedItems.ldap_attr_organisation.$element, attribute);
|
||||
},
|
||||
|
||||
/**
|
||||
* sets the attribute for the Nextcloud user profile role
|
||||
*
|
||||
* @param {string} attribute
|
||||
*/
|
||||
setRoleAttribute: function(attribute) {
|
||||
this.setElementValue(this.managedItems.ldap_attr_role.$element, attribute);
|
||||
},
|
||||
|
||||
/**
|
||||
* sets the attribute for the Nextcloud user profile headline
|
||||
*
|
||||
* @param {string} attribute
|
||||
*/
|
||||
setHeadlineAttribute: function(attribute) {
|
||||
this.setElementValue(this.managedItems.ldap_attr_headline.$element, attribute);
|
||||
},
|
||||
|
||||
/**
|
||||
* sets the attribute for the Nextcloud user profile biography
|
||||
*
|
||||
* @param {string} attribute
|
||||
*/
|
||||
setBiographyAttribute: function(attribute) {
|
||||
this.setElementValue(this.managedItems.ldap_attr_biography.$element, attribute);
|
||||
},
|
||||
|
||||
/**
|
||||
* deals with the result of the Test Connection test
|
||||
*
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
||||
* @author Lennart Rosam <hello@takuto.de>
|
||||
* @author Lukas Reschke <lukas@statuscode.ch>
|
||||
* @author Marc Hefter <marchefter@march42.net>
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
|
|
@ -123,6 +124,13 @@ class Configuration {
|
|||
'ldapExtStorageHomeAttribute' => null,
|
||||
'ldapMatchingRuleInChainState' => self::LDAP_SERVER_FEATURE_UNKNOWN,
|
||||
'ldapConnectionTimeout' => 15,
|
||||
'ldapAttributePhone' => null,
|
||||
'ldapAttributeWebsite' => null,
|
||||
'ldapAttributeAddress' => null,
|
||||
'ldapAttributeOrganisation' => null,
|
||||
'ldapAttributeRole' => null,
|
||||
'ldapAttributeHeadline' => null,
|
||||
'ldapAttributeBiography' => null,
|
||||
];
|
||||
|
||||
public function __construct(string $configPrefix, bool $autoRead = true) {
|
||||
|
|
@ -469,6 +477,13 @@ class Configuration {
|
|||
'ldap_ext_storage_home_attribute' => '',
|
||||
'ldap_matching_rule_in_chain_state' => self::LDAP_SERVER_FEATURE_UNKNOWN,
|
||||
'ldap_connection_timeout' => 15,
|
||||
'ldap_attr_phone' => '',
|
||||
'ldap_attr_website' => '',
|
||||
'ldap_attr_address' => '',
|
||||
'ldap_attr_organisation' => '',
|
||||
'ldap_attr_role' => '',
|
||||
'ldap_attr_headline' => '',
|
||||
'ldap_attr_biography' => '',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -535,6 +550,13 @@ class Configuration {
|
|||
'ldap_matching_rule_in_chain_state' => 'ldapMatchingRuleInChainState',
|
||||
'ldapIgnoreNamingRules' => 'ldapIgnoreNamingRules', // sysconfig
|
||||
'ldap_connection_timeout' => 'ldapConnectionTimeout',
|
||||
'ldap_attr_phone' => 'ldapAttributePhone',
|
||||
'ldap_attr_website' => 'ldapAttributeWebsite',
|
||||
'ldap_attr_address' => 'ldapAttributeAddress',
|
||||
'ldap_attr_organisation' => 'ldapAttributeOrganisation',
|
||||
'ldap_attr_role' => 'ldapAttributeRole',
|
||||
'ldap_attr_headline' => 'ldapAttributeHeadline',
|
||||
'ldap_attr_biography' => 'ldapAttributeBiography',
|
||||
];
|
||||
return $array;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,13 @@ use Psr\Log\LoggerInterface;
|
|||
* @property int hasMemberOfFilterSupport
|
||||
* @property int useMemberOfToDetectMembership
|
||||
* @property string ldapMatchingRuleInChainState
|
||||
* @property string ldapAttributePhone
|
||||
* @property string ldapAttributeWebsite
|
||||
* @property string ldapAttributeAddress
|
||||
* @property string ldapAttributeOrganisation
|
||||
* @property string ldapAttributeRole
|
||||
* @property string ldapAttributeHeadline
|
||||
* @property string ldapAttributeBiography
|
||||
*/
|
||||
class Connection extends LDAPUtility {
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
||||
* @author Marc Hefter <marchefter@march42.net>
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
* @author Roger Szabo <roger.szabo@web.de>
|
||||
|
|
@ -152,6 +153,13 @@ class Manager {
|
|||
$this->access->getConnection()->ldapUserDisplayName,
|
||||
$this->access->getConnection()->ldapUserDisplayName2,
|
||||
$this->access->getConnection()->ldapExtStorageHomeAttribute,
|
||||
$this->access->getConnection()->ldapAttributePhone,
|
||||
$this->access->getConnection()->ldapAttributeWebsite,
|
||||
$this->access->getConnection()->ldapAttributeAddress,
|
||||
$this->access->getConnection()->ldapAttributeOrganisation,
|
||||
$this->access->getConnection()->ldapAttributeRole,
|
||||
$this->access->getConnection()->ldapAttributeHeadline,
|
||||
$this->access->getConnection()->ldapAttributeBiography,
|
||||
];
|
||||
|
||||
$homeRule = (string)$this->access->getConnection()->homeFolderNamingRule;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
* @author Joas Schilling <coding@schilljs.com>
|
||||
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
||||
* @author Juan Pablo Villafáñez <jvillafanez@solidgear.es>
|
||||
* @author Marc Hefter <marchefter@march42.net>
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
* @author Philipp Staiger <philipp@staiger.it>
|
||||
* @author Roger Szabo <roger.szabo@web.de>
|
||||
|
|
@ -35,6 +36,7 @@ use OCA\User_LDAP\Access;
|
|||
use OCA\User_LDAP\Connection;
|
||||
use OCA\User_LDAP\Exceptions\AttributeNotSet;
|
||||
use OCA\User_LDAP\FilesystemHelper;
|
||||
use OCP\Accounts\IAccountManager;
|
||||
use OCP\IAvatarManager;
|
||||
use OCP\IConfig;
|
||||
use OCP\ILogger;
|
||||
|
|
@ -108,6 +110,17 @@ class User {
|
|||
*/
|
||||
public const USER_PREFKEY_FIRSTLOGIN = 'firstLoginAccomplished';
|
||||
|
||||
/**
|
||||
* DB config keys for user profile
|
||||
*/
|
||||
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_ORGANISATION = 'profile_organisation';
|
||||
public const USER_PREFKEY_ROLE = 'profile_role';
|
||||
public const USER_PREFKEY_HEADLINE = 'profile_headline';
|
||||
public const USER_PREFKEY_BIOGRAPHY = 'profile_biography';
|
||||
|
||||
/**
|
||||
* @brief constructor, make sure the subclasses call this one!
|
||||
* @param string $username the internal username
|
||||
|
|
@ -231,6 +244,49 @@ class User {
|
|||
}
|
||||
unset($attr);
|
||||
|
||||
//User Profile Field - Phone number
|
||||
$attr = strtolower($this->connection->ldapAttributePhone);
|
||||
if (isset($ldapEntry[$attr])) {
|
||||
$this->updateProfile(self::USER_PREFKEY_PHONE, $ldapEntry[$attr][0]);
|
||||
}
|
||||
unset($attr);
|
||||
//User Profile Field - website
|
||||
$attr = strtolower($this->connection->ldapAttributeWebsite);
|
||||
if (isset($ldapEntry[$attr])) {
|
||||
$this->updateProfile(self::USER_PREFKEY_WEBSITE, $ldapEntry[$attr][0]);
|
||||
}
|
||||
unset($attr);
|
||||
//User Profile Field - Address
|
||||
$attr = strtolower($this->connection->ldapAttributeAddress);
|
||||
if (isset($ldapEntry[$attr])) {
|
||||
$this->updateProfile(self::USER_PREFKEY_ADDRESS, $ldapEntry[$attr][0]);
|
||||
}
|
||||
unset($attr);
|
||||
//User Profile Field - organisation
|
||||
$attr = strtolower($this->connection->ldapAttributeAddress);
|
||||
if (isset($ldapEntry[$attr])) {
|
||||
$this->updateProfile(self::USER_PREFKEY_ORGANISATION, $ldapEntry[$attr][0]);
|
||||
}
|
||||
unset($attr);
|
||||
//User Profile Field - role
|
||||
$attr = strtolower($this->connection->ldapAttributeAddress);
|
||||
if (isset($ldapEntry[$attr])) {
|
||||
$this->updateProfile(self::USER_PREFKEY_ROLE, $ldapEntry[$attr][0]);
|
||||
}
|
||||
unset($attr);
|
||||
//User Profile Field - headline
|
||||
$attr = strtolower($this->connection->ldapAttributeAddress);
|
||||
if (isset($ldapEntry[$attr])) {
|
||||
$this->updateProfile(self::USER_PREFKEY_HEADLINE, $ldapEntry[$attr][0]);
|
||||
}
|
||||
unset($attr);
|
||||
//User Profile Field - biography
|
||||
$attr = strtolower($this->connection->ldapAttributeAddress);
|
||||
if (isset($ldapEntry[$attr])) {
|
||||
$this->updateProfile(self::USER_PREFKEY_BIOGRAPHY, $ldapEntry[$attr][0]);
|
||||
}
|
||||
unset($attr);
|
||||
|
||||
//Avatar
|
||||
/** @var Connection $connection */
|
||||
$connection = $this->access->getConnection();
|
||||
|
|
@ -512,6 +568,46 @@ 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) {
|
||||
if ($this->wasRefreshed($property)) {
|
||||
return;
|
||||
}
|
||||
if ($valueFromLDAP !== null) {
|
||||
//$propertyValue = (string)$valueFromLDAP;
|
||||
$propertyValue = [$valueFromLDAP];
|
||||
}
|
||||
if ($propertyValue && isset($propertyValue[0])) {
|
||||
$value = $propertyValue[0];
|
||||
$this->config->setUserValue($this->getUsername(), 'user_ldap', $property, $value);
|
||||
// TODO: update user profile data; call \OCP\Accounts\IAccount::setProperty
|
||||
return $value;
|
||||
} else {
|
||||
$this->config->deleteUserValue($this->getUsername(), 'user_ldap', $property);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* called by a post_login hook to save the avatar picture
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue