@@ -1,5 +1,5 @@  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | -declare(strict_types=1);  | 
                                                        |
| 2 | +declare(strict_types = 1);  | 
                                                        |
| 3 | 3 | /**  | 
                                                        
| 4 | 4 | * @copyright (c) 2018 Joas Schilling <[email protected]>  | 
                                                        
| 5 | 5 | *  | 
                                                        
@@ -32,53 +32,53 @@  | 
                                                    ||
| 32 | 32 | use OCP\Util;  | 
                                                        
| 33 | 33 | |
| 34 | 34 |  class Application extends App { | 
                                                        
| 35 | -	public function __construct() { | 
                                                        |
| 36 | -		parent::__construct('updatenotification', []); | 
                                                        |
| 37 | - }  | 
                                                        |
| 35 | +    public function __construct() { | 
                                                        |
| 36 | +        parent::__construct('updatenotification', []); | 
                                                        |
| 37 | + }  | 
                                                        |
| 38 | 38 | |
| 39 | -	public function register() { | 
                                                        |
| 40 | - $server = $this->getContainer()->getServer();  | 
                                                        |
| 39 | +    public function register() { | 
                                                        |
| 40 | + $server = $this->getContainer()->getServer();  | 
                                                        |
| 41 | 41 | |
| 42 | -		if ($server->getConfig()->getSystemValue('updatechecker', true) !== true) { | 
                                                        |
| 43 | - // Updater check is disabled  | 
                                                        |
| 44 | - return;  | 
                                                        |
| 45 | - }  | 
                                                        |
| 42 | +        if ($server->getConfig()->getSystemValue('updatechecker', true) !== true) { | 
                                                        |
| 43 | + // Updater check is disabled  | 
                                                        |
| 44 | + return;  | 
                                                        |
| 45 | + }  | 
                                                        |
| 46 | 46 | |
| 47 | - $user = $server->getUserSession()->getUser();  | 
                                                        |
| 48 | -		if (!$user instanceof IUser) { | 
                                                        |
| 49 | - // Nothing to do for guests  | 
                                                        |
| 50 | - return;  | 
                                                        |
| 51 | - }  | 
                                                        |
| 47 | + $user = $server->getUserSession()->getUser();  | 
                                                        |
| 48 | +        if (!$user instanceof IUser) { | 
                                                        |
| 49 | + // Nothing to do for guests  | 
                                                        |
| 50 | + return;  | 
                                                        |
| 51 | + }  | 
                                                        |
| 52 | 52 | |
| 53 | -		if ($server->getAppManager()->isEnabledForUser('notifications')) { | 
                                                        |
| 54 | - // Notifications app is available, so we register.  | 
                                                        |
| 55 | - // Since notifications also work for non-admins we don't check this here.  | 
                                                        |
| 56 | - $this->registerNotifier();  | 
                                                        |
| 57 | -		} else if ($server->getGroupManager()->isAdmin($user->getUID())) { | 
                                                        |
| 58 | -			try { | 
                                                        |
| 59 | - $updateChecker = $this->getContainer()->query(UpdateChecker::class);  | 
                                                        |
| 60 | -			} catch (QueryException $e) { | 
                                                        |
| 61 | - $server->getLogger()->logException($e);  | 
                                                        |
| 62 | - return;  | 
                                                        |
| 63 | - }  | 
                                                        |
| 53 | +        if ($server->getAppManager()->isEnabledForUser('notifications')) { | 
                                                        |
| 54 | + // Notifications app is available, so we register.  | 
                                                        |
| 55 | + // Since notifications also work for non-admins we don't check this here.  | 
                                                        |
| 56 | + $this->registerNotifier();  | 
                                                        |
| 57 | +        } else if ($server->getGroupManager()->isAdmin($user->getUID())) { | 
                                                        |
| 58 | +            try { | 
                                                        |
| 59 | + $updateChecker = $this->getContainer()->query(UpdateChecker::class);  | 
                                                        |
| 60 | +            } catch (QueryException $e) { | 
                                                        |
| 61 | + $server->getLogger()->logException($e);  | 
                                                        |
| 62 | + return;  | 
                                                        |
| 63 | + }  | 
                                                        |
| 64 | 64 | |
| 65 | -			if ($updateChecker->getUpdateState() !== []) { | 
                                                        |
| 66 | -				Util::addScript('updatenotification', 'legacy-notification'); | 
                                                        |
| 67 | -				\OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables'); | 
                                                        |
| 68 | - }  | 
                                                        |
| 69 | - }  | 
                                                        |
| 70 | - }  | 
                                                        |
| 65 | +            if ($updateChecker->getUpdateState() !== []) { | 
                                                        |
| 66 | +                Util::addScript('updatenotification', 'legacy-notification'); | 
                                                        |
| 67 | +                \OC_Hook::connect('\OCP\Config', 'js', $updateChecker, 'populateJavaScriptVariables'); | 
                                                        |
| 68 | + }  | 
                                                        |
| 69 | + }  | 
                                                        |
| 70 | + }  | 
                                                        |
| 71 | 71 | |
| 72 | -	public function registerNotifier() { | 
                                                        |
| 73 | - $notificationsManager = $this->getContainer()->getServer()->getNotificationManager();  | 
                                                        |
| 74 | -		$notificationsManager->registerNotifier(function() { | 
                                                        |
| 75 | - return $this->getContainer()->query(Notifier::class);  | 
                                                        |
| 76 | -		}, function() { | 
                                                        |
| 77 | -			$l = $this->getContainer()->getServer()->getL10N('updatenotification'); | 
                                                        |
| 78 | - return [  | 
                                                        |
| 79 | - 'id' => 'updatenotification',  | 
                                                        |
| 80 | -				'name' => $l->t('Update notifications'), | 
                                                        |
| 81 | - ];  | 
                                                        |
| 82 | - });  | 
                                                        |
| 83 | - }  | 
                                                        |
| 72 | +    public function registerNotifier() { | 
                                                        |
| 73 | + $notificationsManager = $this->getContainer()->getServer()->getNotificationManager();  | 
                                                        |
| 74 | +        $notificationsManager->registerNotifier(function() { | 
                                                        |
| 75 | + return $this->getContainer()->query(Notifier::class);  | 
                                                        |
| 76 | +        }, function() { | 
                                                        |
| 77 | +            $l = $this->getContainer()->getServer()->getL10N('updatenotification'); | 
                                                        |
| 78 | + return [  | 
                                                        |
| 79 | + 'id' => 'updatenotification',  | 
                                                        |
| 80 | +                'name' => $l->t('Update notifications'), | 
                                                        |
| 81 | + ];  | 
                                                        |
| 82 | + });  | 
                                                        |
| 83 | + }  | 
                                                        |
| 84 | 84 | }  | 
                                                        
@@ -1,5 +1,5 @@  | 
                                                    ||
| 1 | 1 | <?php  | 
                                                        
| 2 | -declare(strict_types=1);  | 
                                                        |
| 2 | +declare(strict_types = 1);  | 
                                                        |
| 3 | 3 | /**  | 
                                                        
| 4 | 4 | * @copyright Copyright (c) 2016, ownCloud, Inc.  | 
                                                        
| 5 | 5 | *  | 
                                                        
@@ -35,111 +35,111 @@  | 
                                                    ||
| 35 | 35 | use OCP\Util;  | 
                                                        
| 36 | 36 | |
| 37 | 37 |  class Admin implements ISettings { | 
                                                        
| 38 | - /** @var IConfig */  | 
                                                        |
