Only add the link when the user can follow it.

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2017-01-09 11:24:09 +01:00
parent acbf0d151f
commit 315645ada3
No known key found for this signature in database
GPG key ID: E166FD8976B3BAC8

View file

@ -24,7 +24,10 @@
namespace OCA\UpdateNotification\Notification; namespace OCA\UpdateNotification\Notification;
use OCP\IGroupManager;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
use OCP\L10N\IFactory; use OCP\L10N\IFactory;
use OCP\Notification\IManager; use OCP\Notification\IManager;
use OCP\Notification\INotification; use OCP\Notification\INotification;
@ -41,6 +44,12 @@ class Notifier implements INotifier {
/** @var IFactory */ /** @var IFactory */
protected $l10NFactory; protected $l10NFactory;
/** @var IUserSession */
protected $userSession;
/** @var IGroupManager */
protected $groupManager;
/** @var string[] */ /** @var string[] */
protected $appVersions; protected $appVersions;
@ -50,11 +59,15 @@ class Notifier implements INotifier {
* @param IURLGenerator $url * @param IURLGenerator $url
* @param IManager $notificationManager * @param IManager $notificationManager
* @param IFactory $l10NFactory * @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->url = $url;
$this->notificationManager = $notificationManager; $this->notificationManager = $notificationManager;
$this->l10NFactory = $l10NFactory; $this->l10NFactory = $l10NFactory;
$this->userSession = $userSession;
$this->groupManager = $groupManager;
$this->appVersions = $this->getAppVersions(); $this->appVersions = $this->getAppVersions();
} }
@ -76,7 +89,10 @@ class Notifier implements INotifier {
$parameters = $notification->getSubjectParameters(); $parameters = $notification->getSubjectParameters();
$notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']])); $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 { } else {
$appInfo = $this->getAppInfo($notification->getObjectType()); $appInfo = $this->getAppInfo($notification->getObjectType());
$appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name']; $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'))); $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() { protected function getCoreVersions() {
return implode('.', \OCP\Util::getVersion()); return implode('.', \OCP\Util::getVersion());
} }