Signed-off-by: Joas Schilling <coding@schilljs.com>tags/v14.0.0beta1
@@ -5,7 +5,7 @@ | |||
<description>Displays update notifications for Nextcloud and provides the SSO for the updater.</description> | |||
<licence>AGPL</licence> | |||
<author>Lukas Reschke</author> | |||
<version>1.4.0</version> | |||
<version>1.4.1</version> | |||
<namespace>UpdateNotification</namespace> | |||
<default_enable/> | |||
<dependencies> | |||
@@ -17,6 +17,6 @@ | |||
</background-jobs> | |||
<settings> | |||
<admin>OCA\UpdateNotification\Controller\AdminController</admin> | |||
<admin>OCA\UpdateNotification\Settings\Admin</admin> | |||
</settings> | |||
</info> |
@@ -11,5 +11,6 @@ return array( | |||
'OCA\\UpdateNotification\\Notification\\BackgroundJob' => $baseDir . '/../lib/Notification/BackgroundJob.php', | |||
'OCA\\UpdateNotification\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php', | |||
'OCA\\UpdateNotification\\ResetTokenBackgroundJob' => $baseDir . '/../lib/ResetTokenBackgroundJob.php', | |||
'OCA\\UpdateNotification\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php', | |||
'OCA\\UpdateNotification\\UpdateChecker' => $baseDir . '/../lib/UpdateChecker.php', | |||
); |
@@ -26,6 +26,7 @@ class ComposerStaticInitUpdateNotification | |||
'OCA\\UpdateNotification\\Notification\\BackgroundJob' => __DIR__ . '/..' . '/../lib/Notification/BackgroundJob.php', | |||
'OCA\\UpdateNotification\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php', | |||
'OCA\\UpdateNotification\\ResetTokenBackgroundJob' => __DIR__ . '/..' . '/../lib/ResetTokenBackgroundJob.php', | |||
'OCA\\UpdateNotification\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php', | |||
'OCA\\UpdateNotification\\UpdateChecker' => __DIR__ . '/..' . '/../lib/UpdateChecker.php', | |||
); | |||
@@ -26,21 +26,17 @@ | |||
namespace OCA\UpdateNotification\Controller; | |||
use OCA\UpdateNotification\ResetTokenBackgroundJob; | |||
use OCA\UpdateNotification\UpdateChecker; | |||
use OCP\AppFramework\Controller; | |||
use OCP\AppFramework\Http\DataResponse; | |||
use OCP\AppFramework\Http\TemplateResponse; | |||
use OCP\AppFramework\Utility\ITimeFactory; | |||
use OCP\BackgroundJob\IJobList; | |||
use OCP\IConfig; | |||
use OCP\IDateTimeFormatter; | |||
use OCP\IL10N; | |||
use OCP\IRequest; | |||
use OCP\Security\ISecureRandom; | |||
use OCP\Settings\ISettings; | |||
use OCP\Util; | |||
class AdminController extends Controller implements ISettings { | |||
class AdminController extends Controller { | |||
/** @var IJobList */ | |||
private $jobList; | |||
/** @var ISecureRandom */ | |||
@@ -49,12 +45,8 @@ class AdminController extends Controller implements ISettings { | |||
private $config; | |||
/** @var ITimeFactory */ | |||
private $timeFactory; | |||
/** @var UpdateChecker */ | |||
private $updateChecker; | |||
/** @var IL10N */ | |||
private $l10n; | |||
/** @var IDateTimeFormatter */ | |||
private $dateTimeFormatter; | |||
/** | |||
* @param string $appName | |||
@@ -64,8 +56,6 @@ class AdminController extends Controller implements ISettings { | |||
* @param IConfig $config | |||
* @param ITimeFactory $timeFactory | |||
* @param IL10N $l10n | |||
* @param UpdateChecker $updateChecker | |||
* @param IDateTimeFormatter $dateTimeFormatter | |||
*/ | |||
public function __construct($appName, | |||
IRequest $request, | |||
@@ -73,60 +63,13 @@ class AdminController extends Controller implements ISettings { | |||
ISecureRandom $secureRandom, | |||
IConfig $config, | |||
ITimeFactory $timeFactory, | |||
IL10N $l10n, | |||
UpdateChecker $updateChecker, | |||
IDateTimeFormatter $dateTimeFormatter) { | |||
IL10N $l10n) { | |||
parent::__construct($appName, $request); | |||
$this->jobList = $jobList; | |||
$this->secureRandom = $secureRandom; | |||
$this->config = $config; | |||
$this->timeFactory = $timeFactory; | |||
$this->l10n = $l10n; | |||
$this->updateChecker = $updateChecker; | |||
$this->dateTimeFormatter = $dateTimeFormatter; | |||
} | |||
/** | |||
* @return TemplateResponse | |||
*/ | |||
public function getForm() { | |||
$lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat'); | |||
$lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp); | |||
$channels = [ | |||
'daily', | |||
'beta', | |||
'stable', | |||
'production', | |||
]; | |||
$currentChannel = Util::getChannel(); | |||
// Remove the currently used channel from the channels list | |||
if(($key = array_search($currentChannel, $channels)) !== false) { | |||
unset($channels[$key]); | |||
} | |||
$updateState = $this->updateChecker->getUpdateState(); | |||
$notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); | |||
$defaultUpdateServerURL = 'https://updates.nextcloud.com/server/'; | |||
$updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL); | |||
$params = [ | |||
'isNewVersionAvailable' => !empty($updateState['updateAvailable']), | |||
'isUpdateChecked' => $lastUpdateCheckTimestamp > 0, | |||
'lastChecked' => $lastUpdateCheck, | |||
'currentChannel' => $currentChannel, | |||
'channels' => $channels, | |||
'newVersionString' => (empty($updateState['updateVersion'])) ? '' : $updateState['updateVersion'], | |||
'downloadLink' => (empty($updateState['downloadLink'])) ? '' : $updateState['downloadLink'], | |||
'updaterEnabled' => (empty($updateState['updaterEnabled'])) ? false : $updateState['updaterEnabled'], | |||
'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL, | |||
'updateServerURL' => $updateServerURL, | |||
'notify_groups' => implode('|', $notifyGroups), | |||
]; | |||
return new TemplateResponse($this->appName, 'admin', $params, ''); | |||
} | |||
/** | |||
@@ -153,22 +96,4 @@ class AdminController extends Controller implements ISettings { | |||
return new DataResponse($newToken); | |||
} | |||
/** | |||
* @return string the section ID, e.g. 'sharing' | |||
*/ | |||
public function getSection() { | |||
return 'server'; | |||
} | |||
/** | |||
* @return int whether the form should be rather on the top or bottom of | |||
* the admin section. The forms are arranged in ascending order of the | |||
* priority values. It is required to return a value between 0 and 100. | |||
* | |||
* E.g.: 70 | |||
*/ | |||
public function getPriority() { | |||
return 1; | |||
} | |||
} |
@@ -0,0 +1,116 @@ | |||
<?php | |||
/** | |||
* @copyright Copyright (c) 2016, ownCloud, Inc. | |||
* | |||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de> | |||
* @author Joas Schilling <coding@schilljs.com> | |||
* @author Lukas Reschke <lukas@statuscode.ch> | |||
* @author Morris Jobke <hey@morrisjobke.de> | |||
* | |||
* @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\UpdateNotification\Settings; | |||
use OCA\UpdateNotification\UpdateChecker; | |||
use OCP\AppFramework\Http\TemplateResponse; | |||
use OCP\IConfig; | |||
use OCP\IDateTimeFormatter; | |||
use OCP\Settings\ISettings; | |||
use OCP\Util; | |||
class Admin implements ISettings { | |||
/** @var IConfig */ | |||
private $config; | |||
/** @var UpdateChecker */ | |||
private $updateChecker; | |||
/** @var IDateTimeFormatter */ | |||
private $dateTimeFormatter; | |||
/** | |||
* @param IConfig $config | |||
* @param UpdateChecker $updateChecker | |||
* @param IDateTimeFormatter $dateTimeFormatter | |||
*/ | |||
public function __construct(IConfig $config, | |||
UpdateChecker $updateChecker, | |||
IDateTimeFormatter $dateTimeFormatter) { | |||
$this->config = $config; | |||
$this->updateChecker = $updateChecker; | |||
$this->dateTimeFormatter = $dateTimeFormatter; | |||
} | |||
/** | |||
* @return TemplateResponse | |||
*/ | |||
public function getForm() { | |||
$lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat'); | |||
$lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp); | |||
$channels = [ | |||
'daily', | |||
'beta', | |||
'stable', | |||
'production', | |||
]; | |||
$currentChannel = Util::getChannel(); | |||
// Remove the currently used channel from the channels list | |||
if(($key = array_search($currentChannel, $channels, true)) !== false) { | |||
unset($channels[$key]); | |||
} | |||
$updateState = $this->updateChecker->getUpdateState(); | |||
$notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); | |||
$defaultUpdateServerURL = 'https://updates.nextcloud.com/server/'; | |||
$updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL); | |||
$params = [ | |||
'isNewVersionAvailable' => !empty($updateState['updateAvailable']), | |||
'isUpdateChecked' => $lastUpdateCheckTimestamp > 0, | |||
'lastChecked' => $lastUpdateCheck, | |||
'currentChannel' => $currentChannel, | |||
'channels' => $channels, | |||
'newVersionString' => empty($updateState['updateVersion']) ? '' : $updateState['updateVersion'], | |||
'downloadLink' => empty($updateState['downloadLink']) ? '' : $updateState['downloadLink'], | |||
'updaterEnabled' => empty($updateState['updaterEnabled']) ? false : $updateState['updaterEnabled'], | |||
'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL, | |||
'updateServerURL' => $updateServerURL, | |||
'notify_groups' => implode('|', $notifyGroups), | |||
]; | |||
return new TemplateResponse('updatenotification', 'admin', $params, ''); | |||
} | |||
/** | |||
* @return string the section ID, e.g. 'sharing' | |||
*/ | |||
public function getSection() { | |||
return 'server'; | |||
} | |||
/** | |||
* @return int whether the form should be rather on the top or bottom of | |||
* the admin section. The forms are arranged in ascending order of the | |||
* priority values. It is required to return a value between 0 and 100. | |||
* | |||
* E.g.: 70 | |||
*/ | |||
public function getPriority() { | |||
return 1; | |||
} | |||
} |
@@ -54,10 +54,6 @@ class AdminControllerTest extends TestCase { | |||
private $timeFactory; | |||
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $l10n; | |||
/** @var UpdateChecker|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $updateChecker; | |||
/** @var IDateTimeFormatter|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $dateTimeFormatter; | |||
public function setUp() { | |||
parent::setUp(); | |||
@@ -68,8 +64,6 @@ class AdminControllerTest extends TestCase { | |||
$this->config = $this->createMock(IConfig::class); | |||
$this->timeFactory = $this->createMock(ITimeFactory::class); | |||
$this->l10n = $this->createMock(IL10N::class); | |||
$this->updateChecker = $this->createMock(UpdateChecker::class); | |||
$this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class); | |||
$this->adminController = new AdminController( | |||
'updatenotification', | |||
@@ -78,126 +72,10 @@ class AdminControllerTest extends TestCase { | |||
$this->secureRandom, | |||
$this->config, | |||
$this->timeFactory, | |||
$this->l10n, | |||
$this->updateChecker, | |||
$this->dateTimeFormatter | |||
$this->l10n | |||
); | |||
} | |||
public function testGetFormWithUpdate() { | |||
$channels = [ | |||
'daily', | |||
'beta', | |||
'stable', | |||
'production', | |||
]; | |||
$currentChannel = Util::getChannel(); | |||
// Remove the currently used channel from the channels list | |||
if(($key = array_search($currentChannel, $channels, true)) !== false) { | |||
unset($channels[$key]); | |||
} | |||
$this->config | |||
->expects($this->exactly(2)) | |||
->method('getAppValue') | |||
->willReturnMap([ | |||
['core', 'lastupdatedat', '', '12345'], | |||
['updatenotification', 'notify_groups', '["admin"]', '["admin"]'], | |||
]); | |||
$this->config | |||
->expects($this->once()) | |||
->method('getSystemValue') | |||
->with('updater.server.url', 'https://updates.nextcloud.com/server/') | |||
->willReturn('https://updates.nextcloud.com/server/'); | |||
$this->dateTimeFormatter | |||
->expects($this->once()) | |||
->method('formatDateTime') | |||
->with('12345') | |||
->willReturn('LastCheckedReturnValue'); | |||
$this->updateChecker | |||
->expects($this->once()) | |||
->method('getUpdateState') | |||
->willReturn([ | |||
'updateAvailable' => true, | |||
'updateVersion' => '8.1.2', | |||
'downloadLink' => 'https://downloads.nextcloud.org/server', | |||
'updaterEnabled' => true, | |||
]); | |||
$params = [ | |||
'isNewVersionAvailable' => true, | |||
'isUpdateChecked' => true, | |||
'lastChecked' => 'LastCheckedReturnValue', | |||
'currentChannel' => Util::getChannel(), | |||
'channels' => $channels, | |||
'newVersionString' => '8.1.2', | |||
'downloadLink' => 'https://downloads.nextcloud.org/server', | |||
'updaterEnabled' => true, | |||
'isDefaultUpdateServerURL' => true, | |||
'updateServerURL' => 'https://updates.nextcloud.com/server/', | |||
'notify_groups' => 'admin', | |||
]; | |||
$expected = new TemplateResponse('updatenotification', 'admin', $params, ''); | |||
$this->assertEquals($expected, $this->adminController->getForm()); | |||
} | |||
public function testGetFormWithoutUpdate() { | |||
$channels = [ | |||
'daily', | |||
'beta', | |||
'stable', | |||
'production', | |||
]; | |||
$currentChannel = Util::getChannel(); | |||
// Remove the currently used channel from the channels list | |||
if(($key = array_search($currentChannel, $channels, true)) !== false) { | |||
unset($channels[$key]); | |||
} | |||
$this->config | |||
->expects($this->exactly(2)) | |||
->method('getAppValue') | |||
->willReturnMap([ | |||
['core', 'lastupdatedat', '', '12345'], | |||
['updatenotification', 'notify_groups', '["admin"]', '["admin"]'], | |||
]); | |||
$this->config | |||
->expects($this->once()) | |||
->method('getSystemValue') | |||
->with('updater.server.url', 'https://updates.nextcloud.com/server/') | |||
->willReturn('https://updates.nextcloud.com/server/'); | |||
$this->dateTimeFormatter | |||
->expects($this->once()) | |||
->method('formatDateTime') | |||
->with('12345') | |||
->willReturn('LastCheckedReturnValue'); | |||
$this->updateChecker | |||
->expects($this->once()) | |||
->method('getUpdateState') | |||
->willReturn([]); | |||
$params = [ | |||
'isNewVersionAvailable' => false, | |||
'isUpdateChecked' => true, | |||
'lastChecked' => 'LastCheckedReturnValue', | |||
'currentChannel' => Util::getChannel(), | |||
'channels' => $channels, | |||
'newVersionString' => '', | |||
'downloadLink' => '', | |||
'updaterEnabled' => 0, | |||
'isDefaultUpdateServerURL' => true, | |||
'updateServerURL' => 'https://updates.nextcloud.com/server/', | |||
'notify_groups' => 'admin', | |||
]; | |||
$expected = new TemplateResponse('updatenotification', 'admin', $params, ''); | |||
$this->assertEquals($expected, $this->adminController->getForm()); | |||
} | |||
public function testCreateCredentials() { | |||
$this->jobList | |||
->expects($this->once()) | |||
@@ -225,11 +103,4 @@ class AdminControllerTest extends TestCase { | |||
$this->assertEquals($expected, $this->adminController->createCredentials()); | |||
} | |||
public function testGetSection() { | |||
$this->assertSame('server', $this->adminController->getSection()); | |||
} | |||
public function testGetPriority() { | |||
$this->assertSame(1, $this->adminController->getPriority()); | |||
} | |||
} |
@@ -0,0 +1,126 @@ | |||
<?php | |||
/** | |||
* @copyright Copyright (c) 2016, ownCloud, Inc. | |||
* | |||
* @author Joas Schilling <coding@schilljs.com> | |||
* @author Lukas Reschke <lukas@statuscode.ch> | |||
* @author Morris Jobke <hey@morrisjobke.de> | |||
* | |||
* @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\UpdateNotification\Tests\Settings; | |||
use OCA\UpdateNotification\Settings\Admin; | |||
use OCA\UpdateNotification\UpdateChecker; | |||
use OCP\AppFramework\Http\TemplateResponse; | |||
use OCP\IConfig; | |||
use OCP\IDateTimeFormatter; | |||
use OCP\Util; | |||
use Test\TestCase; | |||
class AdminTest extends TestCase { | |||
/** @var Admin */ | |||
private $admin; | |||
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $config; | |||
/** @var UpdateChecker|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $updateChecker; | |||
/** @var IDateTimeFormatter|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $dateTimeFormatter; | |||
public function setUp() { | |||
parent::setUp(); | |||
$this->config = $this->createMock(IConfig::class); | |||
$this->updateChecker = $this->createMock(UpdateChecker::class); | |||
$this->dateTimeFormatter = $this->createMock(IDateTimeFormatter::class); | |||
$this->admin = new Admin( | |||
$this->config, | |||
$this->updateChecker, | |||
$this->dateTimeFormatter | |||
); | |||
} | |||
public function testGetFormWithUpdate() { | |||
$channels = [ | |||
'daily', | |||
'beta', | |||
'stable', | |||
'production', | |||
]; | |||
$currentChannel = Util::getChannel(); | |||
// Remove the currently used channel from the channels list | |||
if(($key = array_search($currentChannel, $channels, true)) !== false) { | |||
unset($channels[$key]); | |||
} | |||
$this->config | |||
->expects($this->exactly(2)) | |||
->method('getAppValue') | |||
->willReturnMap([ | |||
['core', 'lastupdatedat', '', '12345'], | |||
['updatenotification', 'notify_groups', '["admin"]', '["admin"]'], | |||
]); | |||
$this->config | |||
->expects($this->once()) | |||
->method('getSystemValue') | |||
->with('updater.server.url', 'https://updates.nextcloud.com/server/') | |||
->willReturn('https://updates.nextcloud.com/server/'); | |||
$this->dateTimeFormatter | |||
->expects($this->once()) | |||
->method('formatDateTime') | |||
->with('12345') | |||
->willReturn('LastCheckedReturnValue'); | |||
$this->updateChecker | |||
->expects($this->once()) | |||
->method('getUpdateState') | |||
->willReturn([ | |||
'updateAvailable' => true, | |||
'updateVersion' => '8.1.2', | |||
'downloadLink' => 'https://downloads.nextcloud.org/server', | |||
'updaterEnabled' => true, | |||
]); | |||
$params = [ | |||
'isNewVersionAvailable' => true, | |||
'isUpdateChecked' => true, | |||
'lastChecked' => 'LastCheckedReturnValue', | |||
'currentChannel' => Util::getChannel(), | |||
'channels' => $channels, | |||
'newVersionString' => '8.1.2', | |||
'downloadLink' => 'https://downloads.nextcloud.org/server', | |||
'updaterEnabled' => true, | |||
'isDefaultUpdateServerURL' => true, | |||
'updateServerURL' => 'https://updates.nextcloud.com/server/', | |||
'notify_groups' => 'admin', | |||
]; | |||
$expected = new TemplateResponse('updatenotification', 'admin', $params, ''); | |||
$this->assertEquals($expected, $this->admin->getForm()); | |||
} | |||
public function testGetSection() { | |||
$this->assertSame('server', $this->admin->getSection()); | |||
} | |||
public function testGetPriority() { | |||
$this->assertSame(1, $this->admin->getPriority()); | |||
} | |||
} |