| 39 | - private $config;  | 
                                                        |
| 40 | - /** @var UpdateChecker */  | 
                                                        |
| 41 | - private $updateChecker;  | 
                                                        |
| 42 | - /** @var IGroupManager */  | 
                                                        |
| 43 | - private $groupManager;  | 
                                                        |
| 44 | - /** @var IDateTimeFormatter */  | 
                                                        |
| 45 | - private $dateTimeFormatter;  | 
                                                        |
| 46 | -  | 
                                                        |
| 47 | - /**  | 
                                                        |
| 48 | - * @param IConfig $config  | 
                                                        |
| 49 | - * @param UpdateChecker $updateChecker  | 
                                                        |
| 50 | - * @param IGroupManager $groupManager  | 
                                                        |
| 51 | - * @param IDateTimeFormatter $dateTimeFormatter  | 
                                                        |
| 52 | - */  | 
                                                        |
| 53 | - public function __construct(IConfig $config,  | 
                                                        |
| 54 | - UpdateChecker $updateChecker,  | 
                                                        |
| 55 | - IGroupManager $groupManager,  | 
                                                        |
| 56 | -								IDateTimeFormatter $dateTimeFormatter) { | 
                                                        |
| 57 | - $this->config = $config;  | 
                                                        |
| 58 | - $this->updateChecker = $updateChecker;  | 
                                                        |
| 59 | - $this->groupManager = $groupManager;  | 
                                                        |
| 60 | - $this->dateTimeFormatter = $dateTimeFormatter;  | 
                                                        |
| 61 | - }  | 
                                                        |
