From 6f955defe46b498f014d4e0f105d26324bb7ecd6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 27 Sep 2016 14:38:10 +0200 Subject: [PATCH 1/3] Return the autoupdater value from the server Signed-off-by: Joas Schilling --- lib/private/Updater/VersionCheck.php | 1 + tests/lib/Updater/VersionCheckTest.php | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib/private/Updater/VersionCheck.php b/lib/private/Updater/VersionCheck.php index e846052a30..d90990e279 100644 --- a/lib/private/Updater/VersionCheck.php +++ b/lib/private/Updater/VersionCheck.php @@ -89,6 +89,7 @@ class VersionCheck { $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/VersionCheckTest.php b/tests/lib/Updater/VersionCheckTest.php index d6b457da8a..7e129232ed 100644 --- a/tests/lib/Updater/VersionCheckTest.php +++ b/tests/lib/Updater/VersionCheckTest.php @@ -83,6 +83,7 @@ class VersionCheckTest 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 @@ -120,6 +121,7 @@ class VersionCheckTest 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->updater ->expects($this->once()) @@ -176,6 +178,7 @@ class VersionCheckTest extends \Test\TestCase { 'versionstring' => '', 'url' => '', 'web' => '', + 'autoupdater' => '', ]; $this->config @@ -209,6 +212,7 @@ class VersionCheckTest extends \Test\TestCase { + '; $this->updater ->expects($this->once()) From 3e00554d35be995f52fba4ab49fc6ef1b01fc37b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 27 Sep 2016 14:47:59 +0200 Subject: [PATCH 2/3] Respect updater kill switch and fall back to download button Signed-off-by: Joas Schilling --- apps/updatenotification/js/admin.js | 5 +++++ .../lib/Controller/AdminController.php | 6 ++++-- apps/updatenotification/lib/UpdateChecker.php | 4 ++++ apps/updatenotification/templates/admin.php | 13 +++++++++---- .../tests/Controller/AdminControllerTest.php | 13 +++++++++++-- apps/updatenotification/tests/UpdateCheckerTest.php | 5 +++++ 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/apps/updatenotification/js/admin.js b/apps/updatenotification/js/admin.js index 3ca45a191d..91d9f80b60 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/Controller/AdminController.php b/apps/updatenotification/lib/Controller/AdminController.php index 9f10f1b32f..56f41ebf3e 100644 --- a/apps/updatenotification/lib/Controller/AdminController.php +++ b/apps/updatenotification/lib/Controller/AdminController.php @@ -107,11 +107,13 @@ class AdminController extends Controller implements ISettings { $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); $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'], 'notify_groups' => implode('|', $notifyGroups), ]; diff --git a/apps/updatenotification/lib/UpdateChecker.php b/apps/updatenotification/lib/UpdateChecker.php index dd51831007..040a6c3a6a 100644 --- a/apps/updatenotification/lib/UpdateChecker.php +++ b/apps/updatenotification/lib/UpdateChecker.php @@ -46,9 +46,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 68ef1d423b..78337eb313 100644 --- a/apps/updatenotification/templates/admin.php +++ b/apps/updatenotification/templates/admin.php @@ -14,13 +14,18 @@ $currentChannel = $_['currentChannel']; ?>
- + t('A new version is available: %s', [$newVersionString])); ?> - - + + + + + t('Download now')) ?> + + t('Your version is up to date.')); ?> - +

