Skip to content
12 changes: 12 additions & 0 deletions apps/dav/lib/CardDAV/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '_$!<Anniversary>!$_', ['X-NC-SCOPE' => $scope]));
break;
}
}

Expand Down
2 changes: 2 additions & 0 deletions apps/settings/lib/Settings/Personal/PersonalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
26 changes: 26 additions & 0 deletions apps/user_ldap/js/wizard/wizardTabAdvanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down Expand Up @@ -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
*
Expand Down
6 changes: 6 additions & 0 deletions apps/user_ldap/lib/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class Configuration {
'ldapAttributeHeadline' => null,
'ldapAttributeBiography' => null,
'ldapAdminGroup' => '',
'ldapAttributeBirthDate' => null,
'ldapAttributeAnniversaryDate' => null,
];

public function __construct(string $configPrefix, bool $autoRead = true) {
Expand Down Expand Up @@ -492,6 +494,8 @@ public function getDefaults(): array {
'ldap_attr_headline' => '',
'ldap_attr_biography' => '',
'ldap_admin_group' => '',
'ldap_attr_birthdate' => '',
'ldap_attr_anniversarydate' => '',
];
}

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions apps/user_ldap/lib/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
* @property string ldapAttributeHeadline
* @property string ldapAttributeBiography
* @property string ldapAdminGroup
* @property string ldapAttributeBirthDate
* @property string ldapAttributeAnniversaryDate
*/
class Connection extends LDAPUtility {
/**
Expand Down
2 changes: 2 additions & 0 deletions apps/user_ldap/lib/User/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions apps/user_ldap/lib/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions apps/user_ldap/templates/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
<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>
<p><label for="ldap_attr_birthdate"> <?php p($l->t('Birthday Field')); ?></label><input type="text" id="ldap_attr_birthdate" name="ldap_attr_birthdate" title="<?php p($l->t('User profile Birthday will be set from the specified attribute')); ?>" data-default="<?php p($_['ldap_attr_birthdate_default']); ?>"></p>
<p><label for="ldap_attr_anniversarydate"> <?php p($l->t('Anniversary Field')); ?></label><input type="text" id="ldap_attr_anniversarydate" name="ldap_attr_anniversarydate" title="<?php p($l->t('User profile Anniversary Date will be set from the specified attribute')); ?>" data-default="<?php p($_['ldap_attr_anniversarydate_default']); ?>"></p>
</div>
</div>
<?php print_unescaped($_['settingControls']); ?>
Expand Down
14 changes: 14 additions & 0 deletions lib/private/Accounts/AccountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions lib/public/Accounts/IAccountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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';
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/Accounts/AccountManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down