From 315645ada343946aa3c27f874b36b7ded6b3ff50 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 9 Jan 2017 11:24:09 +0100 Subject: [PATCH] Only add the link when the user can follow it. Signed-off-by: Joas Schilling --- .../lib/Notification/Notifier.php | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/apps/updatenotification/lib/Notification/Notifier.php b/apps/updatenotification/lib/Notification/Notifier.php index b23b7fe84d..079ec4c5e0 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()); }