| 62 | -  | 
                                                        |
| 63 | - /**  | 
                                                        |
| 64 | - * @return TemplateResponse  | 
                                                        |
| 65 | - */  | 
                                                        |
| 66 | -	public function getForm(): TemplateResponse { | 
                                                        |
| 67 | -		$lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat'); | 
                                                        |
| 68 | - $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);  | 
                                                        |
| 69 | -  | 
                                                        |
| 70 | - $channels = [  | 
                                                        |
| 71 | - 'daily',  | 
                                                        |
| 72 | - 'beta',  | 
                                                        |
| 73 | - 'stable',  | 
                                                        |
| 74 | - 'production',  | 
                                                        |
| 75 | - ];  | 
                                                        |
| 76 | - $currentChannel = Util::getChannel();  | 
                                                        |
| 77 | -		if ($currentChannel === 'git') { | 
                                                        |
| 78 | - $channels[] = 'git';  | 
                                                        |
| 79 | - }  | 
                                                        |
| 80 | -  | 
                                                        |
| 81 | - $updateState = $this->updateChecker->getUpdateState();  | 
                                                        |
| 82 | -  | 
                                                        |
| 83 | -		$notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); | 
                                                        |
| 84 | -  | 
                                                        |
| 85 | - $defaultUpdateServerURL = 'https://updates.nextcloud.com/updater_server/';  | 
                                                        |
| 86 | -		$updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL); | 
                                                        |
| 87 | -  | 
                                                        |
| 88 | - $params = [  | 
                                                        |
| 89 | - 'isNewVersionAvailable' => !empty($updateState['updateAvailable']),  | 
                                                        |
| 90 | - 'isUpdateChecked' => $lastUpdateCheckTimestamp > 0,  | 
                                                        |
| 91 | - 'lastChecked' => $lastUpdateCheck,  | 
                                                        |
| 92 | - 'currentChannel' => $currentChannel,  | 
                                                        |
| 93 | - 'channels' => $channels,  | 
                                                        |
| 94 | - 'newVersionString' => empty($updateState['updateVersion']) ? '' : $updateState['updateVersion'],  | 
                                                        |
| 95 | - 'downloadLink' => empty($updateState['downloadLink']) ? '' : $updateState['downloadLink'],  | 
                                                        |
| 96 | - 'updaterEnabled' => empty($updateState['updaterEnabled']) ? false : $updateState['updaterEnabled'],  | 
                                                        |
| 97 | - 'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL,  | 
                                                        |
| 98 | - 'updateServerURL' => $updateServerURL,  | 
                                                        |
| 99 | - 'notifyGroups' => $this->getSelectedGroups($notifyGroups),  | 
                                                        |
| 100 | - ];  | 
                                                        |
| 101 | -  | 
                                                        |
| 102 | - $params = [  | 
                                                        |
| 103 | - 'json' => json_encode($params),  | 
                                                        |
| 104 | - ];  | 
                                                        |
| 105 | -  | 
                                                        |
| 106 | -		return new TemplateResponse('updatenotification', 'admin', $params, ''); | 
                                                        |
| 107 | - }  | 
                                                        |
| 108 | -  | 
                                                        |
| 109 | - /**  | 
                                                        |
| 110 | - * @param array $groupIds  | 
                                                        |
| 111 | - * @return array  | 
                                                        |
| 112 | - */  | 
                                                        |
| 113 | -	protected function getSelectedGroups(array $groupIds): array { | 
                                                        |
| 114 | - $result = [];  | 
                                                        |
| 115 | -		foreach ($groupIds as $groupId) { | 
                                                        |
| 116 | - $group = $this->groupManager->get($groupId);  | 
                                                        |
| 117 | -  | 
                                                        |
| 118 | -			if ($group === null) { | 
                                                        |
| 119 | - continue;  | 
                                                        |
| 120 | - }  | 
                                                        |
| 121 | -  | 
                                                        |
| 122 | - $result[] = ['value' => $group->getGID(), 'label' => $group->getDisplayName()];  | 
                                                        |
| 123 | - }  | 
                                                        |
| 124 | -  | 
                                                        |
| 125 | - return $result;  | 
                                                        |
| 126 | - }  | 
                                                        |
