diff options
author | Joas Schilling <coding@schilljs.com> | 2017-01-09 11:24:09 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2017-01-09 11:24:09 +0100 |
commit | 315645ada343946aa3c27f874b36b7ded6b3ff50 (patch) | |
tree | 58cfc7ea7725612974afdc8af9084fcfc91f2069 /apps | |
parent | acbf0d151ff4c720532b1befc0471b18457c337b (diff) | |
download | nextcloud-server-315645ada343946aa3c27f874b36b7ded6b3ff50.tar.gz nextcloud-server-315645ada343946aa3c27f874b36b7ded6b3ff50.zip |
Only add the link when the user can follow it.
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps')
-rw-r--r-- | apps/updatenotification/lib/Notification/Notifier.php | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/apps/updatenotification/lib/Notification/Notifier.php b/apps/updatenotification/lib/Notification/Notifier.php index b23b7fe84dd..079ec4c5e0a 100644 --- a/apps/updatenotification/lib/Notification/Notifier.php +++ b/apps/updatenotification/lib/Notification/Notifier.php @@ -24,7 +24,10 @@ namespace OCA\UpdateNotification\Notification; +use OCP\IGroupManager; use OCP\IURLGenerator; +use OCP\IUser; +use OCP\IUserSession; use OCP\L10N\IFactory; use OCP\Notification\IManager; use OCP\Notification\INotification; @@ -41,6 +44,12 @@ class Notifier implements INotifier { /** @var IFactory */ protected $l10NFactory; + /** @var IUserSession */ + protected $userSession; + + /** @var IGroupManager */ + protected $groupManager; + /** @var string[] */ protected $appVersions; @@ -50,11 +59,15 @@ class Notifier implements INotifier { * @param IURLGenerator $url * @param IManager $notificationManager * @param IFactory $l10NFactory + * @param IUserSession $userSession + * @param IGroupManager $groupManager */ - public function __construct(IURLGenerator $url, IManager $notificationManager, IFactory $l10NFactory) { + public function __construct(IURLGenerator $url, IManager $notificationManager, IFactory $l10NFactory, IUserSession $userSession, IGroupManager $groupManager) { $this->url = $url; $this->notificationManager = $notificationManager; $this->l10NFactory = $l10NFactory; + $this->userSession = $userSession; + $this->groupManager = $groupManager; $this->appVersions = $this->getAppVersions(); } @@ -76,7 +89,10 @@ class Notifier implements INotifier { $parameters = $notification->getSubjectParameters(); $notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']])); - $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index') . '#updater'); + + if ($this->isAdmin()) { + $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index') . '#updater'); + } } else { $appInfo = $this->getAppInfo($notification->getObjectType()); $appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name']; @@ -94,7 +110,9 @@ class Notifier implements INotifier { ] ]); - $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps') . '#app-' . $notification->getObjectType()); + if ($this->isAdmin()) { + $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps') . '#app-' . $notification->getObjectType()); + } } $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('updatenotification', 'notification.svg'))); @@ -116,6 +134,19 @@ class Notifier implements INotifier { } } + /** + * @return bool + */ + protected function isAdmin() { + $user = $this->userSession->getUser(); + + if ($user instanceof IUser) { + return $this->groupManager->isAdmin($user->getUID()); + } + + return false; + } + protected function getCoreVersions() { return implode('.', \OCP\Util::getVersion()); } |