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 OCA\UpdateNotification\ResetTokenBackgroundJob;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\IJobList;
@ -74,6 +75,10 @@ class AdminController extends Controller {
$this->l10n = $l10n; $this->l10n = $l10n;
} }
private function isUpdaterEnabled() {
return !$this->config->getSystemValue('upgrade.disable-web', false);
}
/** /**
* @param string $channel * @param string $channel
* @return DataResponse * @return DataResponse
@ -88,6 +93,10 @@ class AdminController extends Controller {
* @return DataResponse * @return DataResponse
*/ */
public function createCredentials(): 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 // Create a new job and store the creation date
$this->jobList->add(ResetTokenBackgroundJob::class); $this->jobList->add(ResetTokenBackgroundJob::class);
$this->config->setAppValue('core', 'updater.secret.created', $this->timeFactory->getTime()); $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'], 'newVersionString' => empty($updateState['updateVersionString']) ? '' : $updateState['updateVersionString'],
'downloadLink' => empty($updateState['downloadLink']) ? '' : $updateState['downloadLink'], 'downloadLink' => empty($updateState['downloadLink']) ? '' : $updateState['downloadLink'],
'changes' => $this->filterChanges($updateState['changes'] ?? []), 'changes' => $this->filterChanges($updateState['changes'] ?? []),
'webUpdaterEnabled' => !$this->config->getSystemValue('upgrade.disable-web', false),
'updaterEnabled' => empty($updateState['updaterEnabled']) ? false : $updateState['updaterEnabled'], 'updaterEnabled' => empty($updateState['updaterEnabled']) ? false : $updateState['updaterEnabled'],
'versionIsEol' => empty($updateState['versionIsEol']) ? false : $updateState['versionIsEol'], 'versionIsEol' => empty($updateState['versionIsEol']) ? false : $updateState['versionIsEol'],
'isDefaultUpdateServerURL' => $isDefaultUpdateServerURL, 'isDefaultUpdateServerURL' => $isDefaultUpdateServerURL,

View File

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

View File

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

View File

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