| 127 | -  | 
                                                        |
| 128 | - /**  | 
                                                        |
| 129 | - * @return string the section ID, e.g. 'sharing'  | 
                                                        |
| 130 | - */  | 
                                                        |
| 131 | -	public function getSection(): string { | 
                                                        |
| 132 | - return 'server';  | 
                                                        |
| 133 | - }  | 
                                                        |
| 134 | -  | 
                                                        |
| 135 | - /**  | 
                                                        |
| 136 | - * @return int whether the form should be rather on the top or bottom of  | 
                                                        |
| 137 | - * the admin section. The forms are arranged in ascending order of the  | 
                                                        |
| 138 | - * priority values. It is required to return a value between 0 and 100.  | 
                                                        |
| 139 | - *  | 
                                                        |
| 140 | - * E.g.: 70  | 
                                                        |
| 141 | - */  | 
                                                        |
| 142 | -	public function getPriority(): int { | 
                                                        |
| 143 | - return 1;  | 
                                                        |
| 144 | - }  | 
                                                        |
| 38 | + /** @var IConfig */  | 
                                                        |
| 39 | + private $config;  | 
                                                        |
| 40 | + /** @var UpdateChecker */  | 
                                                        |
| 41 | + private $updateChecker;  | 
                                                        |
| 42 | + /** @var IGroupManager */  | 
                                                        |
| 43 | + private $groupManager;  | 
                                                        |
| 44 | + /** @var IDateTimeFormatter */  | 
                                                        |
| 45 | + private $dateTimeFormatter;  | 
                                                        |
| 46 | +  | 
                                                        |
| 47 | + /**  | 
                                                        |
| 48 | + * @param IConfig $config  | 
                                                        |
| 49 | + * @param UpdateChecker $updateChecker  | 
                                                        |
| 50 | + * @param IGroupManager $groupManager  | 
                                                        |
| 51 | + * @param IDateTimeFormatter $dateTimeFormatter  | 
                                                        |
| 52 | + */  | 
                                                        |
| 53 | + public function __construct(IConfig $config,  | 
                                                        |
| 54 | + UpdateChecker $updateChecker,  | 
                                                        |
| 55 | + IGroupManager $groupManager,  | 
                                                        |
| 56 | +                                IDateTimeFormatter $dateTimeFormatter) { | 
                                                        |
| 57 | + $this->config = $config;  | 
                                                        |
| 58 | + $this->updateChecker = $updateChecker;  | 
                                                        |
| 59 | + $this->groupManager = $groupManager;  | 
                                                        |
| 60 | + $this->dateTimeFormatter = $dateTimeFormatter;  | 
                                                        |
| 61 | + }  | 
                                                        |
| 62 | +  | 
                                                        |
| 63 | + /**  | 
                                                        |
| 64 | + * @return TemplateResponse  | 
                                                        |
| 65 | + */  | 
                                                        |
