From fc0f21089cf62fb550a81c2be9e0fd4d3d1918f4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 11 Sep 2019 11:36:29 +0200 Subject: [PATCH 1/3] Allow to directly disable the nextcloud announcements from the notification Signed-off-by: Joas Schilling --- lib/Notification/Notifier.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 4391836d..171be2df 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -24,6 +24,7 @@ namespace OCA\NextcloudAnnouncements\Notification; +use OCP\IGroupManager; use OCP\IURLGenerator; use OCP\L10N\IFactory; use OCP\Notification\INotification; @@ -35,22 +36,21 @@ class Notifier implements INotifier { /** @var string */ protected $appName; - /** @var IFactory */ protected $l10nFactory; - /** @var IURLGenerator */ protected $url; + /** @var IGroupManager */ + protected $groupManager; - /** - * @param string $appName - * @param IFactory $l10nFactory - * @param IURLGenerator $url - */ - public function __construct($appName, IFactory $l10nFactory, IURLGenerator $url) { + public function __construct(string $appName, + IFactory $l10nFactory, + IURLGenerator $url, + IGroupManager $groupManager) { $this->appName = $appName; $this->l10nFactory = $l10nFactory; $this->url = $url; + $this->groupManager = $groupManager; } /** @@ -75,6 +75,15 @@ public function prepare(INotification $notification, $languageCode) { ->setParsedMessage($parameters[0]) ->setIcon($this->url->getAbsoluteURL($this->url->imagePath($this->appName, 'app-dark.svg'))); + $isAdmin = $this->groupManager->isAdmin($notification->getUser()); + if ($isAdmin) { + $action = $notification->createAction(); + $action->setParsedLabel($l->t('Disable announcements')) + ->setLink($this->url->linkToOCSRouteAbsolute('provisioning_api.AppsController.disable', ['app' => 'nextcloud_announcements']), 'DELETE') + ->setPrimary(false); + $notification->addParsedAction($action); + } + return $notification; default: From 9bef9787083ba2ff649ab0e566fd3fabbead9fee Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 11 Sep 2019 11:37:44 +0200 Subject: [PATCH 2/3] Add a note that the announcements are only shown to administrators by default Signed-off-by: Joas Schilling --- lib/Notification/Notifier.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 171be2df..940a0086 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -24,6 +24,7 @@ namespace OCA\NextcloudAnnouncements\Notification; +use OCP\IConfig; use OCP\IGroupManager; use OCP\IURLGenerator; use OCP\L10N\IFactory; @@ -40,16 +41,20 @@ class Notifier implements INotifier { protected $l10nFactory; /** @var IURLGenerator */ protected $url; + /** @var IConfig */ + protected $config; /** @var IGroupManager */ protected $groupManager; public function __construct(string $appName, IFactory $l10nFactory, IURLGenerator $url, + IConfig $config, IGroupManager $groupManager) { $this->appName = $appName; $this->l10nFactory = $l10nFactory; $this->url = $url; + $this->config = $config; $this->groupManager = $groupManager; } @@ -71,8 +76,8 @@ public function prepare(INotification $notification, $languageCode) { switch ($notification->getSubject()) { case self::SUBJECT: $parameters = $notification->getSubjectParameters(); + $message = $parameters[0]; $notification->setParsedSubject($l->t('Nextcloud announcement')) - ->setParsedMessage($parameters[0]) ->setIcon($this->url->getAbsoluteURL($this->url->imagePath($this->appName, 'app-dark.svg'))); $isAdmin = $this->groupManager->isAdmin($notification->getUser()); @@ -82,8 +87,15 @@ public function prepare(INotification $notification, $languageCode) { ->setLink($this->url->linkToOCSRouteAbsolute('provisioning_api.AppsController.disable', ['app' => 'nextcloud_announcements']), 'DELETE') ->setPrimary(false); $notification->addParsedAction($action); + + $groups = $this->config->getAppValue($this->appName, 'notification_groups', ''); + if ($groups === '') { + $message .= "\n\n" . $l->t('(These announcements are only shown to administrators)'); + } } + $notification->setParsedMessage($message); + return $notification; default: From d457f29118031a68c38632845dd2db8be4d87049 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 11 Sep 2019 11:53:16 +0200 Subject: [PATCH 3/3] Only show the uninstall button on default settings Signed-off-by: Joas Schilling --- lib/Notification/Notifier.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 940a0086..ed162ea3 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -82,14 +82,14 @@ public function prepare(INotification $notification, $languageCode) { $isAdmin = $this->groupManager->isAdmin($notification->getUser()); if ($isAdmin) { - $action = $notification->createAction(); - $action->setParsedLabel($l->t('Disable announcements')) - ->setLink($this->url->linkToOCSRouteAbsolute('provisioning_api.AppsController.disable', ['app' => 'nextcloud_announcements']), 'DELETE') - ->setPrimary(false); - $notification->addParsedAction($action); - $groups = $this->config->getAppValue($this->appName, 'notification_groups', ''); if ($groups === '') { + $action = $notification->createAction(); + $action->setParsedLabel($l->t('Disable announcements')) + ->setLink($this->url->linkToOCSRouteAbsolute('provisioning_api.AppsController.disable', ['app' => 'nextcloud_announcements']), 'DELETE') + ->setPrimary(false); + $notification->addParsedAction($action); + $message .= "\n\n" . $l->t('(These announcements are only shown to administrators)'); } }