Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Respect updater kill switch and fall back to download button
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Sep 27, 2016
commit 1167e695d38c4ed8c1fd0ac41a29ae350fca00f6
6 changes: 4 additions & 2 deletions apps/updatenotification/controller/admincontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@ public function displayPanel() {
}
$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, '');
Expand Down
5 changes: 5 additions & 0 deletions apps/updatenotification/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});
});
Expand Down
4 changes: 4 additions & 0 deletions apps/updatenotification/lib/updatechecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ public function getUpdateState() {
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;
}
Expand Down
13 changes: 9 additions & 4 deletions apps/updatenotification/templates/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@
<form id="oca_updatenotification_section" class="section">
<h2><?php p($l->t('Updater')); ?></h2>

<?php if($isNewVersionAvailable === true): ?>
<?php if($isNewVersionAvailable === true) { ?>
<strong><?php p($l->t('A new version is available: %s', [$newVersionString])); ?></strong>
<input type="button" id="oca_updatenotification_button" value="<?php p($l->t('Open updater')) ?>">
<?php else: ?>
<?php if ($_['updaterEnabled']) { ?>
<input type="button" id="oca_updatenotification_button" value="<?php p($l->t('Open updater')) ?>">
<?php } ?>
<?php if (!empty($_['downloadLink'])) { ?>
<a href="<?php p($_['downloadLink']); ?>" class="button<?php if ($_['updaterEnabled']) { p(' hidden'); } ?>"><?php p($l->t('Download now')) ?></a>
<?php } ?>
<?php } else { ?>
<strong><?php print_unescaped($l->t('Your version is up to date.')); ?></strong>
<span class="icon-info svg" title="<?php p($l->t('Checked on %s', [$lastCheckedDate])) ?>"></span>
<?php endif; ?>
<?php } ?>

<p>
<label for="release-channel"><?php p($l->t('Update channel:')) ?></label>
Expand Down
7 changes: 7 additions & 0 deletions apps/updatenotification/tests/UpdateCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ public function testGetUpdateStateWithUpdateAndInvalidLink() {
'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());
}
Expand All @@ -65,12 +68,16 @@ public function testGetUpdateStateWithUpdateAndValidLink() {
'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());
}
Expand Down
13 changes: 11 additions & 2 deletions apps/updatenotification/tests/controller/AdminControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,21 @@ public function testDisplayPanelWithUpdate() {
$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,
'lastChecked' => 'LastCheckedReturnValue',
'currentChannel' => \OCP\Util::getChannel(),
'channels' => $channels,
'newVersionString' => '8.1.2',
'downloadLink' => 'https://downloads.nextcloud.org/server',
'updaterEnabled' => true,
];

$expected = new TemplateResponse('updatenotification', 'admin', $params, '');
Expand Down Expand Up @@ -149,14 +156,16 @@ public function testDisplayPanelWithoutUpdate() {
$this->updateChecker
->expects($this->once())
->method('getUpdateState')
->willReturn([]);
->willReturn(['updaterEnabled' => false]);

$params = [
'isNewVersionAvailable' => false,
'lastChecked' => 'LastCheckedReturnValue',
'currentChannel' => \OCP\Util::getChannel(),
'channels' => $channels,
'newVersionString' => '',
'downloadLink' => '',
'updaterEnabled' => 0,
];

$expected = new TemplateResponse('updatenotification', 'admin', $params, '');
Expand Down