diff --git a/apps/updatenotification/tests/Controller/AdminControllerTest.php b/apps/updatenotification/tests/Controller/AdminControllerTest.php index 336edffc95..2360663e1c 100644 --- a/apps/updatenotification/tests/Controller/AdminControllerTest.php +++ b/apps/updatenotification/tests/Controller/AdminControllerTest.php @@ -111,7 +111,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, @@ -119,6 +124,8 @@ class AdminControllerTest extends TestCase { 'currentChannel' => \OCP\Util::getChannel(), 'channels' => $channels, 'newVersionString' => '8.1.2', + 'downloadLink' => 'https://downloads.nextcloud.org/server', + 'updaterEnabled' => true, 'notify_groups' => 'admin', ]; @@ -155,7 +162,7 @@ class AdminControllerTest extends TestCase { $this->updateChecker ->expects($this->once()) ->method('getUpdateState') - ->willReturn([]); + ->willReturn(['updaterEnabled' => false]); $params = [ 'isNewVersionAvailable' => false, @@ -163,6 +170,8 @@ class AdminControllerTest extends TestCase { 'currentChannel' => \OCP\Util::getChannel(), 'channels' => $channels, 'newVersionString' => '', + 'downloadLink' => '', + 'updaterEnabled' => 0, 'notify_groups' => 'admin', ]; diff --git a/apps/updatenotification/tests/UpdateCheckerTest.php b/apps/updatenotification/tests/UpdateCheckerTest.php index ce19cc60f2..c5c3034dd7 100644 --- a/apps/updatenotification/tests/UpdateCheckerTest.php +++ b/apps/updatenotification/tests/UpdateCheckerTest.php @@ -50,11 +50,13 @@ class UpdateCheckerTest extends TestCase { 'versionstring' => 'Nextcloud 123', 'web'=> 'javascript:alert(1)', 'url'=> 'javascript:alert(2)', + 'autoupdater'=> '0', ]); $expected = [ 'updateAvailable' => true, 'updateVersion' => 'Nextcloud 123', + 'updaterEnabled' => false, ]; $this->assertSame($expected, $this->updateChecker->getUpdateState()); } @@ -68,12 +70,15 @@ class UpdateCheckerTest extends TestCase { 'versionstring' => 'Nextcloud 123', 'web'=> 'https://docs.nextcloud.com/myUrl', 'url'=> 'https://downloads.nextcloud.org/server', + 'autoupdater'=> '1', ]); $expected = [ 'updateAvailable' => true, 'updateVersion' => 'Nextcloud 123', + 'updaterEnabled' => true, 'updateLink' => 'https://docs.nextcloud.com/myUrl', + 'downloadLink' => 'https://downloads.nextcloud.org/server', ]; $this->assertSame($expected, $this->updateChecker->getUpdateState()); } From 615b69677eeab739db4408c51a5873f31cc51033 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 27 Sep 2016 14:52:22 +0200 Subject: [PATCH 3/3] Use the same URL everywhere Signed-off-by: Joas Schilling --- config/config.sample.php | 2 +- lib/private/Updater/VersionCheck.php | 2 +- tests/lib/Updater/VersionCheckTest.php | 16 ++++++++-------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/config/config.sample.php b/config/config.sample.php index d6680caac1..3aa0f353c5 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -519,7 +519,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/', /** * Is Nextcloud connected to the Internet or running in a closed network? diff --git a/lib/private/Updater/VersionCheck.php b/lib/private/Updater/VersionCheck.php index d90990e279..f66e109fd2 100644 --- a/lib/private/Updater/VersionCheck.php +++ b/lib/private/Updater/VersionCheck.php @@ -59,7 +59,7 @@ class VersionCheck { 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()); diff --git a/tests/lib/Updater/VersionCheckTest.php b/tests/lib/Updater/VersionCheckTest.php index 7e129232ed..c85516c320 100644 --- a/tests/lib/Updater/VersionCheckTest.php +++ b/tests/lib/Updater/VersionCheckTest.php @@ -94,7 +94,7 @@ class VersionCheckTest extends \Test\TestCase { $this->config ->expects($this->at(1)) ->method('getSystemValue') - ->with('updater.server.url', 'https://updates.nextcloud.com/update-server/') + ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') ->willReturnArgument(1); $this->config ->expects($this->at(2)) @@ -126,7 +126,7 @@ class VersionCheckTest extends \Test\TestCase { $this->updater ->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()); @@ -141,7 +141,7 @@ class VersionCheckTest extends \Test\TestCase { $this->config ->expects($this->at(1)) ->method('getSystemValue') - ->with('updater.server.url', 'https://updates.nextcloud.com/update-server/') + ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') ->willReturnArgument(1); $this->config ->expects($this->at(2)) @@ -166,7 +166,7 @@ class VersionCheckTest extends \Test\TestCase { $this->updater ->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()); @@ -189,7 +189,7 @@ class VersionCheckTest extends \Test\TestCase { $this->config ->expects($this->at(1)) ->method('getSystemValue') - ->with('updater.server.url', 'https://updates.nextcloud.com/update-server/') + ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') ->willReturnArgument(1); $this->config ->expects($this->at(2)) @@ -217,7 +217,7 @@ class VersionCheckTest extends \Test\TestCase { $this->updater ->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()); @@ -234,7 +234,7 @@ class VersionCheckTest extends \Test\TestCase { $this->config ->expects($this->at(1)) ->method('getSystemValue') - ->with('updater.server.url', 'https://updates.nextcloud.com/update-server/') + ->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/') ->willReturnArgument(1); $this->config ->expects($this->at(2)) @@ -259,7 +259,7 @@ class VersionCheckTest extends \Test\TestCase { $this->updater ->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());