Hide updater button when web updater is disabled

Whenever the web updater is disabled, the updater button and its
matching token requesting endpoints are disabled.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
This commit is contained in:
Vincent Petry 2021-02-17 09:34:01 +01:00
parent d4b99c81f3
commit 6ce469132c
No known key found for this signature in database
GPG Key ID: E055D6A4D513575C
7 changed files with 34 additions and 14 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -29,6 +29,7 @@ namespace OCA\UpdateNotification\Controller;
use OCA\UpdateNotification\ResetTokenBackgroundJob;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
@ -74,6 +75,10 @@ class AdminController extends Controller {
$this->l10n = $l10n;
}
private function isUpdaterEnabled() {
return !$this->config->getSystemValue('upgrade.disable-web', false);
}
/**
* @param string $channel
* @return DataResponse
@ -88,6 +93,10 @@ class AdminController extends Controller {
* @return DataResponse
*/
public function createCredentials(): DataResponse {
if (!$this->isUpdaterEnabled()) {
return new DataResponse(['status' => 'error', 'message' => $this->l10n->t('Web updater is disabled')], Http::STATUS_FORBIDDEN);
}
// Create a new job and store the creation date
$this->jobList->add(ResetTokenBackgroundJob::class);
$this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime());

View File

@ -110,6 +110,7 @@ class Admin implements ISettings {
'newVersionString' => empty($updateState['updateVersionString']) ? '' : $updateState['updateVersionString'],
'downloadLink' => empty($updateState['downloadLink']) ? '' : $updateState['downloadLink'],
'changes' => $this->filterChanges($updateState['changes'] ?? []),
'webUpdaterEnabled' => !$this->config->getSystemValue('upgrade.disable-web', false),
'updaterEnabled' => empty($updateState['updaterEnabled']) ? false : $updateState['updaterEnabled'],
'versionIsEol' => empty($updateState['versionIsEol']) ? false : $updateState['versionIsEol'],
'isDefaultUpdateServerURL' => $isDefaultUpdateServerURL,

View File

@ -42,7 +42,7 @@
</template>
<div>
<a v-if="updaterEnabled"
<a v-if="updaterEnabled && webUpdaterEnabled"
href="#"
class="button primary"
@click="clickUpdaterButton">{{ t('updatenotification', 'Open updater') }}</a>
@ -50,6 +50,9 @@
:href="downloadLink"
class="button"
:class="{ hidden: !updaterEnabled }">{{ t('updatenotification', 'Download now') }}</a>
<span v-if="updaterEnabled && !webUpdaterEnabled">
{{ t('updatenotification', 'Please use the command line updater to update.') }}
</span>
<div v-if="whatsNew" class="whatsNew">
<div class="toggleWhatsNew">
<a v-click-outside="hideMenu" class="button" @click="toggleMenu">{{ t('updatenotification', 'What\'s new?') }}</a>
@ -132,6 +135,7 @@ export default {
newVersionString: '',
lastCheckedDate: '',
isUpdateChecked: false,
webUpdaterEnabled: true,
updaterEnabled: true,
versionIsEol: false,
downloadLink: '',
@ -322,6 +326,7 @@ export default {
this.newVersionString = data.newVersionString
this.lastCheckedDate = data.lastChecked
this.isUpdateChecked = data.isUpdateChecked
this.webUpdaterEnabled = data.webUpdaterEnabled
this.updaterEnabled = data.updaterEnabled
this.downloadLink = data.downloadLink
this.isNewVersionAvailable = data.isNewVersionAvailable

View File

@ -9,6 +9,5 @@ declare(strict_types=1);
* later. See the COPYING file.
*/
script('updatenotification', 'updatenotification');
/** @var array $_ */
?>
/** @var array $_ */ ?>
<div id="updatenotification" data-json="<?php p($_['json']); ?>"></div>

View File

@ -93,10 +93,11 @@ class AdminTest extends TestCase {
['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
]);
$this->config
->expects($this->once())
->method('getSystemValue')
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
->willReturn('https://updates.nextcloud.com/updater_server/');
->willReturnMap([
['updater.server.url', 'https://updates.nextcloud.com/updater_server/', 'https://updates.nextcloud.com/updater_server/'],
['upgrade.disable-web', false, false],
]);
$this->dateTimeFormatter
->expects($this->once())
->method('formatDateTime')
@ -143,6 +144,7 @@ class AdminTest extends TestCase {
'newVersionString' => 'Nextcloud 8.1.2',
'downloadLink' => 'https://downloads.nextcloud.org/server',
'changes' => [],
'webUpdaterEnabled' => true,
'updaterEnabled' => true,
'versionIsEol' => false,
'isDefaultUpdateServerURL' => true,
@ -178,10 +180,11 @@ class AdminTest extends TestCase {
['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
]);
$this->config
->expects($this->once())
->method('getSystemValue')
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
->willReturn('https://updates.nextcloud.com/updater_server_changed/');
->willReturnMap([
['updater.server.url', 'https://updates.nextcloud.com/updater_server/', 'https://updates.nextcloud.com/updater_server_changed/'],
['upgrade.disable-web', false, true],
]);
$this->dateTimeFormatter
->expects($this->once())
->method('formatDateTime')
@ -228,6 +231,7 @@ class AdminTest extends TestCase {
'newVersionString' => 'Nextcloud 8.1.2',
'downloadLink' => 'https://downloads.nextcloud.org/server',
'changes' => [],
'webUpdaterEnabled' => false,
'updaterEnabled' => true,
'versionIsEol' => false,
'isDefaultUpdateServerURL' => false,
@ -263,10 +267,11 @@ class AdminTest extends TestCase {
['updatenotification', 'notify_groups', '["admin"]', '["admin"]'],
]);
$this->config
->expects($this->once())
->method('getSystemValue')
->with('updater.server.url', 'https://updates.nextcloud.com/updater_server/')
->willReturn('https://updates.nextcloud.com/customers/ABC-DEF/');
->willReturnMap([
['updater.server.url', 'https://updates.nextcloud.com/updater_server/', 'https://updates.nextcloud.com/customers/ABC-DEF/'],
['upgrade.disable-web', false, false],
]);
$this->dateTimeFormatter
->expects($this->once())
->method('formatDateTime')
@ -313,6 +318,7 @@ class AdminTest extends TestCase {
'newVersionString' => 'Nextcloud 8.1.2',
'downloadLink' => 'https://downloads.nextcloud.org/server',
'changes' => [],
'webUpdaterEnabled' => true,
'updaterEnabled' => true,
'versionIsEol' => false,
'isDefaultUpdateServerURL' => true,