diff options
author | Morris Jobke <hey@morrisjobke.de> | 2020-05-06 19:11:54 +0300 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2020-05-06 19:11:54 +0300 |
commit | ecbc009e2fc8aa7fd078634f4cb2271fded69fb6 (patch) | |
tree | 06a38a88467567ec86ee55bf2f83947f32a1607c /apps | |
parent | afc59665582dbd83c4c25cab21a5b30b79cac676 (diff) |
Translate the maintenance mode message in webdav
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/appinfo/v1/caldav.php | 2 | ||||
-rw-r--r-- | apps/dav/appinfo/v1/carddav.php | 2 | ||||
-rw-r--r-- | apps/dav/appinfo/v1/publicwebdav.php | 3 | ||||
-rw-r--r-- | apps/dav/appinfo/v1/webdav.php | 3 | ||||
-rw-r--r-- | apps/dav/appinfo/v2/direct.php | 2 | ||||
-rw-r--r-- | apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php | 2 | ||||
-rw-r--r-- | apps/dav/lib/Connector/Sabre/MaintenancePlugin.php | 14 | ||||
-rw-r--r-- | apps/dav/lib/Connector/Sabre/ServerFactory.php | 9 | ||||
-rw-r--r-- | apps/dav/lib/Direct/ServerFactory.php | 8 | ||||
-rw-r--r-- | apps/dav/lib/Server.php | 2 | ||||
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/MaintenancePluginTest.php | 12 | ||||
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php | 3 |
12 files changed, 42 insertions, 20 deletions
diff --git a/apps/dav/appinfo/v1/caldav.php b/apps/dav/appinfo/v1/caldav.php index 1fc708664ad..8fffe3855df 100644 --- a/apps/dav/appinfo/v1/caldav.php +++ b/apps/dav/appinfo/v1/caldav.php @@ -82,7 +82,7 @@ $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri()); $server->setBaseUri($baseuri); // Add plugins -$server->addPlugin(new MaintenancePlugin()); +$server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud')); $server->addPlugin(new \Sabre\CalDAV\Plugin()); diff --git a/apps/dav/appinfo/v1/carddav.php b/apps/dav/appinfo/v1/carddav.php index b2e812c2c18..cef3b6cec06 100644 --- a/apps/dav/appinfo/v1/carddav.php +++ b/apps/dav/appinfo/v1/carddav.php @@ -80,7 +80,7 @@ $server::$exposeVersion = false; $server->httpRequest->setUrl(\OC::$server->getRequest()->getRequestUri()); $server->setBaseUri($baseuri); // Add plugins -$server->addPlugin(new MaintenancePlugin()); +$server->addPlugin(new MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud')); $server->addPlugin(new Plugin()); diff --git a/apps/dav/appinfo/v1/publicwebdav.php b/apps/dav/appinfo/v1/publicwebdav.php index 556dd35de58..e72112aace4 100644 --- a/apps/dav/appinfo/v1/publicwebdav.php +++ b/apps/dav/appinfo/v1/publicwebdav.php @@ -55,7 +55,8 @@ $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory( \OC::$server->getTagManager(), \OC::$server->getRequest(), \OC::$server->getPreviewManager(), - \OC::$server->getEventDispatcher() + \OC::$server->getEventDispatcher(), + \OC::$server->getL10N('dav') ); $requestUri = \OC::$server->getRequest()->getRequestUri(); diff --git a/apps/dav/appinfo/v1/webdav.php b/apps/dav/appinfo/v1/webdav.php index 6a6a60b3f09..b2daf0b5cb2 100644 --- a/apps/dav/appinfo/v1/webdav.php +++ b/apps/dav/appinfo/v1/webdav.php @@ -46,7 +46,8 @@ $serverFactory = new \OCA\DAV\Connector\Sabre\ServerFactory( \OC::$server->getTagManager(), \OC::$server->getRequest(), \OC::$server->getPreviewManager(), - \OC::$server->getEventDispatcher() + \OC::$server->getEventDispatcher(), + \OC::$server->getL10N('dav') ); // Backends diff --git a/apps/dav/appinfo/v2/direct.php b/apps/dav/appinfo/v2/direct.php index 4c6e967e10e..010a3ebf827 100644 --- a/apps/dav/appinfo/v2/direct.php +++ b/apps/dav/appinfo/v2/direct.php @@ -35,7 +35,7 @@ ignore_user_abort(true); $requestUri = \OC::$server->getRequest()->getRequestUri(); -$serverFactory = new \OCA\DAV\Direct\ServerFactory(\OC::$server->getConfig()); +$serverFactory = new \OCA\DAV\Direct\ServerFactory(\OC::$server->getConfig(), \OC::$server->getL10N('dav')); $server = $serverFactory->createServer( $baseuri, $requestUri, diff --git a/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php b/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php index 9a0e78e55a8..3f4031740cc 100644 --- a/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php +++ b/apps/dav/lib/CalDAV/InvitationResponse/InvitationResponseServer.php @@ -52,7 +52,7 @@ class InvitationResponseServer { $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); // Add maintenance plugin - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); // Set URL explicitly due to reverse-proxy situations $this->server->httpRequest->setUrl($baseUri); diff --git a/apps/dav/lib/Connector/Sabre/MaintenancePlugin.php b/apps/dav/lib/Connector/Sabre/MaintenancePlugin.php index 0885edd11a9..e5db244c21f 100644 --- a/apps/dav/lib/Connector/Sabre/MaintenancePlugin.php +++ b/apps/dav/lib/Connector/Sabre/MaintenancePlugin.php @@ -28,6 +28,7 @@ namespace OCA\DAV\Connector\Sabre; use OCP\IConfig; +use OCP\IL10N; use OCP\Util; use Sabre\DAV\Exception\ServiceUnavailable; use Sabre\DAV\ServerPlugin; @@ -37,6 +38,9 @@ class MaintenancePlugin extends ServerPlugin { /** @var IConfig */ private $config; + /** @var \OCP\IL10N */ + private $l10n; + /** * Reference to main server object * @@ -47,11 +51,9 @@ class MaintenancePlugin extends ServerPlugin { /** * @param IConfig $config */ - public function __construct(IConfig $config = null) { + public function __construct(IConfig $config, IL10N $l10n) { $this->config = $config; - if (is_null($config)) { - $this->config = \OC::$server->getConfig(); - } + $this->l10n = \OC::$server->getL10N('dav'); } @@ -80,10 +82,10 @@ class MaintenancePlugin extends ServerPlugin { */ public function checkMaintenanceMode() { if ($this->config->getSystemValueBool('maintenance')) { - throw new ServiceUnavailable('System in maintenance mode.'); + throw new ServiceUnavailable($this->l10n->t('System in maintenance mode.')); } if (Util::needUpgrade()) { - throw new ServiceUnavailable('Upgrade needed'); + throw new ServiceUnavailable($this->l10n->t('Upgrade needed')); } return true; diff --git a/apps/dav/lib/Connector/Sabre/ServerFactory.php b/apps/dav/lib/Connector/Sabre/ServerFactory.php index 51543e2ed8a..8beabd3510b 100644 --- a/apps/dav/lib/Connector/Sabre/ServerFactory.php +++ b/apps/dav/lib/Connector/Sabre/ServerFactory.php @@ -38,6 +38,7 @@ use OCA\DAV\Files\BrowserErrorPagePlugin; use OCP\Files\Mount\IMountManager; use OCP\IConfig; use OCP\IDBConnection; +use OCP\IL10N; use OCP\ILogger; use OCP\IPreview; use OCP\IRequest; @@ -66,6 +67,8 @@ class ServerFactory { private $previewManager; /** @var EventDispatcherInterface */ private $eventDispatcher; + /** @var IL10N */ + private $l10n; /** * @param IConfig $config @@ -86,7 +89,8 @@ class ServerFactory { ITagManager $tagManager, IRequest $request, IPreview $previewManager, - EventDispatcherInterface $eventDispatcher + EventDispatcherInterface $eventDispatcher, + IL10N $l10n ) { $this->config = $config; $this->logger = $logger; @@ -97,6 +101,7 @@ class ServerFactory { $this->request = $request; $this->previewManager = $previewManager; $this->eventDispatcher = $eventDispatcher; + $this->l10n = $l10n; } /** @@ -118,7 +123,7 @@ class ServerFactory { $server->setBaseUri($baseUri); // Load plugins - $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); + $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config, $this->l10n)); $server->addPlugin(new \OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin($this->config)); $server->addPlugin(new \OCA\DAV\Connector\Sabre\AnonymousOptionsPlugin()); $server->addPlugin($authPlugin); diff --git a/apps/dav/lib/Direct/ServerFactory.php b/apps/dav/lib/Direct/ServerFactory.php index f0f56921bdc..aa229e3baf3 100644 --- a/apps/dav/lib/Direct/ServerFactory.php +++ b/apps/dav/lib/Direct/ServerFactory.php @@ -31,14 +31,18 @@ use OCA\DAV\Db\DirectMapper; use OCP\AppFramework\Utility\ITimeFactory; use OCP\Files\IRootFolder; use OCP\IConfig; +use OCP\IL10N; use OCP\IRequest; class ServerFactory { /** @var IConfig */ private $config; + /** @var IL10N */ + private $l10n; - public function __construct(IConfig $config) { + public function __construct(IConfig $config, IL10N $l10n) { $this->config = $config; + $this->l10n = $l10n; } public function createServer(string $baseURI, @@ -54,7 +58,7 @@ class ServerFactory { $server->httpRequest->setUrl($requestURI); $server->setBaseUri($baseURI); - $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config)); + $server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin($this->config, $this->l10n)); return $server; } diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php index e93df5c26df..46cac5ef873 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -92,7 +92,7 @@ class Server { $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); // Add maintenance plugin - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); // Backends $authBackend = new Auth( diff --git a/apps/dav/tests/unit/Connector/Sabre/MaintenancePluginTest.php b/apps/dav/tests/unit/Connector/Sabre/MaintenancePluginTest.php index 5a4424cb327..94bd1bb0b37 100644 --- a/apps/dav/tests/unit/Connector/Sabre/MaintenancePluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/MaintenancePluginTest.php @@ -28,6 +28,7 @@ namespace OCA\DAV\Tests\unit\Connector\Sabre; use OCA\DAV\Connector\Sabre\MaintenancePlugin; use OCP\IConfig; +use OCP\IL10N; use Test\TestCase; /** @@ -38,6 +39,8 @@ use Test\TestCase; class MaintenancePluginTest extends TestCase { /** @var IConfig */ private $config; + /** @var \PHPUnit\Framework\MockObject\Builder\InvocationMocker|\PHPUnit_Framework_MockObject_Builder_InvocationMocker|IL10N */ + private $l10n; /** @var MaintenancePlugin */ private $maintenancePlugin; @@ -45,10 +48,11 @@ class MaintenancePluginTest extends TestCase { parent::setUp(); $this->config = $this->getMockBuilder(IConfig::class)->getMock(); - $this->maintenancePlugin = new MaintenancePlugin($this->config); + $this->l10n = $this->getMockBuilder(IL10N::class)->getMock(); + $this->maintenancePlugin = new MaintenancePlugin($this->config, $this->l10n); } - + public function testMaintenanceMode() { $this->expectException(\Sabre\DAV\Exception\ServiceUnavailable::class); $this->expectExceptionMessage('System in maintenance mode.'); @@ -58,6 +62,10 @@ class MaintenancePluginTest extends TestCase { ->method('getSystemValueBool') ->with('maintenance') ->willReturn(true); + $this->l10n + ->expects($this->any()) + ->method('t') + ->willReturnArgument(0); $this->maintenancePlugin->checkMaintenanceMode(); } diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php index bcc0ea75fad..112f1280778 100644 --- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php +++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php @@ -70,7 +70,8 @@ abstract class RequestTestCase extends TestCase { ->disableOriginalConstructor() ->getMock(), \OC::$server->getPreviewManager(), - \OC::$server->getEventDispatcher() + \OC::$server->getEventDispatcher(), + \OC::$server->getL10N('dav') ); } |