diff options
author | Johannes Merkel <mail@johannesgge.de> | 2023-06-23 18:40:46 +0200 |
---|---|---|
committer | Johannes <74607597+JohannesGGE@users.noreply.github.com> | 2023-07-03 17:55:18 +0200 |
commit | eda3824d91107ed0ea223bca060a802a235abdab (patch) | |
tree | 1f65894d50094a95c1557da20679e78beb5b4787 /apps | |
parent | 646dfd2a40aa79b8fed8be314070bb8f629a6edc (diff) | |
download | nextcloud-server-eda3824d91107ed0ea223bca060a802a235abdab.tar.gz nextcloud-server-eda3824d91107ed0ea223bca060a802a235abdab.zip |
enh(sab): Add profileUrl to SAB
Signed-off-by: Johannes Merkel <mail@johannesgge.de>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/lib/CardDAV/Converter.php | 21 | ||||
-rw-r--r-- | apps/dav/tests/unit/CardDAV/ConverterTest.php | 11 |
2 files changed, 28 insertions, 4 deletions
diff --git a/apps/dav/lib/CardDAV/Converter.php b/apps/dav/lib/CardDAV/Converter.php index b3d8b094d69..e19b52b4783 100644 --- a/apps/dav/lib/CardDAV/Converter.php +++ b/apps/dav/lib/CardDAV/Converter.php @@ -29,6 +29,7 @@ namespace OCA\DAV\CardDAV; use Exception; use OCP\Accounts\IAccountManager; +use OCP\IURLGenerator; use OCP\IImage; use OCP\IUser; use OCP\IUserManager; @@ -36,14 +37,17 @@ use Sabre\VObject\Component\VCard; use Sabre\VObject\Property\Text; class Converter { + /** @var IURLGenerator */ + private $urlGenerator; /** @var IAccountManager */ private $accountManager; private IUserManager $userManager; public function __construct(IAccountManager $accountManager, - IUserManager $userManager) { + IUserManager $userManager, IURLGenerator $urlGenerator) { $this->accountManager = $accountManager; $this->userManager = $userManager; + $this->urlGenerator = $urlGenerator; } public function createCardFromUser(IUser $user): ?VCard { @@ -88,6 +92,21 @@ class Converter { case IAccountManager::PROPERTY_WEBSITE: $vCard->add(new Text($vCard, 'URL', $property->getValue(), ['X-NC-SCOPE' => $scope])); break; + case IAccountManager::PROPERTY_PROFILE_ENABLED: + if ($property->getValue()) { + $vCard->add( + new Text( + $vCard, + 'X-SOCIALPROFILE', + $this->urlGenerator->linkToRouteAbsolute('core.ProfilePage.index', ['targetUserId' => $user->getUID()]), + [ + 'TYPE' => 'NEXTCLOUD', + 'X-NC-SCOPE' => IAccountManager::SCOPE_PUBLISHED + ] + ) + ); + } + break; case IAccountManager::PROPERTY_PHONE: $vCard->add(new Text($vCard, 'TEL', $property->getValue(), ['TYPE' => 'VOICE', 'X-NC-SCOPE' => $scope])); break; diff --git a/apps/dav/tests/unit/CardDAV/ConverterTest.php b/apps/dav/tests/unit/CardDAV/ConverterTest.php index 6b589ec3874..7205cf56654 100644 --- a/apps/dav/tests/unit/CardDAV/ConverterTest.php +++ b/apps/dav/tests/unit/CardDAV/ConverterTest.php @@ -34,6 +34,7 @@ use OCA\DAV\CardDAV\Converter; use OCP\Accounts\IAccount; use OCP\Accounts\IAccountManager; use OCP\Accounts\IAccountProperty; +use OCP\IURLGenerator; use OCP\IImage; use OCP\IUser; use OCP\IUserManager; @@ -47,11 +48,15 @@ class ConverterTest extends TestCase { /** @var IUserManager|(IUserManager&MockObject)|MockObject */ private IUserManager|MockObject $userManager; + /** @var IURLGenerator */ + private $urlGenerator; + protected function setUp(): void { parent::setUp(); $this->accountManager = $this->createMock(IAccountManager::class); $this->userManager = $this->createMock(IUserManager::class); + $this->urlGenerator = $this->createMock(IURLGenerator::class); } /** @@ -103,7 +108,7 @@ class ConverterTest extends TestCase { $user = $this->getUserMock((string)$displayName, $eMailAddress, $cloudId); $accountManager = $this->getAccountManager($user); - $converter = new Converter($accountManager, $this->userManager); + $converter = new Converter($accountManager, $this->userManager, $this->urlGenerator); $vCard = $converter->createCardFromUser($user); if ($expectedVCard !== null) { $this->assertInstanceOf('Sabre\VObject\Component\VCard', $vCard); @@ -124,7 +129,7 @@ class ConverterTest extends TestCase { ->willReturn('Manager'); $accountManager = $this->getAccountManager($user); - $converter = new Converter($accountManager, $this->userManager); + $converter = new Converter($accountManager, $this->userManager, $this->urlGenerator); $vCard = $converter->createCardFromUser($user); $this->compareData( @@ -212,7 +217,7 @@ class ConverterTest extends TestCase { * @param $fullName */ public function testNameSplitter($expected, $fullName): void { - $converter = new Converter($this->accountManager, $this->userManager); + $converter = new Converter($this->accountManager, $this->userManager, $this->urlGenerator); $r = $converter->splitFullName($fullName); $r = implode(';', $r); $this->assertEquals($expected, $r); |