[Pkg-owncloud-commits] [owncloud] 160/457: detect migration status

David Prévot taffit at moszumanska.debian.org
Sun Jun 28 20:05:55 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch stable8
in repository owncloud.

commit 68db3059eec904e90c41a8452799222e21c9c460
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date:   Wed May 27 11:10:06 2015 +0200

    detect migration status
---
 apps/encryption/appinfo/app.php                    |  6 +-
 apps/encryption/appinfo/application.php            |  8 +-
 apps/encryption/controller/statuscontroller.php    | 15 +++-
 apps/encryption/js/encryption.js                   |  2 +-
 apps/encryption/lib/session.php                    |  1 +
 .../tests/controller/StatusControllerTest.php      | 90 ++++++++++++++++++++++
 6 files changed, 115 insertions(+), 7 deletions(-)

diff --git a/apps/encryption/appinfo/app.php b/apps/encryption/appinfo/app.php
index 0c7c231..2eb12f6 100644
--- a/apps/encryption/appinfo/app.php
+++ b/apps/encryption/appinfo/app.php
@@ -25,8 +25,10 @@ namespace OCA\Encryption\AppInfo;
 
 \OCP\Util::addscript('encryption', 'encryption');
 
-$app = new Application();
-if (\OC::$server->getEncryptionManager()->isReady()) {
+$encryptionSystemReady = \OC::$server->getEncryptionManager()->isReady();
+
+$app = new Application([], $encryptionSystemReady);
+if ($encryptionSystemReady) {
 	$app->registerEncryptionModule();
 	$app->registerHooks();
 	$app->registerSettings();
diff --git a/apps/encryption/appinfo/application.php b/apps/encryption/appinfo/application.php
index 10ad610..cb9c33c 100644
--- a/apps/encryption/appinfo/application.php
+++ b/apps/encryption/appinfo/application.php
@@ -52,12 +52,18 @@ class Application extends \OCP\AppFramework\App {
 
 	/**
 	 * @param array $urlParams
+	 * @param bool $encryptionSystemReady
 	 */
-	public function __construct($urlParams = array()) {
+	public function __construct($urlParams = array(), $encryptionSystemReady = true) {
 		parent::__construct('encryption', $urlParams);
 		$this->encryptionManager = \OC::$server->getEncryptionManager();
 		$this->config = \OC::$server->getConfig();
 		$this->registerServices();
+		if($encryptionSystemReady === false) {
+			/** @var Session $session */
+			$session = $this->getContainer()->query('Session');
+			$session->setStatus(Session::RUN_MIGRATION);
+		}
 	}
 
 	/**
diff --git a/apps/encryption/controller/statuscontroller.php b/apps/encryption/controller/statuscontroller.php
index ef3d70a..cdc4b2e 100644
--- a/apps/encryption/controller/statuscontroller.php
+++ b/apps/encryption/controller/statuscontroller.php
@@ -60,20 +60,29 @@ class StatusController extends Controller {
 	public function getStatus() {
 
 		$status = 'error';
-		$message = '';
+		$message = 'no valid init status';
 		switch( $this->session->getStatus()) {
+			case Session::RUN_MIGRATION:
+				$status = 'interactionNeeded';
+				$message = (string)$this->l->t(
+					'You need to migrate your encryption keys from the old encryption (ownCloud <= 8.0) to the new one. Please run \'occ encryption:migrate\' or contact your administrator'
+				);
+				break;
 			case Session::INIT_EXECUTED:
-				$status = 'success';
+				$status = 'interactionNeeded';
 				$message = (string)$this->l->t(
 					'Invalid private key for Encryption App. Please update your private key password in your personal settings to recover access to your encrypted files.'
 				);
 				break;
 			case Session::NOT_INITIALIZED:
-				$status = 'success';
+				$status = 'interactionNeeded';
 				$message = (string)$this->l->t(
 					'Encryption App is enabled but your keys are not initialized, please log-out and log-in again'
 				);
 				break;
+			case Session::INIT_SUCCESSFUL:
+				$status = 'success';
+				$message = (string)$this->l->t('Encryption App is enabled and ready');
 		}
 
 		return new DataResponse(
diff --git a/apps/encryption/js/encryption.js b/apps/encryption/js/encryption.js
index ea6a559..a6c1bea 100644
--- a/apps/encryption/js/encryption.js
+++ b/apps/encryption/js/encryption.js
@@ -22,7 +22,7 @@ OC.Encryption = {
 		$.get(
 			OC.generateUrl('/apps/encryption/ajax/getStatus'),
 			function (result) {
-				if (result.status === "success") {
+				if (result.status === "interactionNeeded") {
 					OC.Notification.show(result.data.message);
 				}
 			}
diff --git a/apps/encryption/lib/session.php b/apps/encryption/lib/session.php
index 85d2a76..9709518 100644
--- a/apps/encryption/lib/session.php
+++ b/apps/encryption/lib/session.php
@@ -33,6 +33,7 @@ class Session {
 	const NOT_INITIALIZED = '0';
 	const INIT_EXECUTED = '1';
 	const INIT_SUCCESSFUL = '2';
+	const RUN_MIGRATION = '3';
 
 	/**
 	 * @param ISession $session
diff --git a/apps/encryption/tests/controller/StatusControllerTest.php b/apps/encryption/tests/controller/StatusControllerTest.php
new file mode 100644
index 0000000..b57fd1c
--- /dev/null
+++ b/apps/encryption/tests/controller/StatusControllerTest.php
@@ -0,0 +1,90 @@
+<?php
+/**
+ * @author Björn Schießle <schiessle at owncloud.com>
+ *
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+
+namespace OCA\Encryption\Tests\Controller;
+
+
+use OCA\Encryption\Controller\StatusController;
+use OCA\Encryption\Session;
+use Test\TestCase;
+
+class StatusControllerTest extends TestCase {
+
+	/** @var \PHPUnit_Framework_MockObject_MockObject */
+	protected $requestMock;
+
+	/** @var \PHPUnit_Framework_MockObject_MockObject */
+	protected $l10nMock;
+
+	/** @var  \OCA\Encryption\Session | \PHPUnit_Framework_MockObject_MockObject */
+	protected $sessionMock;
+
+	/** @var StatusController */
+	protected $controller;
+
+	protected function setUp() {
+
+		parent::setUp();
+
+		$this->sessionMock = $this->getMockBuilder('OCA\Encryption\Session')
+			->disableOriginalConstructor()->getMock();
+		$this->requestMock = $this->getMock('OCP\IRequest');
+
+		$this->l10nMock = $this->getMockBuilder('OCP\IL10N')
+			->disableOriginalConstructor()->getMock();
+		$this->l10nMock->expects($this->any())
+			->method('t')
+			->will($this->returnCallback(function($message) {
+				return $message;
+			}));
+
+		$this->controller = new StatusController('encryptionTest',
+			$this->requestMock,
+			$this->l10nMock,
+			$this->sessionMock);
+
+	}
+
+	/**
+	 * @dataProvider dataTestGetStatus
+	 *
+	 * @param string $status
+	 * @param string $expectedStatus
+	 */
+	public function testGetStatus($status, $expectedStatus) {
+		$this->sessionMock->expects($this->once())
+			->method('getStatus')->willReturn($status);
+		$result = $this->controller->getStatus();
+		$data = $result->getData();
+		$this->assertSame($expectedStatus, $data['status']);
+	}
+
+	public function dataTestGetStatus() {
+		return array(
+			array(Session::RUN_MIGRATION, 'interactionNeeded'),
+			array(Session::INIT_EXECUTED, 'interactionNeeded'),
+			array(Session::INIT_SUCCESSFUL, 'success'),
+			array(Session::NOT_INITIALIZED, 'interactionNeeded'),
+			array('unknown', 'error'),
+		);
+	}
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list