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;
/** @var IFactory */
protected $l10NFactory;
+ /** @var IUserSession */
+ protected $userSession;
+
+ /** @var IGroupManager */
+ protected $groupManager;
+
/** @var string[] */
protected $appVersions;
* @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();
}
$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'];
]
]);
- $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')));
}
}
+ /**
+ * @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());
}