diff options
-rw-r--r-- | bower.json | 2 | ||||
-rw-r--r-- | js/app.js | 2 | ||||
-rw-r--r-- | js/cache.js | 19 | ||||
-rw-r--r-- | lib/controller/pagecontroller.php | 27 | ||||
-rw-r--r-- | templates/index.php | 7 | ||||
-rw-r--r-- | tests/controller/pagecontrollertest.php | 24 |
6 files changed, 63 insertions, 18 deletions
diff --git a/bower.json b/bower.json index 42a771a71..8e81edf0d 100644 --- a/bower.json +++ b/bower.json @@ -21,7 +21,7 @@ "domReady": "^2.0.1", "handlebars": "^4.0.5", "jquery": "2.2.3", - "jquery-storage-api": "jQuery-Storage-API#^1.8.1", + "jquery-storage-api": "julien-maurel/jQuery-Storage-API#~1.7.4", "jquery-visibility": "~1.0.11", "requirejs": "2.2.0", "text": "^2.0.14", @@ -28,6 +28,7 @@ define(function(require) { var Marionette = require('marionette'); var OC = require('OC'); var AppView = require('views/app'); + var Cache = require('cache'); var Radio = require('radio'); var Router = require('router'); var AccountController = require('controller/accountcontroller'); @@ -77,6 +78,7 @@ define(function(require) { Mail.on('start', function() { this.view = new AppView(); + Cache.init(); Radio.ui.trigger('content:loading'); diff --git a/js/cache.js b/js/cache.js index 44a6fdb75..4f8994a59 100644 --- a/js/cache.js +++ b/js/cache.js @@ -5,7 +5,7 @@ * later. See the COPYING file. * * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @copyright Christoph Wurst 2015 + * @copyright Christoph Wurst 2015, 2016 */ define(function(require) { @@ -61,6 +61,22 @@ define(function(require) { } }; + function init() { + console.log('initializing cacheā¦'); + var installedVersion = $('#config-installed-version').val(); + if (storage.isSet('mail-app-version')) { + var cachedVersion = storage.get('mail-app-version'); + if (cachedVersion !== installedVersion) { + console.log('clearing cache because app version has changed'); + storage.removeAll(); + } + } else { + // Could be an old version -> clear data + storage.removeAll(); + } + storage.set('mail-app-version', installedVersion); + } + /** * @param {AccountsCollection} accounts * @returns {undefined} @@ -221,6 +237,7 @@ define(function(require) { } return { + init: init, cleanUp: cleanUp, getMessage: getMessage, addMessage: addMessage, diff --git a/lib/controller/pagecontroller.php b/lib/controller/pagecontroller.php index ca0d5631c..0b5067184 100644 --- a/lib/controller/pagecontroller.php +++ b/lib/controller/pagecontroller.php @@ -24,17 +24,19 @@ namespace OCA\Mail\Controller; +use OCA\Mail\Db\MailAccountMapper; use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; use OCP\IRequest; use OCP\IURLGenerator; -use OCA\Mail\Db\MailAccountMapper; class PageController extends Controller { /** - * @var \OCA\Mail\Db\MailAccountMapper + * @var MailAccountMapper */ private $mailAccountMapper; @@ -44,20 +46,27 @@ class PageController extends Controller { private $urlGenerator; /** + * @var IConfig + */ + private $config; + + /** * @var string */ private $currentUserId; /** * @param string $appName - * @param \OCP\IRequest $request + * @param IRequest $request * @param $mailAccountMapper + * @param IConfig $config * @param $UserId */ - public function __construct($appName, IRequest $request, MailAccountMapper $mailAccountMapper, IURLGenerator $urlGenerator, $UserId) { + public function __construct($appName, IRequest $request, MailAccountMapper $mailAccountMapper, IURLGenerator $urlGenerator, IConfig $config, $UserId) { parent::__construct($appName, $request); $this->mailAccountMapper = $mailAccountMapper; $this->urlGenerator = $urlGenerator; + $this->config = $config; $this->currentUserId = $UserId; } @@ -68,10 +77,16 @@ class PageController extends Controller { * @return TemplateResponse renders the index page */ public function index() { - $response = new TemplateResponse($this->appName, 'index', []); + // TODO: remove DEBUG constant check once minimum oc + // core version >= 8.2, see https://github.com/owncloud/core/pull/18510 + $response = new TemplateResponse($this->appName, 'index', [ + 'debug' => (defined('DEBUG') && DEBUG) || $this->config->getSystemValue('debug', false), + 'app-version' => $this->config->getAppValue('mail', 'installed_version'), + ]); + // set csp rules for ownCloud 8.1 if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) { - $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy(); + $csp = new ContentSecurityPolicy(); $csp->addAllowedFrameDomain('\'self\''); $response->setContentSecurityPolicy($csp); } diff --git a/templates/index.php b/templates/index.php index 9d82ac7bf..8fdf4b4de 100644 --- a/templates/index.php +++ b/templates/index.php @@ -23,9 +23,6 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ -// TODO: remove DEBUG constant check once minimum oc -// core version >= 8.2, see https://github.com/owncloud/core/pull/18510 -$debug = (defined('DEBUG') && DEBUG) || \OC::$server->getConfig()->getSystemValue('debug', false); style('mail', 'mail'); style('mail', 'mobile'); @@ -34,7 +31,7 @@ script('mail', 'vendor/jquery-storage-api/jquery.storageapi'); script('mail', 'vendor/jquery-visibility/jquery-visibility'); script('mail', 'vendor/requirejs/require'); script('mail', 'searchproxy'); -if ($debug) { +if ($_['debug']) { // Load JS dependencies asynchronously as specified in require_config.js script('mail', 'require_config'); } else { @@ -43,6 +40,8 @@ if ($debug) { } ?> +<input type="hidden" id="config-installed-version" value="<?php p($_['app-version']); ?>"> + <div id="user-displayname" style="display: none"><?php p(\OCP\User::getDisplayName(\OCP\User::getUser())); ?></div> <div id="user-email" diff --git a/tests/controller/pagecontrollertest.php b/tests/controller/pagecontrollertest.php index 431ac514d..01fa3e1b0 100644 --- a/tests/controller/pagecontrollertest.php +++ b/tests/controller/pagecontrollertest.php @@ -1,4 +1,5 @@ <?php + /** * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @@ -29,6 +30,7 @@ class PageControllerTest extends TestCase { private $userId; private $mailAccountMapper; private $urlGenerator; + private $config; private $controller; protected function setUp() { @@ -36,19 +38,29 @@ class PageControllerTest extends TestCase { $this->appName = 'mail'; $this->userId = 'george'; - $this->request = $this->getMockBuilder('\OCP\IRequest') - ->disableOriginalConstructor() - ->getMock(); + $this->request = $this->getMock('\OCP\IRequest'); $this->mailAccountMapper = $this->getMockBuilder('OCA\Mail\Db\MailAccountMapper') ->disableOriginalConstructor() ->getMock(); $this->urlGenerator = $this->getMock('OCP\IURLGenerator'); - $this->controller = new PageController($this->appName, $this->request, - $this->mailAccountMapper, $this->urlGenerator, $this->userId); + $this->config = $this->getMock('OCP\IConfig'); + $this->controller = new PageController($this->appName, $this->request, $this->mailAccountMapper, $this->urlGenerator, $this->config, $this->userId); } public function testIndex() { - $expected = new TemplateResponse($this->appName, 'index', []); + $this->config->expects($this->once()) + ->method('getSystemValue') + ->with('debug', false) + ->will($this->returnValue(true)); + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('mail', 'installed_version') + ->will($this->returnValue('1.2.3')); + + $expected = new TemplateResponse($this->appName, 'index', [ + 'debug' => true, + 'app-version' => '1.2.3' + ]); // set csp rules for ownCloud 8.1 if (class_exists('OCP\AppFramework\Http\ContentSecurityPolicy')) { $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy(); |