Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2021-08-16 18:55:27 +0300
committerThomas Citharel <tcit@tcit.fr>2021-08-16 20:03:00 +0300
commita7b9b398a35c914b39c8eb41f920612a5f21eb36 (patch)
tree696a300f8e7a33827653628464b15b0506f02035
parent5da42273805160f75436f53b829b17e7b4ed2054 (diff)
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>
-rw-r--r--apps/dav/appinfo/v1/caldav.php1
-rw-r--r--apps/dav/appinfo/v1/carddav.php1
-rw-r--r--apps/dav/lib/Command/CreateCalendar.php3
-rw-r--r--apps/dav/lib/Connector/Sabre/Principal.php6
-rw-r--r--apps/dav/lib/RootCollection.php3
-rw-r--r--apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php2
-rw-r--r--apps/dav/tests/unit/CardDAV/CardDavBackendTest.php2
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php29
-rw-r--r--apps/files_versions/lib/AppInfo/Application.php4
9 files changed, 47 insertions, 4 deletions
diff --git a/apps/dav/appinfo/v1/caldav.php b/apps/dav/appinfo/v1/caldav.php
index b1543ba3cef..28840fcef4c 100644
--- a/apps/dav/appinfo/v1/caldav.php
+++ b/apps/dav/appinfo/v1/caldav.php
@@ -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();
diff --git a/apps/dav/appinfo/v1/carddav.php b/apps/dav/appinfo/v1/carddav.php
index 637ae3eed1a..53449b91c4b 100644
--- a/apps/dav/appinfo/v1/carddav.php
+++ b/apps/dav/appinfo/v1/carddav.php
@@ -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();
diff --git a/apps/dav/lib/Command/CreateCalendar.php b/apps/dav/lib/Command/CreateCalendar.php
index 4d2012b0d39..1d818809245 100644
--- a/apps/dav/lib/Command/CreateCalendar.php
+++ b/apps/dav/lib/Command/CreateCalendar.php
@@ -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();
diff --git a/apps/dav/lib/Connector/Sabre/Principal.php b/apps/dav/lib/Connector/Sabre/Principal.php
index 5e81e155d74..4a422fa9628 100644
--- a/apps/dav/lib/Connector/Sabre/Principal.php
+++ b/apps/dav/lib/Connector/Sabre/Principal.php
@@ -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();
diff --git a/apps/dav/lib/RootCollection.php b/apps/dav/lib/RootCollection.php
index aa81d2ff222..8d921414d51 100644
--- a/apps/dav/lib/RootCollection.php
+++ b/apps/dav/lib/RootCollection.php
@@ -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);
diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
index 94e099f523e..c659e2ccc6d 100644
--- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
+++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
@@ -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();
diff --git a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
index fb9522519a5..7eda691d199 100644
--- a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
+++ b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
@@ -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();
diff --git a/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php b/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
index acaa82dca8b..ac504c37c74 100644
--- a/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
@@ -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');
diff --git a/apps/files_versions/lib/AppInfo/Application.php b/apps/files_versions/lib/AppInfo/Application.php
index f0d182043c1..c994cd2f54a 100644
--- a/apps/files_versions/lib/AppInfo/Application.php
+++ b/apps/files_versions/lib/AppInfo/Application.php
@@ -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),
);
});