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(
$principalBackend = new Principal(
\OC::$server->getUserManager(),
\OC::$server->getGroupManager(),
+ \OC::$server->get(IAccountManager::class),
\OC::$server->getShareManager(),
\OC::$server->getUserSession(),
\OC::$server->getAppManager(),
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;
$principalBackend = new Principal(
\OC::$server->getUserManager(),
\OC::$server->getGroupManager(),
+ \OC::$server->get(IAccountManager::class),
\OC::$server->getShareManager(),
\OC::$server->getUserSession(),
\OC::$server->getAppManager(),
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;
$principalBackend = new Principal(
$this->userManager,
$this->groupManager,
+ \OC::$server->get(IAccountManager::class),
\OC::$server->getShareManager(),
\OC::$server->getUserSession(),
\OC::$server->getAppManager(),
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;
/** @var IGroupManager */
private $groupManager;
+ /** @var IAccountManager */
+ private $accountManager;
+
/** @var IShareManager */
private $shareManager;
public function __construct(IUserManager $userManager,
IGroupManager $groupManager,
+ IAccountManager $accountManager,
IShareManager $shareManager,
IUserSession $userSession,
IAppManager $appManager,
string $principalPrefix = 'principals/users/') {
$this->userManager = $userManager;
$this->groupManager = $groupManager;
+ $this->accountManager = $accountManager;
$this->shareManager = $shareManager;
$this->userSession = $userSession;
$this->appManager = $appManager;
/**
* @param IUser $user
* @return array
+ * @throws PropertyDoesNotExistException
*/
protected function userToPrincipal($user) {
$userId = $user->getUID();
'{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;
}
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;
$userPrincipalBackend = new Principal(
$userManager,
$groupManager,
+ \OC::$server->get(IAccountManager::class),
$shareManager,
\OC::$server->getUserSession(),
\OC::$server->getAppManager(),
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;
->setConstructorArgs([
$this->userManager,
$this->groupManager,
+ $this->createMock(IAccountManager::class),
$this->createMock(ShareManager::class),
$this->createMock(IUserSession::class),
$this->createMock(IAppManager::class),
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;
->setConstructorArgs([
$this->userManager,
$this->groupManager,
+ $this->createMock(IAccountManager::class),
$this->createMock(ShareManager::class),
$this->createMock(IUserSession::class),
$this->createMock(IAppManager::class),
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;
/** @var IGroupManager | MockObject */
private $groupManager;
+ /** @var IAccountManager|MockObject */
+ private $accountManager;
+
/** @var IManager | MockObject */
private $shareManager;
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);
$this->connector = new Principal(
$this->userManager,
$this->groupManager,
+ $this->accountManager,
$this->shareManager,
$this->userSession,
$this->appManager,
->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',
'{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');
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;
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),