diff --git a/apps/updatenotification/controller/admincontroller.php b/apps/updatenotification/controller/admincontroller.php index eddedb6c1b..5eafb1449f 100644 --- a/apps/updatenotification/controller/admincontroller.php +++ b/apps/updatenotification/controller/admincontroller.php @@ -102,11 +102,13 @@ class AdminController extends Controller { } $updateState = $this->updateChecker->getUpdateState(); $params = [ - 'isNewVersionAvailable' => ($updateState === []) ? false : true, + 'isNewVersionAvailable' => !empty($updateState['updateAvailable']), 'lastChecked' => $lastUpdateCheck, 'currentChannel' => $currentChannel, 'channels' => $channels, - 'newVersionString' => ($updateState === []) ? '' : $updateState['updateVersion'], + 'newVersionString' => (empty($updateState['updateVersion'])) ? '' : $updateState['updateVersion'], + 'downloadLink' => (empty($updateState['downloadLink'])) ? '' : $updateState['downloadLink'], + 'updaterEnabled' => $updateState['updaterEnabled'], ]; return new TemplateResponse($this->appName, 'admin', $params, ''); diff --git a/apps/updatenotification/js/admin.js b/apps/updatenotification/js/admin.js index 3bc5dd2152..d1d51e7239 100644 --- a/apps/updatenotification/js/admin.js +++ b/apps/updatenotification/js/admin.js @@ -35,6 +35,11 @@ $(document).ready(function(){ body.removeAttr('id'); body.attr('id', 'body-settings'); } + }, + error: function() { + OC.Notification.showTemporary(t('updatenotification', 'Could not start updater, please try the manual update')); + $('#oca_updatenotification_button').addClass('hidden'); + $('#oca_updatenotification_section .button').removeClass('hidden'); } }); }); diff --git a/apps/updatenotification/lib/updatechecker.php b/apps/updatenotification/lib/updatechecker.php index 32eab405a6..dc5de9d068 100644 --- a/apps/updatenotification/lib/updatechecker.php +++ b/apps/updatenotification/lib/updatechecker.php @@ -45,9 +45,13 @@ class UpdateChecker { if(isset($data['version']) && $data['version'] !== '' && $data['version'] !== []) { $result['updateAvailable'] = true; $result['updateVersion'] = $data['versionstring']; + $result['updaterEnabled'] = $data['autoupdater'] === '1'; if(substr($data['web'], 0, 8) === 'https://') { $result['updateLink'] = $data['web']; } + if(substr($data['url'], 0, 8) === 'https://') { + $result['downloadLink'] = $data['url']; + } return $result; } diff --git a/apps/updatenotification/templates/admin.php b/apps/updatenotification/templates/admin.php index 534a3032d9..4400dd277c 100644 --- a/apps/updatenotification/templates/admin.php +++ b/apps/updatenotification/templates/admin.php @@ -16,13 +16,18 @@

t('Updater')); ?>

- + t('A new version is available: %s', [$newVersionString])); ?> - - + + + + + t('Download now')) ?> + + t('Your version is up to date.')); ?> - +

