Expose user language through DAV

Introduces the '{http://nextcloud.com/ns}language' prop that gives the
user's language

Closes #28449

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
pull/28458/head
Thomas Citharel 3 years ago
parent 5da4227380
commit a7b9b398a3
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

@ -52,6 +52,7 @@ $principalBackend = new Principal(
\OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class),
\OC::$server->get(KnownUserService::class),
\OC::$server->getConfig(),
\OC::$server->getL10NFactory(),
'principals/'
);
$db = \OC::$server->getDatabaseConnection();

@ -55,6 +55,7 @@ $principalBackend = new Principal(
\OC::$server->query(\OCA\DAV\CalDAV\Proxy\ProxyMapper::class),
\OC::$server->get(KnownUserService::class),
\OC::$server->getConfig(),
\OC::$server->getL10NFactory(),
'principals/'
);
$db = \OC::$server->getDatabaseConnection();

@ -87,7 +87,8 @@ class CreateCalendar extends Command {
\OC::$server->getAppManager(),
\OC::$server->query(ProxyMapper::class),
\OC::$server->get(KnownUserService::class),
\OC::$server->getConfig()
\OC::$server->getConfig(),
\OC::$server->getL10NFactory(),
);
$random = \OC::$server->getSecureRandom();
$logger = \OC::$server->getLogger();

@ -50,6 +50,7 @@ use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Share\IManager as IShareManager;
use Sabre\DAV\Exception;
use Sabre\DAV\PropPatch;
@ -89,6 +90,8 @@ class Principal implements BackendInterface {
/** @var IConfig */
private $config;
/** @var IFactory */
private $languageFactory;
public function __construct(IUserManager $userManager,
IGroupManager $groupManager,
@ -98,6 +101,7 @@ class Principal implements BackendInterface {
ProxyMapper $proxyMapper,
KnownUserService $knownUserService,
IConfig $config,
IFactory $languageFactory,
string $principalPrefix = 'principals/users/') {
$this->userManager = $userManager;
$this->groupManager = $groupManager;
@ -109,6 +113,7 @@ class Principal implements BackendInterface {
$this->proxyMapper = $proxyMapper;
$this->knownUserService = $knownUserService;
$this->config = $config;
$this->languageFactory = $languageFactory;
}
use PrincipalProxyTrait {
@ -508,6 +513,7 @@ class Principal implements BackendInterface {
'uri' => $this->principalPrefix . '/' . $userId,
'{DAV:}displayname' => is_null($displayName) ? $userId : $displayName,
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL',
'{http://nextcloud.com/ns}language' => $this->languageFactory->getUserLanguage($user),
];
$email = $user->getEMailAddress();

@ -73,7 +73,8 @@ class RootCollection extends SimpleCollection {
\OC::$server->getAppManager(),
$proxyMapper,
\OC::$server->get(KnownUserService::class),
\OC::$server->getConfig()
\OC::$server->getConfig(),
\OC::$server->getL10NFactory()
);
$groupPrincipalBackend = new GroupPrincipalBackend($groupManager, $userSession, $shareManager, $config);
$calendarResourcePrincipalBackend = new ResourcePrincipalBackend($db, $userSession, $groupManager, $logger, $proxyMapper);

@ -37,6 +37,7 @@ use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Security\ISecureRandom;
use OCP\Share\IManager as ShareManager;
use Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet;
@ -94,6 +95,7 @@ abstract class AbstractCalDavBackend extends TestCase {
$this->createMock(ProxyMapper::class),
$this->createMock(KnownUserService::class),
$this->createMock(IConfig::class),
$this->createMock(IFactory::class)
])
->setMethods(['getPrincipalByPath', 'getGroupMembership'])
->getMock();

@ -46,6 +46,7 @@ use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Share\IManager as ShareManager;
use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\PropPatch;
@ -141,6 +142,7 @@ class CardDavBackendTest extends TestCase {
$this->createMock(ProxyMapper::class),
$this->createMock(KnownUserService::class),
$this->createMock(IConfig::class),
$this->createMock(IFactory::class)
])
->setMethods(['getPrincipalByPath', 'getGroupMembership'])
->getMock();

@ -40,6 +40,7 @@ use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Share\IManager;
use PHPUnit\Framework\MockObject\MockObject;
use Sabre\DAV\PropPatch;
@ -72,6 +73,8 @@ class PrincipalTest extends TestCase {
private $knownUserService;
/** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
private $config;
/** @var IFactory|MockObject */
private $languageFactory;
protected function setUp(): void {
$this->userManager = $this->createMock(IUserManager::class);
@ -82,6 +85,7 @@ class PrincipalTest extends TestCase {
$this->proxyMapper = $this->createMock(ProxyMapper::class);
$this->knownUserService = $this->createMock(KnownUserService::class);
$this->config = $this->createMock(IConfig::class);
$this->languageFactory = $this->createMock(IFactory::class);
$this->connector = new \OCA\DAV\Connector\Sabre\Principal(
$this->userManager,
@ -91,7 +95,8 @@ class PrincipalTest extends TestCase {
$this->appManager,
$this->proxyMapper,
$this->knownUserService,
$this->config
$this->config,
$this->languageFactory
);
parent::setUp();
}
@ -130,16 +135,24 @@ class PrincipalTest extends TestCase {
->with('')
->willReturn([$fooUser, $barUser]);
$this->languageFactory
->expects($this->exactly(2))
->method('getUserLanguage')
->withConsecutive([$fooUser], [$barUser])
->willReturnOnConsecutiveCalls('de', 'en');
$expectedResponse = [
0 => [
'uri' => 'principals/users/foo',
'{DAV:}displayname' => 'Dr. Foo-Bar',
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL',
'{http://nextcloud.com/ns}language' => 'de',
],
1 => [
'uri' => 'principals/users/bar',
'{DAV:}displayname' => 'bar',
'{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',
]
];
@ -170,10 +183,17 @@ class PrincipalTest extends TestCase {
->with('foo')
->willReturn($fooUser);
$this->languageFactory
->expects($this->once())
->method('getUserLanguage')
->with($fooUser)
->willReturn('de');
$expectedResponse = [
'uri' => 'principals/users/foo',
'{DAV:}displayname' => 'foo',
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL',
'{http://nextcloud.com/ns}language' => 'de'
];
$response = $this->connector->getPrincipalByPath('principals/users/foo');
$this->assertSame($expectedResponse, $response);
@ -195,10 +215,17 @@ class PrincipalTest extends TestCase {
->with('foo')
->willReturn($fooUser);
$this->languageFactory
->expects($this->once())
->method('getUserLanguage')
->with($fooUser)
->willReturn('de');
$expectedResponse = [
'uri' => 'principals/users/foo',
'{DAV:}displayname' => 'foo',
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL',
'{http://nextcloud.com/ns}language' => 'de',
'{http://sabredav.org/ns}email-address' => 'foo@nextcloud.com',
];
$response = $this->connector->getPrincipalByPath('principals/users/foo');

@ -48,6 +48,7 @@ use OCP\IGroupManager;
use OCP\IServerContainer;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Share\IManager as IShareManager;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
@ -79,7 +80,8 @@ class Application extends App implements IBootstrap {
$server->get(IAppManager::class),
$server->get(ProxyMapper::class),
$server->get(KnownUserService::class),
$server->get(IConfig::class)
$server->get(IConfig::class),
$server->get(IFactory::class),
);
});

Loading…
Cancel
Save