diff --git a/apps/dav/lib/CardDAV/Converter.php b/apps/dav/lib/CardDAV/Converter.php index 8ea75fbef7474..5fc1fd12abd42 100644 --- a/apps/dav/lib/CardDAV/Converter.php +++ b/apps/dav/lib/CardDAV/Converter.php @@ -134,6 +134,18 @@ public function createCardFromUser(IUser $user): ?VCard { case IAccountManager::PROPERTY_ROLE: $vCard->add(new Text($vCard, 'TITLE', $property->getValue(), ['X-NC-SCOPE' => $scope])); break; + case IAccountManager::PROPERTY_BIOGRAPHY: + $vCard->add(new Text($vCard, 'NOTE', $property->getValue(), ['X-NC-SCOPE' => $scope])); + break; + case IAccountManager::PROPERTY_BIRTHDATE: + $vCard->add(new Text($vCard, 'BDAY', substr($property->getValue(), 0, 8), ['VALUE' => 'DATE', 'X-NC-SCOPE' => $scope])); + break; + case IAccountManager::PROPERTY_ANNIVERSARYDATE: + $vCard->add(new Text($vCard, 'ANNIVERSARY', substr($property->getValue(), 0, 8), ['VALUE' => 'DATE', 'X-NC-SCOPE' => $scope])); + /* iOS compatibility */ + $vCard->add(new Text($vCard, 'ITEM1.X-ABDATE', substr($property->getValue(), 0, 8), ['TYPE' => 'pref', 'X-NC-SCOPE' => $scope])); + $vCard->add(new Text($vCard, 'ITEM1.X-ABLABEL', '_$!!$_', ['X-NC-SCOPE' => $scope])); + break; } } diff --git a/apps/settings/lib/Settings/Personal/PersonalInfo.php b/apps/settings/lib/Settings/Personal/PersonalInfo.php index 8974d54d45e58..e5b01e35e7eaa 100644 --- a/apps/settings/lib/Settings/Personal/PersonalInfo.php +++ b/apps/settings/lib/Settings/Personal/PersonalInfo.php @@ -167,6 +167,8 @@ public function getForm(): TemplateResponse { 'role' => $this->getProperty($account, IAccountManager::PROPERTY_ROLE), 'headline' => $this->getProperty($account, IAccountManager::PROPERTY_HEADLINE), 'biography' => $this->getProperty($account, IAccountManager::PROPERTY_BIOGRAPHY), + 'birthDate' => $this->getProperty($account, IAccountManager::PROPERTY_BIRTHDATE), + 'anniversaryDate' => $this->getProperty($account, IAccountManager::PROPERTY_ANNIVERSARYDATE), ]; $accountParameters = [ diff --git a/apps/user_ldap/js/wizard/wizardTabAdvanced.js b/apps/user_ldap/js/wizard/wizardTabAdvanced.js index 3b25189796869..4828f2fe2ff18 100644 --- a/apps/user_ldap/js/wizard/wizardTabAdvanced.js +++ b/apps/user_ldap/js/wizard/wizardTabAdvanced.js @@ -167,6 +167,14 @@ OCA = OCA || {}; $element: $('#ldap_attr_biography'), setMethod: 'setBiographyAttribute' }, + ldap_attr_birthdate: { + $element: $('#ldap_attr_birthdate'), + setMethod: 'setBirthDateAttribute' + }, + ldap_attr_anniversarydate: { + $element: $('#ldap_attr_anniversarydate'), + setMethod: 'setAnniversaryDateAttribute' + }, }; this.setManagedItems(items); }, @@ -498,6 +506,24 @@ OCA = OCA || {}; this.setElementValue(this.managedItems.ldap_attr_biography.$element, attribute); }, + /** + * sets the attribute for the Nextcloud user profile birthday + * + * @param {string} attribute + */ + setBirthDateAttribute: function(attribute) { + this.setElementValue(this.managedItems.ldap_attr_birthdate.$element, attribute); + }, + + /** + * sets the attribute for the Nextcloud user profile anniversary date + * + * @param {string} attribute + */ + setAnniversaryDateAttribute: function(attribute) { + this.setElementValue(this.managedItems.ldap_attr_anniversarydate.$element, attribute); + }, + /** * 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 b009ba3f4809e..07d0667a5f974 100644 --- a/apps/user_ldap/lib/Configuration.php +++ b/apps/user_ldap/lib/Configuration.php @@ -135,6 +135,8 @@ class Configuration { 'ldapAttributeHeadline' => null, 'ldapAttributeBiography' => null, 'ldapAdminGroup' => '', + 'ldapAttributeBirthDate' => null, + 'ldapAttributeAnniversaryDate' => null, ]; public function __construct(string $configPrefix, bool $autoRead = true) { @@ -492,6 +494,8 @@ public function getDefaults(): array { 'ldap_attr_headline' => '', 'ldap_attr_biography' => '', 'ldap_admin_group' => '', + 'ldap_attr_birthdate' => '', + 'ldap_attr_anniversarydate' => '', ]; } @@ -569,6 +573,8 @@ public function getConfigTranslationArray(): array { 'ldap_attr_headline' => 'ldapAttributeHeadline', 'ldap_attr_biography' => 'ldapAttributeBiography', 'ldap_admin_group' => 'ldapAdminGroup', + 'ldap_attr_birthdate' => 'ldapAttributeBirthDate', + 'ldap_attr_anniversarydate' => 'ldapAttributeAnniversaryDate', ]; return $array; } diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php index 37f7dcaea5ca7..2f06e13e8a9cd 100644 --- a/apps/user_ldap/lib/Connection.php +++ b/apps/user_ldap/lib/Connection.php @@ -84,6 +84,8 @@ * @property string ldapAttributeHeadline * @property string ldapAttributeBiography * @property string ldapAdminGroup + * @property string ldapAttributeBirthDate + * @property string ldapAttributeAnniversaryDate */ class Connection extends LDAPUtility { /** diff --git a/apps/user_ldap/lib/User/Manager.php b/apps/user_ldap/lib/User/Manager.php index 9d3ba333e89ef..15897a00eed0b 100644 --- a/apps/user_ldap/lib/User/Manager.php +++ b/apps/user_ldap/lib/User/Manager.php @@ -162,6 +162,8 @@ public function getAttributes($minimal = false) { $this->access->getConnection()->ldapAttributeRole, $this->access->getConnection()->ldapAttributeHeadline, $this->access->getConnection()->ldapAttributeBiography, + $this->access->getConnection()->ldapAttributeBirthDate, + $this->access->getConnection()->ldapAttributeAnniversaryDate, ]; $homeRule = (string)$this->access->getConnection()->homeFolderNamingRule; diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php index 3b0015380ecef..e3883b519cd84 100644 --- a/apps/user_ldap/lib/User/User.php +++ b/apps/user_ldap/lib/User/User.php @@ -324,6 +324,18 @@ public function processAttributes($ldapEntry) { } elseif (!empty($attr)) { // configured, but not defined $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_BIOGRAPHY] = ""; } + //User Profile Field - birthday + $attr = strtolower($this->connection->ldapAttributeBirthDate); + if (!empty($attr)) { + $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_BIRTHDATE] + = $ldapEntry[$attr][0] ?? ""; + } + //User Profile Field - anniversary date + $attr = strtolower($this->connection->ldapAttributeAnniversaryDate); + if (!empty($attr)) { + $profileValues[\OCP\Accounts\IAccountManager::PROPERTY_ANNIVERSARYDATE] + = $ldapEntry[$attr][0] ?? ""; + } // check for changed data and cache just for TTL checking $checksum = hash('sha256', json_encode($profileValues)); $this->connection->writeToCache($cacheKey, $checksum // write array to cache. is waste of cache space diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php index ae4091288b500..4b0ad91d27de2 100644 --- a/apps/user_ldap/templates/settings.php +++ b/apps/user_ldap/templates/settings.php @@ -132,6 +132,8 @@

+

+

diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php index 97156a027e61e..578322acdaa94 100644 --- a/lib/private/Accounts/AccountManager.php +++ b/lib/private/Accounts/AccountManager.php @@ -103,6 +103,8 @@ class AccountManager implements IAccountManager { self::PROPERTY_ROLE => self::SCOPE_LOCAL, self::PROPERTY_HEADLINE => self::SCOPE_LOCAL, self::PROPERTY_BIOGRAPHY => self::SCOPE_LOCAL, + self::PROPERTY_BIRTHDATE => self::SCOPE_LOCAL, + self::PROPERTY_ANNIVERSARYDATE => self::SCOPE_LOCAL, ]; public function __construct( @@ -695,6 +697,18 @@ protected function buildDefaultUserRecord(IUser $user): array { 'scope' => $scopes[self::PROPERTY_BIOGRAPHY], ], + [ + 'name' => self::PROPERTY_BIRTHDATE, + 'value' => '', + 'scope' => $scopes[self::PROPERTY_BIRTHDATE], + ], + + [ + 'name' => self::PROPERTY_ANNIVERSARYDATE, + 'value' => '', + 'scope' => $scopes[self::PROPERTY_ANNIVERSARYDATE], + ], + [ 'name' => self::PROPERTY_PROFILE_ENABLED, 'value' => $this->isProfileEnabledByDefault($this->config) ? '1' : '0', diff --git a/lib/public/Accounts/IAccountManager.php b/lib/public/Accounts/IAccountManager.php index 68eca469ad9c9..3bab8bc041fdf 100644 --- a/lib/public/Accounts/IAccountManager.php +++ b/lib/public/Accounts/IAccountManager.php @@ -140,6 +140,10 @@ interface IAccountManager { */ public const PROPERTY_PROFILE_ENABLED = 'profile_enabled'; + // To hold extra LDAP attributes + public const PROPERTY_BIRTHDATE = 'birthdate'; + public const PROPERTY_ANNIVERSARYDATE = 'anniversarydate'; + /** * The list of allowed properties * @@ -159,6 +163,8 @@ interface IAccountManager { self::PROPERTY_HEADLINE, self::PROPERTY_BIOGRAPHY, self::PROPERTY_PROFILE_ENABLED, + self::PROPERTY_BIRTHDATE, + self::PROPERTY_ANNIVERSARYDATE, ]; public const COLLECTION_EMAIL = 'additional_mail'; diff --git a/tests/lib/Accounts/AccountManagerTest.php b/tests/lib/Accounts/AccountManagerTest.php index 3d0bee5902f9c..ed9f06cb298e1 100644 --- a/tests/lib/Accounts/AccountManagerTest.php +++ b/tests/lib/Accounts/AccountManagerTest.php @@ -632,6 +632,18 @@ public function testAddMissingDefaults() { 'scope' => IAccountManager::SCOPE_LOCAL, ], + [ + 'name' => IAccountManager::PROPERTY_BIRTHDATE, + 'value' => '', + 'scope' => IAccountManager::SCOPE_LOCAL, + ], + + [ + 'name' => IAccountManager::PROPERTY_ANNIVERSARYDATE, + 'value' => '', + 'scope' => IAccountManager::SCOPE_LOCAL, + ], + [ 'name' => IAccountManager::PROPERTY_PROFILE_ENABLED, 'value' => '1',