diff --git a/apps/updatenotification/tests/UpdateCheckerTest.php b/apps/updatenotification/tests/UpdateCheckerTest.php index e83d4c9a24..cd11387ed1 100644 --- a/apps/updatenotification/tests/UpdateCheckerTest.php +++ b/apps/updatenotification/tests/UpdateCheckerTest.php @@ -48,11 +48,14 @@ class UpdateCheckerTest extends TestCase { 'version' => 123, 'versionstring' => 'ownCloud 123', 'web'=> 'javascript:alert(1)', + 'url'=> 'javascript:alert(2)', + 'autoupdater'=> '0', ]); $expected = [ 'updateAvailable' => true, 'updateVersion' => 'ownCloud 123', + 'updaterEnabled' => false, ]; $this->assertSame($expected, $this->updateChecker->getUpdateState()); } @@ -65,12 +68,16 @@ class UpdateCheckerTest extends TestCase { 'version' => 123, 'versionstring' => 'ownCloud 123', 'web'=> 'https://owncloud.org/myUrl', + 'url'=> 'https://downloads.nextcloud.org/server', + 'autoupdater'=> '1', ]); $expected = [ 'updateAvailable' => true, 'updateVersion' => 'ownCloud 123', + 'updaterEnabled' => true, 'updateLink' => 'https://owncloud.org/myUrl', + 'downloadLink' => 'https://downloads.nextcloud.org/server', ]; $this->assertSame($expected, $this->updateChecker->getUpdateState()); } diff --git a/apps/updatenotification/tests/controller/AdminControllerTest.php b/apps/updatenotification/tests/controller/AdminControllerTest.php index 795c797909..887ffc0566 100644 --- a/apps/updatenotification/tests/controller/AdminControllerTest.php +++ b/apps/updatenotification/tests/controller/AdminControllerTest.php @@ -108,7 +108,12 @@ class AdminControllerTest extends TestCase { $this->updateChecker ->expects($this->once()) ->method('getUpdateState') - ->willReturn(['updateVersion' => '8.1.2']); + ->willReturn([ + 'updateAvailable' => true, + 'updateVersion' => '8.1.2', + 'downloadLink' => 'https://downloads.nextcloud.org/server', + 'updaterEnabled' => true, + ]); $params = [ 'isNewVersionAvailable' => true, @@ -116,6 +121,8 @@ class AdminControllerTest extends TestCase { 'currentChannel' => \OCP\Util::getChannel(), 'channels' => $channels, 'newVersionString' => '8.1.2', + 'downloadLink' => 'https://downloads.nextcloud.org/server', + 'updaterEnabled' => true, ]; $expected = new TemplateResponse('updatenotification', 'admin', $params, ''); @@ -149,7 +156,7 @@ class AdminControllerTest extends TestCase { $this->updateChecker ->expects($this->once()) ->method('getUpdateState') - ->willReturn([]); + ->willReturn(['updaterEnabled' => false]); $params = [ 'isNewVersionAvailable' => false, @@ -157,6 +164,8 @@ class AdminControllerTest extends TestCase { 'currentChannel' => \OCP\Util::getChannel(), 'channels' => $channels, 'newVersionString' => '', + 'downloadLink' => '', + 'updaterEnabled' => 0, ]; $expected = new TemplateResponse('updatenotification', 'admin', $params, ''); diff --git a/config/config.sample.php b/config/config.sample.php index 538dd9d7a6..8f4d2ef930 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -498,7 +498,7 @@ $CONFIG = array( /** * URL that Nextcloud should use to look for updates */ -'updater.server.url' => 'https://updates.nextcloud.com/update-server/', +'updater.server.url' => 'https://updates.nextcloud.com/updater_server/', /** * Release channel to use for updates diff --git a/lib/private/updater.php b/lib/private/updater.php index 2ebc332bd5..c1dbca24fe 100644 --- a/lib/private/updater.php +++ b/lib/private/updater.php @@ -144,7 +144,7 @@ class Updater extends BasicEmitter { return json_decode($this->config->getAppValue('core', 'lastupdateResult'), true); } - $updaterUrl = $this->config->getSystemValue('updater.server.url', 'https://updates.nextcloud.com/update-server/'); + $updaterUrl = $this->config->getSystemValue('updater.server.url', 'https://updates.nextcloud.com/updater_server/'); $this->config->setAppValue('core', 'lastupdatedat', time()); @@ -174,6 +174,7 @@ class Updater extends BasicEmitter { $tmp['versionstring'] = (string)$data->versionstring; $tmp['url'] = (string)$data->url; $tmp['web'] = (string)$data->web; + $tmp['autoupdater'] = (string)$data->autoupdater; } else { libxml_clear_errors(); } diff --git a/tests/lib/updater.php b/tests/lib/updater.php index 2ceb260407..e106078f76 100644 --- a/tests/lib/updater.php +++ b/tests/lib/updater.php @@ -212,6 +212,7 @@ class UpdaterTest extends \Test\TestCase { 'versionstring' => 'ownCloud 8.0.4', 'url' => 'https://download.owncloud.org/community/owncloud-8.0.4.zip', 'web' => 'http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html', + 'autoupdater' => '0', ]; $this->config @@ -222,8 +223,8 @@ class UpdaterTest extends \Test\TestCase { $this->config ->expects($this->at(1)) ->method('getSystemValue') - ->with('updater.server.url', 'https://updates.nextcloud.com/update-server/') - ->willReturn('https://updates.nextcloud.com/update-server/'); + ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') + ->willReturnArgument(1); $this->config ->expects($this->at(2)) ->method('setAppValue') @@ -249,11 +250,12 @@ class UpdaterTest extends \Test\TestCase { ownCloud 8.0.4 https://download.owncloud.org/community/owncloud-8.0.4.zip http://doc.owncloud.org/server/8.0/admin_manual/maintenance/upgrade.html + 0 '; $this->httpHelper ->expects($this->once()) ->method('getUrlContent') - ->with($this->buildUpdateUrl('https://updates.nextcloud.com/update-server/')) + ->with($this->buildUpdateUrl('https://updates.nextcloud.com/updater_server/')) ->will($this->returnValue($updateXml)); $this->assertSame($expectedResult, $this->updater->check()); @@ -268,8 +270,8 @@ class UpdaterTest extends \Test\TestCase { $this->config ->expects($this->at(1)) ->method('getSystemValue') - ->with('updater.server.url', 'https://updates.nextcloud.com/update-server/') - ->willReturn('https://updates.nextcloud.com/update-server/'); + ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') + ->willReturnArgument(1); $this->config ->expects($this->at(2)) ->method('setAppValue') @@ -293,7 +295,7 @@ class UpdaterTest extends \Test\TestCase { $this->httpHelper ->expects($this->once()) ->method('getUrlContent') - ->with($this->buildUpdateUrl('https://updates.nextcloud.com/update-server/')) + ->with($this->buildUpdateUrl('https://updates.nextcloud.com/updater_server/')) ->will($this->returnValue($updateXml)); $this->assertSame([], $this->updater->check()); @@ -305,6 +307,7 @@ class UpdaterTest extends \Test\TestCase { 'versionstring' => '', 'url' => '', 'web' => '', + 'autoupdater' => '', ]; $this->config @@ -315,8 +318,8 @@ class UpdaterTest extends \Test\TestCase { $this->config ->expects($this->at(1)) ->method('getSystemValue') - ->with('updater.server.url', 'https://updates.nextcloud.com/update-server/') - ->willReturn('https://updates.nextcloud.com/update-server/'); + ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') + ->willReturnArgument(1); $this->config ->expects($this->at(2)) ->method('setAppValue') @@ -338,11 +341,12 @@ class UpdaterTest extends \Test\TestCase { + '; $this->httpHelper ->expects($this->once()) ->method('getUrlContent') - ->with($this->buildUpdateUrl('https://updates.nextcloud.com/update-server/')) + ->with($this->buildUpdateUrl('https://updates.nextcloud.com/updater_server/')) ->will($this->returnValue($updateXml)); $this->assertSame($expectedResult, $this->updater->check()); @@ -359,8 +363,8 @@ class UpdaterTest extends \Test\TestCase { $this->config ->expects($this->at(1)) ->method('getSystemValue') - ->with('updater.server.url', 'https://updates.nextcloud.com/update-server/') - ->willReturn('https://updates.nextcloud.com/update-server/'); + ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') + ->willReturnArgument(1); $this->config ->expects($this->at(2)) ->method('setAppValue') @@ -384,7 +388,7 @@ class UpdaterTest extends \Test\TestCase { $this->httpHelper ->expects($this->once()) ->method('getUrlContent') - ->with($this->buildUpdateUrl('https://updates.nextcloud.com/update-server/')) + ->with($this->buildUpdateUrl('https://updates.nextcloud.com/updater_server/')) ->will($this->returnValue($updateXml)); $this->assertSame($expectedResult, $this->updater->check());