aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CardDAV
diff options
context:
space:
mode:
authorJake Nabasny <jake@nabasny.com>2023-11-28 11:01:52 -0500
committerRichard Steinmetz <richard@steinmetz.cloud>2024-05-30 12:01:13 +0200
commitf863290572ff91d9a8a8d6cb2ad819964c3a1426 (patch)
tree389883fb9a18bdb2dbcd466bd0f46fe9ff7b82b8 /apps/dav/lib/CardDAV
parent57a7f09a722c384cb3940c19ed2d00d5b9ec925c (diff)
downloadnextcloud-server-f863290572ff91d9a8a8d6cb2ad819964c3a1426.tar.gz
nextcloud-server-f863290572ff91d9a8a8d6cb2ad819964c3a1426.zip
feat(ldap): sync additional properties to profile and SAB
Synced from LDAP to profile: - Date of birth Synced from LDAP to SAB (via the profile): - Biography - Date of birth Original code by Jake Nabasny (GitHub: @slapcat) Co-authored-by: Jake Nabasny <jake@nabasny.com> Co-authored-by: Richard Steinmetz <richard@steinmetz.cloud> Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Diffstat (limited to 'apps/dav/lib/CardDAV')
-rw-r--r--apps/dav/lib/CardDAV/Converter.php29
1 files changed, 27 insertions, 2 deletions
diff --git a/apps/dav/lib/CardDAV/Converter.php b/apps/dav/lib/CardDAV/Converter.php
index e962aaa4392..a0a25716ed8 100644
--- a/apps/dav/lib/CardDAV/Converter.php
+++ b/apps/dav/lib/CardDAV/Converter.php
@@ -7,14 +7,17 @@
*/
namespace OCA\DAV\CardDAV;
+use DateTimeImmutable;
use Exception;
use OCP\Accounts\IAccountManager;
use OCP\IImage;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
+use Psr\Log\LoggerInterface;
use Sabre\VObject\Component\VCard;
use Sabre\VObject\Property\Text;
+use Sabre\VObject\Property\VCard\Date;
class Converter {
/** @var IURLGenerator */
@@ -23,8 +26,12 @@ class Converter {
private $accountManager;
private IUserManager $userManager;
- public function __construct(IAccountManager $accountManager,
- IUserManager $userManager, IURLGenerator $urlGenerator) {
+ public function __construct(
+ IAccountManager $accountManager,
+ IUserManager $userManager,
+ IURLGenerator $urlGenerator,
+ private LoggerInterface $logger,
+ ) {
$this->accountManager = $accountManager;
$this->userManager = $userManager;
$this->urlGenerator = $urlGenerator;
@@ -114,6 +121,24 @@ class Converter {
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:
+ try {
+ $birthdate = new DateTimeImmutable($property->getValue());
+ } catch (Exception $e) {
+ // Invalid date -> just skip the property
+ $this->logger->info("Failed to parse user's birthdate for the SAB: " . $property->getValue(), [
+ 'exception' => $e,
+ 'userId' => $user->getUID(),
+ ]);
+ break;
+ }
+ $dateProperty = new Date($vCard, 'BDAY', null, ['X-NC-SCOPE' => $scope]);
+ $dateProperty->setDateTime($birthdate);
+ $vCard->add($dateProperty);
+ break;
}
}