| 66 | +    public function getForm(): TemplateResponse { | 
                                                        |
| 67 | +        $lastUpdateCheckTimestamp = $this->config->getAppValue('core', 'lastupdatedat'); | 
                                                        |
| 68 | + $lastUpdateCheck = $this->dateTimeFormatter->formatDateTime($lastUpdateCheckTimestamp);  | 
                                                        |
| 69 | +  | 
                                                        |
| 70 | + $channels = [  | 
                                                        |
| 71 | + 'daily',  | 
                                                        |
| 72 | + 'beta',  | 
                                                        |
| 73 | + 'stable',  | 
                                                        |
| 74 | + 'production',  | 
                                                        |
| 75 | + ];  | 
                                                        |
| 76 | + $currentChannel = Util::getChannel();  | 
                                                        |
| 77 | +        if ($currentChannel === 'git') { | 
                                                        |
| 78 | + $channels[] = 'git';  | 
                                                        |
| 79 | + }  | 
                                                        |
| 80 | +  | 
                                                        |
| 81 | + $updateState = $this->updateChecker->getUpdateState();  | 
                                                        |
| 82 | +  | 
                                                        |
| 83 | +        $notifyGroups = json_decode($this->config->getAppValue('updatenotification', 'notify_groups', '["admin"]'), true); | 
                                                        |
| 84 | +  | 
                                                        |
| 85 | + $defaultUpdateServerURL = 'https://updates.nextcloud.com/updater_server/';  | 
                                                        |
| 86 | +        $updateServerURL = $this->config->getSystemValue('updater.server.url', $defaultUpdateServerURL); | 
                                                        |
| 87 | +  | 
                                                        |
| 88 | + $params = [  | 
                                                        |
| 89 | + 'isNewVersionAvailable' => !empty($updateState['updateAvailable']),  | 
                                                        |
| 90 | + 'isUpdateChecked' => $lastUpdateCheckTimestamp > 0,  | 
                                                        |
| 91 | + 'lastChecked' => $lastUpdateCheck,  | 
                                                        |
| 92 | + 'currentChannel' => $currentChannel,  | 
                                                        |
| 93 | + 'channels' => $channels,  | 
                                                        |
| 94 | + 'newVersionString' => empty($updateState['updateVersion']) ? '' : $updateState['updateVersion'],  | 
                                                        |
| 95 | + 'downloadLink' => empty($updateState['downloadLink']) ? '' : $updateState['downloadLink'],  | 
                                                        |
| 96 | + 'updaterEnabled' => empty($updateState['updaterEnabled']) ? false : $updateState['updaterEnabled'],  | 
                                                        |
| 97 | + 'isDefaultUpdateServerURL' => $updateServerURL === $defaultUpdateServerURL,  | 
                                                        |
| 98 | + 'updateServerURL' => $updateServerURL,  | 
                                                        |
| 99 | + 'notifyGroups' => $this->getSelectedGroups($notifyGroups),  | 
                                                        |
| 100 | + ];  | 
                                                        |
| 101 | +  | 
                                                        |
| 102 | + $params = [  | 
                                                        |
| 103 | + 'json' => json_encode($params),  | 
                                                        |
| 104 | + ];  | 
                                                        |
| 105 | +  | 
                                                        |
| 106 | +        return new TemplateResponse('updatenotification', 'admin', $params, ''); | 
                                                        |
| 107 | + }  | 
                                                        |
| 108 | +  | 
                                                        |
| 109 | + /**  | 
                                                        |
| 110 | + * @param array $groupIds  | 
                                                        |
| 111 | + * @return array  | 
                                                        |
| 112 | + */  | 
                                                        |
| 113 | +    protected function getSelectedGroups(array $groupIds): array { | 
                                                        |
| 114 | + $result = [];  | 
                                                        |
| 115 | +        foreach ($groupIds as $groupId) { | 
                                                        |
| 116 | + $group = $this->groupManager->get($groupId);  | 
                                                        |
| 117 | +  | 
                                                        |
| 118 | +            if ($group === null) { | 
                                                        |
| 119 | + continue;  | 
                                                        |
| 120 | + }  | 
                                                        |
| 121 | +  | 
                                                        |
| 122 | + $result[] = ['value' => $group->getGID(), 'label' => $group->getDisplayName()];  | 
                                                        |
| 123 | + }  | 
                                                        |
| 124 | +  | 
                                                        |
| 125 | + return $result;  | 
                                                        |
| 126 | + }  | 
                                                        |
| 127 | +  | 
                                                        |
| 128 | + /**  | 
                                                        |
| 129 | + * @return string the section ID, e.g. 'sharing'  | 
                                                        |
| 130 | + */  | 
                                                        |
| 131 | +    public function getSection(): string { | 
                                                        |
| 132 | + return 'server';  | 
                                                        |
| 133 | + }  | 
                                                        |
| 134 | +  | 
                                                        |
| 135 | + /**  | 
                                                        |
| 136 | + * @return int whether the form should be rather on the top or bottom of  | 
                                                        |
| 137 | + * the admin section. The forms are arranged in ascending order of the  | 
                                                        |
| 138 | + * priority values. It is required to return a value between 0 and 100.  | 
                                                        |
| 139 | + *  | 
                                                        |
| 140 | + * E.g.: 70  | 
                                                        |
| 141 | + */  | 
                                                        |
| 142 | +    public function getPriority(): int { | 
                                                        |
| 143 | + return 1;  | 
                                                        |
| 144 | + }  | 
                                                        |
| 145 | 145 | }  |