]> source.dussan.org Git - nextcloud-server.git/commitdiff
Expose additional emails in {DAV:}alternate-URI-set 31029/head
authorThomas Citharel <tcit@tcit.fr>
Sat, 5 Feb 2022 18:55:23 +0000 (19:55 +0100)
committerThomas Citharel <tcit@tcit.fr>
Tue, 17 May 2022 13:11:36 +0000 (15:11 +0200)
This allows iMip invitations to be send with an alternative email as
"Reply-To" field.

Closes #27201

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
apps/dav/appinfo/v1/caldav.php
apps/dav/appinfo/v1/carddav.php
apps/dav/lib/Command/CreateCalendar.php
apps/dav/lib/Connector/Sabre/Principal.php
apps/dav/lib/RootCollection.php
apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
apps/files_versions/lib/AppInfo/Application.php

index 6a496a992e61dab164674791880b6c66ea0b6fe0..eccd31861964a083bc10af2322c2bd64cb45a655 100644 (file)
@@ -34,6 +34,7 @@ use OCA\DAV\Connector\Sabre\Auth;
 use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
 use OCA\DAV\Connector\Sabre\MaintenancePlugin;
 use OCA\DAV\Connector\Sabre\Principal;
+use OCP\Accounts\IAccountManager;
 use Psr\Log\LoggerInterface;
 
 $authBackend = new Auth(
@@ -47,6 +48,7 @@ $authBackend = new Auth(
 $principalBackend = new Principal(
        \OC::$server->getUserManager(),
        \OC::$server->getGroupManager(),
+       \OC::$server->get(IAccountManager::class),
        \OC::$server->getShareManager(),
        \OC::$server->getUserSession(),
        \OC::$server->getAppManager(),
index a0306118781ef1ffb1229cfc8cf7dda597ddd730..8cf42af9a6c72a4f63a0d1e4c8260d6c341c2aa1 100644 (file)
@@ -35,6 +35,7 @@ use OCA\DAV\Connector\Sabre\Auth;
 use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
 use OCA\DAV\Connector\Sabre\MaintenancePlugin;
 use OCA\DAV\Connector\Sabre\Principal;
+use OCP\Accounts\IAccountManager;
 use OCP\App\IAppManager;
 use Psr\Log\LoggerInterface;
 use Sabre\CardDAV\Plugin;
@@ -50,6 +51,7 @@ $authBackend = new Auth(
 $principalBackend = new Principal(
        \OC::$server->getUserManager(),
        \OC::$server->getGroupManager(),
+       \OC::$server->get(IAccountManager::class),
        \OC::$server->getShareManager(),
        \OC::$server->getUserSession(),
        \OC::$server->getAppManager(),
index 2bea82a345e65a1cf14a2a01e56cf2e6d469133f..8a945f32eba900b2702b3542e2ac0cd65c1b3e74 100644 (file)
@@ -29,6 +29,7 @@ use OC\KnownUser\KnownUserService;
 use OCA\DAV\CalDAV\CalDavBackend;
 use OCA\DAV\CalDAV\Proxy\ProxyMapper;
 use OCA\DAV\Connector\Sabre\Principal;
+use OCP\Accounts\IAccountManager;
 use OCP\EventDispatcher\IEventDispatcher;
 use OCP\IConfig;
 use OCP\IDBConnection;
@@ -83,6 +84,7 @@ class CreateCalendar extends Command {
                $principalBackend = new Principal(
                        $this->userManager,
                        $this->groupManager,
+                       \OC::$server->get(IAccountManager::class),
                        \OC::$server->getShareManager(),
                        \OC::$server->getUserSession(),
                        \OC::$server->getAppManager(),
index 94e3978e67d1a6b5f694145fd18151fa0b2c6a3e..75bee4e7b4288aef51456fd61edfc3984e96c75e 100644 (file)
@@ -41,6 +41,9 @@ use OC\KnownUser\KnownUserService;
 use OCA\Circles\Exceptions\CircleNotFoundException;
 use OCA\DAV\CalDAV\Proxy\ProxyMapper;
 use OCA\DAV\Traits\PrincipalProxyTrait;
+use OCP\Accounts\IAccountManager;
+use OCP\Accounts\IAccountProperty;
+use OCP\Accounts\PropertyDoesNotExistException;
 use OCP\App\IAppManager;
 use OCP\AppFramework\QueryException;
 use OCP\Constants;
@@ -64,6 +67,9 @@ class Principal implements BackendInterface {
        /** @var IGroupManager */
        private $groupManager;
 
+       /** @var IAccountManager */
+       private $accountManager;
+
        /** @var IShareManager */
        private $shareManager;
 
@@ -95,6 +101,7 @@ class Principal implements BackendInterface {
 
        public function __construct(IUserManager $userManager,
                                                                IGroupManager $groupManager,
+                                                               IAccountManager $accountManager,
                                                                IShareManager $shareManager,
                                                                IUserSession $userSession,
                                                                IAppManager $appManager,
@@ -105,6 +112,7 @@ class Principal implements BackendInterface {
                                                                string $principalPrefix = 'principals/users/') {
                $this->userManager = $userManager;
                $this->groupManager = $groupManager;
+               $this->accountManager = $accountManager;
                $this->shareManager = $shareManager;
                $this->userSession = $userSession;
                $this->appManager = $appManager;
@@ -506,6 +514,7 @@ class Principal implements BackendInterface {
        /**
         * @param IUser $user
         * @return array
+        * @throws PropertyDoesNotExistException
         */
        protected function userToPrincipal($user) {
                $userId = $user->getUID();
@@ -517,11 +526,18 @@ class Principal implements BackendInterface {
                        '{http://nextcloud.com/ns}language' => $this->languageFactory->getUserLanguage($user),
                ];
 
+               $account = $this->accountManager->getAccount($user);
+               $alternativeEmails = array_map(fn (IAccountProperty $property) => 'mailto:' . $property->getValue(), $account->getPropertyCollection(IAccountManager::COLLECTION_EMAIL)->getProperties());
+
                $email = $user->getSystemEMailAddress();
                if (!empty($email)) {
                        $principal['{http://sabredav.org/ns}email-address'] = $email;
                }
 
+               if (!empty($alternativeEmails)) {
+                       $principal['{DAV:}alternate-URI-set'] = $alternativeEmails;
+               }
+
                return $principal;
        }
 
index 8a11a676609be9d20cd6ee92cd15ef237fa5408a..359037587a5e11e9b27e3a4fa3b485e3f8eeae09 100644 (file)
@@ -43,6 +43,7 @@ use OCA\DAV\DAV\GroupPrincipalBackend;
 use OCA\DAV\DAV\SystemPrincipalBackend;
 use OCA\DAV\Provisioning\Apple\AppleProvisioningNode;
 use OCA\DAV\Upload\CleanupService;
+use OCP\Accounts\IAccountManager;
 use OCP\App\IAppManager;
 use OCP\AppFramework\Utility\ITimeFactory;
 use OCP\EventDispatcher\IEventDispatcher;
@@ -68,6 +69,7 @@ class RootCollection extends SimpleCollection {
                $userPrincipalBackend = new Principal(
                        $userManager,
                        $groupManager,
+                       \OC::$server->get(IAccountManager::class),
                        $shareManager,
                        \OC::$server->getUserSession(),
                        \OC::$server->getAppManager(),
index ec966248e01e96fd7806831f194abc6edcba6330..0a234fc5c8d3a203912b8d5e27deaf68885bfe3a 100644 (file)
@@ -30,6 +30,7 @@ use OC\KnownUser\KnownUserService;
 use OCA\DAV\CalDAV\CalDavBackend;
 use OCA\DAV\CalDAV\Proxy\ProxyMapper;
 use OCA\DAV\Connector\Sabre\Principal;
+use OCP\Accounts\IAccountManager;
 use OCP\App\IAppManager;
 use OCP\EventDispatcher\IEventDispatcher;
 use OCP\IConfig;
@@ -89,6 +90,7 @@ abstract class AbstractCalDavBackend extends TestCase {
                        ->setConstructorArgs([
                                $this->userManager,
                                $this->groupManager,
+                               $this->createMock(IAccountManager::class),
                                $this->createMock(ShareManager::class),
                                $this->createMock(IUserSession::class),
                                $this->createMock(IAppManager::class),
index 7eda691d199375c79a02a72aec346475cf30dd93..136751628d0171aa2742788af3166a60f78646ad 100644 (file)
@@ -37,6 +37,7 @@ use OCA\DAV\CalDAV\Proxy\ProxyMapper;
 use OCA\DAV\CardDAV\AddressBook;
 use OCA\DAV\CardDAV\CardDavBackend;
 use OCA\DAV\Connector\Sabre\Principal;
+use OCP\Accounts\IAccountManager;
 use OCP\App\IAppManager;
 use OCP\DB\QueryBuilder\IQueryBuilder;
 use OCP\EventDispatcher\IEventDispatcher;
@@ -136,6 +137,7 @@ class CardDavBackendTest extends TestCase {
                        ->setConstructorArgs([
                                $this->userManager,
                                $this->groupManager,
+                               $this->createMock(IAccountManager::class),
                                $this->createMock(ShareManager::class),
                                $this->createMock(IUserSession::class),
                                $this->createMock(IAppManager::class),
index 86413e4a366a5a6c9008e74ff43d7e08d66ef1e4..444c267b509d6bcc9db17f98327e3a8bd4427eac 100644 (file)
@@ -34,6 +34,10 @@ use OC\User\User;
 use OCA\DAV\CalDAV\Proxy\Proxy;
 use OCA\DAV\CalDAV\Proxy\ProxyMapper;
 use OCA\DAV\Connector\Sabre\Principal;
+use OCP\Accounts\IAccount;
+use OCP\Accounts\IAccountManager;
+use OCP\Accounts\IAccountProperty;
+use OCP\Accounts\IAccountPropertyCollection;
 use OCP\App\IAppManager;
 use OCP\IConfig;
 use OCP\IGroup;
@@ -59,6 +63,9 @@ class PrincipalTest extends TestCase {
        /** @var IGroupManager | MockObject */
        private $groupManager;
 
+       /** @var IAccountManager|MockObject */
+       private $accountManager;
+
        /** @var IManager | MockObject */
        private $shareManager;
 
@@ -81,6 +88,7 @@ class PrincipalTest extends TestCase {
        protected function setUp(): void {
                $this->userManager = $this->createMock(IUserManager::class);
                $this->groupManager = $this->createMock(IGroupManager::class);
+               $this->accountManager = $this->createMock(IAccountManager::class);
                $this->shareManager = $this->createMock(IManager::class);
                $this->userSession = $this->createMock(IUserSession::class);
                $this->appManager = $this->createMock(IAppManager::class);
@@ -92,6 +100,7 @@ class PrincipalTest extends TestCase {
                $this->connector = new Principal(
                        $this->userManager,
                        $this->groupManager,
+                       $this->accountManager,
                        $this->shareManager,
                        $this->userSession,
                        $this->appManager,
@@ -143,6 +152,45 @@ class PrincipalTest extends TestCase {
                        ->withConsecutive([$fooUser], [$barUser])
                        ->willReturnOnConsecutiveCalls('de', 'en');
 
+               $fooAccountPropertyCollection = $this->createMock(IAccountPropertyCollection::class);
+               $fooAccountPropertyCollection->expects($this->once())
+                       ->method('getProperties')
+                       ->with()
+                       ->willReturn([]);
+               $fooAccount = $this->createMock(IAccount::class);
+               $fooAccount->expects($this->once())
+                       ->method('getPropertyCollection')
+                       ->with(IAccountManager::COLLECTION_EMAIL)
+                       ->willReturn($fooAccountPropertyCollection);
+
+               $emailPropertyOne = $this->createMock(IAccountProperty::class);
+               $emailPropertyOne->expects($this->once())
+                       ->method('getValue')
+                       ->with()
+                       ->willReturn('alias@nextcloud.com');
+               $emailPropertyTwo = $this->createMock(IAccountProperty::class);
+               $emailPropertyTwo->expects($this->once())
+                       ->method('getValue')
+                       ->with()
+                       ->willReturn('alias2@nextcloud.com');
+
+               $barAccountPropertyCollection = $this->createMock(IAccountPropertyCollection::class);
+               $barAccountPropertyCollection->expects($this->once())
+                       ->method('getProperties')
+                       ->with()
+                       ->willReturn([$emailPropertyOne, $emailPropertyTwo]);
+               $barAccount = $this->createMock(IAccount::class);
+               $barAccount->expects($this->once())
+                       ->method('getPropertyCollection')
+                       ->with(IAccountManager::COLLECTION_EMAIL)
+                       ->willReturn($barAccountPropertyCollection);
+
+               $this->accountManager
+                       ->expects($this->exactly(2))
+                       ->method('getAccount')
+                       ->withConsecutive([$fooUser], [$barUser])
+                       ->willReturnOnConsecutiveCalls($fooAccount, $barAccount);
+
                $expectedResponse = [
                        0 => [
                                'uri' => 'principals/users/foo',
@@ -156,6 +204,7 @@ class PrincipalTest extends TestCase {
                                '{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL',
                                '{http://nextcloud.com/ns}language' => 'en',
                                '{http://sabredav.org/ns}email-address' => 'bar@nextcloud.com',
+                               '{DAV:}alternate-URI-set' => ['mailto:alias@nextcloud.com', 'mailto:alias2@nextcloud.com']
                        ]
                ];
                $response = $this->connector->getPrincipalsByPrefix('principals/users');
index c994cd2f54ada1fef09b7851c0242e0ea6653f8d..357a4179666e2ad0f61e5852b66c2f7a09885961 100644 (file)
@@ -38,6 +38,7 @@ use OCA\Files_Versions\Listener\LoadAdditionalListener;
 use OCA\Files_Versions\Listener\LoadSidebarListener;
 use OCA\Files_Versions\Versions\IVersionManager;
 use OCA\Files_Versions\Versions\VersionManager;
+use OCP\Accounts\IAccountManager;
 use OCP\App\IAppManager;
 use OCP\AppFramework\App;
 use OCP\AppFramework\Bootstrap\IBootContext;
@@ -75,6 +76,7 @@ class Application extends App implements IBootstrap {
                        return new Principal(
                                $server->get(IUserManager::class),
                                $server->get(IGroupManager::class),
+                               \OC::$server->get(IAccountManager::class),
                                $server->get(IShareManager::class),
                                $server->get(IUserSession::class),
                                $server->get(IAppManager::class),