2018-01-15 14:06:03 +03:00
|
|
|
<?php
|
2019-12-03 21:57:53 +03:00
|
|
|
|
2018-01-17 15:42:02 +03:00
|
|
|
declare(strict_types=1);
|
2019-12-03 21:57:53 +03:00
|
|
|
|
2018-01-15 14:06:03 +03:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2018-01-15 14:06:03 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2018-01-15 14:06:03 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2018-01-15 14:06:03 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\UpdateNotification\Settings;
|
|
|
|
|
|
|
|
use OCA\UpdateNotification\UpdateChecker;
|
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\IDateTimeFormatter;
|
2018-01-31 12:54:22 +03:00
|
|
|
use OCP\IGroupManager;
|
2018-06-26 18:25:37 +03:00
|
|
|
use OCP\L10N\IFactory;
|
2018-01-15 14:06:03 +03:00
|
|
|
use OCP\Settings\ISettings;
|
2019-05-13 15:11:07 +03:00
|
|
|
use OCP\Support\Subscription\IRegistry;
|
2018-01-15 14:06:03 +03:00
|
|
|
use OCP\Util;
|
|
|
|
|
|
|
|
class Admin implements ISettings {
|
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
|
|
|
/** @var UpdateChecker */
|
|
|
|
private $updateChecker;
|
2018-01-31 12:54:22 +03:00
|
|
|
/** @var IGroupManager */
|
|
|
|
private $groupManager;
|
2018-01-15 14:06:03 +03:00
|
|
|
/** @var IDateTimeFormatter */
|
|
|
|
private $dateTimeFormatter;
|
2018-06-26 18:25:37 +03:00
|
|
|
/** @var IFactory */
|
|
|
|
private $l10nFactory;
|
2019-05-13 15:11:07 +03:00
|
|
|
/** @var IRegistry */
|
|
|
|
private $subscriptionRegistry;
|
2018-06-26 18:25:37 +03:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
IConfig $config,
|
|
|
|
UpdateChecker $updateChecker,
|
|
|
|
IGroupManager $groupManager,
|
|
|
|
IDateTimeFormatter $dateTimeFormatter,
|
2019-05-13 15:11:07 +03:00
|
|
|
IFactory $l10nFactory,
|
|
|
|
IRegistry $subscriptionRegistry
|
2018-06-26 18:25:37 +03:00
|
|
|
) {
|
2018-01-15 14:06:03 +03:00
|
|
|
$this->config = $config;
|
|
|
|
$this->updateChecker = $updateChecker;
|
2018-01-31 12:54:22 +03:00
|
|
|
$this->groupManager = $groupManager;
|
2018-01-15 14:06:03 +03:00
|
|
|
$this->dateTimeFormatter = $dateTimeFormatter;
|
2018-06-26 18:25:37 +03:00
|
|
|
$this->l10nFactory = $l10nFactory;
|
2019-05-13 15:11:07 +03:00
|
|
|
$this->subscriptionRegistry = $subscriptionRegistry;
|
2018-01-15 14:06:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return TemplateResponse
|
|
|
|
*/
|
2018-01-17 15:42:02 +03:00
|
|
|
public function getForm(): TemplateResponse {
|
2018-01-15 14:06:03 +03:00
|
|
|
$lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat');
|
|
|
|
$lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);
|
|
|
|
|
|
|
|
$channels = [
|
|
|
|
'daily',
|
|
|
|
'beta',
|
|
|
|
'stable',
|
|
|
|
'production',
|
|
|
|
];
|
|
|
|
$currentChannel = Util::getChannel();
|
2018-01-18 14:25:52 +03:00
|
|
|
if ($currentChannel === 'git') {
|
|
|
|
$channels[] = 'git';
|
2018-01-15 14:06:03 +03:00
|
|
|
}
|
2018-01-18 14:25:52 +03:00
|
|
|
|
2018-01-15 14:06:03 +03:00
|
|
|
$updateState = $this->updateChecker->getUpdateState();
|
|
|
|
|
|
|
|
$notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true);
|
|
|
|
|
2018-02-01 15:22:36 +03:00
|
|
|
$defaultUpdateServerURL = 'https://updates.nextcloud.com/updater_server/';
|
2018-01-15 14:06:03 +03:00
|
|
|
$updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL);
|
2019-05-13 15:11:07 +03:00
|
|
|
$defaultCustomerUpdateServerURLPrefix = 'https://updates.nextcloud.com/customers/';
|
|
|
|
|
|
|
|
$isDefaultUpdateServerURL = $updateServerURL === $defaultUpdateServerURL
|
2020-04-24 19:00:49 +03:00
|
|
|
|| strpos($updateServerURL, $defaultCustomerUpdateServerURLPrefix) === 0;
|
2019-05-13 15:11:07 +03:00
|
|
|
|
|
|
|
$hasValidSubscription = $this->subscriptionRegistry->delegateHasValidSubscription();
|
2018-01-15 14:06:03 +03:00
|
|
|
|
|
|
|
$params = [
|
|
|
|
'isNewVersionAvailable' => !empty($updateState['updateAvailable']),
|
|
|
|
'isUpdateChecked' => $lastUpdateCheckTimestamp > 0,
|
|
|
|
'lastChecked' => $lastUpdateCheck,
|
|
|
|
'currentChannel' => $currentChannel,
|
|
|
|
'channels' => $channels,
|
2018-11-08 16:50:12 +03:00
|
|
|
'newVersion' => empty($updateState['updateVersion']) ? '' : $updateState['updateVersion'],
|
|
|
|
'newVersionString' => empty($updateState['updateVersionString']) ? '' : $updateState['updateVersionString'],
|
2018-01-15 14:06:03 +03:00
|
|
|
'downloadLink' => empty($updateState['downloadLink']) ? '' : $updateState['downloadLink'],
|
2018-06-26 18:25:37 +03:00
|
|
|
'changes' => $this->filterChanges($updateState['changes'] ?? []),
|
2018-01-15 14:06:03 +03:00
|
|
|
'updaterEnabled' => empty($updateState['updaterEnabled']) ? false : $updateState['updaterEnabled'],
|
2018-03-14 16:21:49 +03:00
|
|
|
'versionIsEol' => empty($updateState['versionIsEol']) ? false : $updateState['versionIsEol'],
|
2019-05-13 15:11:07 +03:00
|
|
|
'isDefaultUpdateServerURL' => $isDefaultUpdateServerURL,
|
2018-01-15 14:06:03 +03:00
|
|
|
'updateServerURL' => $updateServerURL,
|
2018-01-31 12:54:22 +03:00
|
|
|
'notifyGroups' => $this->getSelectedGroups($notifyGroups),
|
2019-05-13 15:11:07 +03:00
|
|
|
'hasValidSubscription' => $hasValidSubscription,
|
2018-01-18 14:25:52 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
$params = [
|
|
|
|
'json' => json_encode($params),
|
2018-01-15 14:06:03 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
return new TemplateResponse('updatenotification', 'admin', $params, '');
|
|
|
|
}
|
|
|
|
|
2018-08-16 14:20:49 +03:00
|
|
|
protected function filterChanges(array $changes): array {
|
2018-06-26 18:25:37 +03:00
|
|
|
$filtered = [];
|
2020-04-10 15:19:56 +03:00
|
|
|
if (isset($changes['changelogURL'])) {
|
2018-06-26 18:25:37 +03:00
|
|
|
$filtered['changelogURL'] = $changes['changelogURL'];
|
|
|
|
}
|
2020-04-10 15:19:56 +03:00
|
|
|
if (!isset($changes['whatsNew'])) {
|
2018-06-26 18:25:37 +03:00
|
|
|
return $filtered;
|
|
|
|
}
|
|
|
|
|
2018-07-05 01:41:59 +03:00
|
|
|
$iterator = $this->l10nFactory->getLanguageIterator();
|
2018-06-26 18:25:37 +03:00
|
|
|
do {
|
2018-07-05 01:41:59 +03:00
|
|
|
$lang = $iterator->current();
|
2020-04-10 15:19:56 +03:00
|
|
|
if (isset($changes['whatsNew'][$lang])) {
|
2018-08-16 13:50:44 +03:00
|
|
|
$filtered['whatsNew'] = $changes['whatsNew'][$lang];
|
|
|
|
return $filtered;
|
2018-06-26 18:25:37 +03:00
|
|
|
}
|
2018-07-05 01:41:59 +03:00
|
|
|
$iterator->next();
|
2020-04-10 15:19:56 +03:00
|
|
|
} while ($lang !== 'en' && $iterator->valid());
|
2018-06-26 18:25:37 +03:00
|
|
|
|
|
|
|
return $filtered;
|
|
|
|
}
|
|
|
|
|
2018-01-31 12:54:22 +03:00
|
|
|
/**
|
|
|
|
* @param array $groupIds
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function getSelectedGroups(array $groupIds): array {
|
|
|
|
$result = [];
|
|
|
|
foreach ($groupIds as $groupId) {
|
|
|
|
$group = $this->groupManager->get($groupId);
|
|
|
|
|
|
|
|
if ($group === null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result[] = ['value' => $group->getGID(), 'label' => $group->getDisplayName()];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2018-01-15 14:06:03 +03:00
|
|
|
/**
|
|
|
|
* @return string the section ID, e.g. 'sharing'
|
|
|
|
*/
|
2018-01-17 15:42:02 +03:00
|
|
|
public function getSection(): string {
|
2018-04-19 21:10:29 +03:00
|
|
|
return 'overview';
|
2018-01-15 14:06:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int whether the form should be rather on the top or bottom of
|
|
|
|
* the admin section. The forms are arranged in ascending order of the
|
|
|
|
* priority values. It is required to return a value between 0 and 100.
|
|
|
|
*
|
|
|
|
* E.g.: 70
|
|
|
|
*/
|
2018-01-17 15:42:02 +03:00
|
|
|
public function getPriority(): int {
|
2018-04-19 21:10:29 +03:00
|
|
|
return 11;
|
2018-01-15 14:06:03 +03:00
|
|
|
}
|
|
|
|
}
|