From 56b59602ea4ff131d955b0486caaf007586e1e14 Mon Sep 17 00:00:00 2001 From: Samuelson Brito Date: Sat, 24 May 2025 22:46:47 -0400 Subject: [PATCH 1/4] feat: send notification to admins after LibreSign upgrade Signed-off-by: Samuelson Brito --- appinfo/info.xml | 1 + lib/Migration/NotifyAdminsAfterUpgrade.php | 39 ++++++++++++++++++++++ lib/Notification/Notifier.php | 14 ++++++++ 3 files changed, 54 insertions(+) create mode 100644 lib/Migration/NotifyAdminsAfterUpgrade.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 450928b9e4..66ace77001 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -60,6 +60,7 @@ Developed with ❤️ by [LibreCode](https://librecode.coop). Help us transform OCA\Libresign\Migration\DeleteOldBinaries OCA\Libresign\Migration\ResynchronizeDatabaseSequences + OCA\Libresign\Migration\NotifyAdminsAfterUpgrade diff --git a/lib/Migration/NotifyAdminsAfterUpgrade.php b/lib/Migration/NotifyAdminsAfterUpgrade.php new file mode 100644 index 0000000000..be3ecf5861 --- /dev/null +++ b/lib/Migration/NotifyAdminsAfterUpgrade.php @@ -0,0 +1,39 @@ +userManager->search('', 1, 0, ['admin']); + foreach ($admins as $admin) { + $notification = $this->notificationManager->createNotification(); + $notification + ->setApp(AppInfoApplication::APP_ID) + ->setUser($admin->getUID()) + ->setDateTime(new \DateTime()) + ->setObject('upgrade', '1') + ->setSubject('libresign_upgrade', [ + 'message' => 'LibreSign has been updated! Consider supporting the project: https://libresign.coop' + ]); + $this->notificationManager->notify($notification); + } + } +} diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 21ae213f64..5b67c4b980 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -52,6 +52,7 @@ public function prepare(INotification $notification, string $languageCode): INot 'new_sign_request' => $this->parseSignRequest($notification, $l, false), 'update_sign_request' => $this->parseSignRequest($notification, $l, true), 'file_signed' => $this->parseSigned($notification, $l), + 'libresign_upgrade' => $this->parseUpgrade($notification, $l), default => throw new UnknownNotificationException(), }; } @@ -206,4 +207,17 @@ private function parseSigned( return $notification; } + + private function parseUpgrade( + INotification $notification, + IL10N $l, + ): INotification { + $parameters = $notification->getSubjectParameters(); + $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg'))); + $subject = $l->t('LibreSign has been updated!'); + $message = $parameters['message'] ?? ''; + $notification->setParsedSubject($subject) + ->setParsedMessage($message); + return $notification; + } } From c204315f97dbeda68abef888eb60a056242c8357 Mon Sep 17 00:00:00 2001 From: Samuelson Brito Date: Sun, 25 May 2025 01:10:58 -0400 Subject: [PATCH 2/4] feat: add dismiss button Signed-off-by: Samuelson Brito --- lib/Notification/Notifier.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index 5b67c4b980..e1f0a910e9 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -212,12 +212,32 @@ private function parseUpgrade( INotification $notification, IL10N $l, ): INotification { + $parameters = $notification->getSubjectParameters(); $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg'))); $subject = $l->t('LibreSign has been updated!'); $message = $parameters['message'] ?? ''; $notification->setParsedSubject($subject) ->setParsedMessage($message); + + $dismissAction = $notification->createAction() + ->setParsedLabel($l->t('Dismiss notification')) + ->setPrimary(false) + ->setLink( + $this->url->linkToOCSRouteAbsolute( + 'libresign.notify.notificationDismiss', + [ + 'apiVersion' => 'v1', + 'timestamp' => $notification->getDateTime()->getTimestamp(), + 'objectType' => 'upgrade', + 'objectId' => '1', + 'subject' => 'libresign_upgrade', + ], + ), + IAction::TYPE_DELETE + ); + $notification->addParsedAction($dismissAction); + return $notification; } } From b7cfd99350c3fce4d53de4288a23acb093df3797 Mon Sep 17 00:00:00 2001 From: Samuelson Brito Date: Sun, 25 May 2025 01:13:08 -0400 Subject: [PATCH 3/4] feat: notify admins only once per LibreSign version after upgrade Signed-off-by: Samuelson Brito --- lib/Migration/NotifyAdminsAfterUpgrade.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/Migration/NotifyAdminsAfterUpgrade.php b/lib/Migration/NotifyAdminsAfterUpgrade.php index be3ecf5861..ee5fea9411 100644 --- a/lib/Migration/NotifyAdminsAfterUpgrade.php +++ b/lib/Migration/NotifyAdminsAfterUpgrade.php @@ -5,6 +5,9 @@ namespace OCA\Libresign\Migration; use OCA\Libresign\AppInfo\Application as AppInfoApplication; +use OCP\App\IAppManager; +use OCP\IConfig; +use OCP\IL10N; use OCP\IUserManager; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; @@ -14,6 +17,8 @@ class NotifyAdminsAfterUpgrade implements IRepairStep { public function __construct( private IUserManager $userManager, private NotificationManager $notificationManager, + private IConfig $config, + private IAppManager $appManager, ) { } @@ -22,6 +27,14 @@ public function getName(): string { } public function run(IOutput $output): void { + + $currentVersion = $currentVersion = $this->appManager->getAppVersion(AppInfoApplication::APP_ID); + $lastNotifiedVersion = $this->config->getAppValue(AppInfoApplication::APP_ID, 'last_notified_version', ''); + + if ($currentVersion === $lastNotifiedVersion) { + return; + } + $admins = $this->userManager->search('', 1, 0, ['admin']); foreach ($admins as $admin) { $notification = $this->notificationManager->createNotification(); @@ -31,9 +44,12 @@ public function run(IOutput $output): void { ->setDateTime(new \DateTime()) ->setObject('upgrade', '1') ->setSubject('libresign_upgrade', [ - 'message' => 'LibreSign has been updated! Consider supporting the project: https://libresign.coop' + 'message' => 'LibreSign has been updated to version ' . $currentVersion . '! Consider supporting the project: https://libresign.coop' ]); $this->notificationManager->notify($notification); } + + $this->config->setAppValue(AppInfoApplication::APP_ID, 'last_notified_version', $currentVersion); } + } From 0042aa23cef0fbedeccaee941a0f91693c54bd36 Mon Sep 17 00:00:00 2001 From: Samuelson Brito Date: Sun, 25 May 2025 01:56:42 -0400 Subject: [PATCH 4/4] feat: add donate button Signed-off-by: Samuelson Brito --- lib/Migration/NotifyAdminsAfterUpgrade.php | 10 +++++++--- lib/Notification/Notifier.php | 13 +++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/Migration/NotifyAdminsAfterUpgrade.php b/lib/Migration/NotifyAdminsAfterUpgrade.php index ee5fea9411..a20082a1c1 100644 --- a/lib/Migration/NotifyAdminsAfterUpgrade.php +++ b/lib/Migration/NotifyAdminsAfterUpgrade.php @@ -1,13 +1,16 @@ appManager->getAppVersion(AppInfoApplication::APP_ID); - $lastNotifiedVersion = $this->config->getAppValue(AppInfoApplication::APP_ID, 'last_notified_version', ''); + $lastNotifiedVersion = $this->config->getAppValue(AppInfoApplication::APP_ID, 'last_notified_version', ''); if ($currentVersion === $lastNotifiedVersion) { return; @@ -44,7 +47,8 @@ public function run(IOutput $output): void { ->setDateTime(new \DateTime()) ->setObject('upgrade', '1') ->setSubject('libresign_upgrade', [ - 'message' => 'LibreSign has been updated to version ' . $currentVersion . '! Consider supporting the project: https://libresign.coop' + 'version' => $currentVersion, + 'message' => 'If LibreSign is useful to you or your organization, please consider supporting our cooperative by clicking the Donate button below.', ]); $this->notificationManager->notify($notification); } diff --git a/lib/Notification/Notifier.php b/lib/Notification/Notifier.php index e1f0a910e9..0f1b2aca23 100644 --- a/lib/Notification/Notifier.php +++ b/lib/Notification/Notifier.php @@ -214,12 +214,20 @@ private function parseUpgrade( ): INotification { $parameters = $notification->getSubjectParameters(); + $version = $parameters['version'] ?? ''; $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg'))); - $subject = $l->t('LibreSign has been updated!'); + $subject = $l->t('LibreSign has been updated to version %s!', [$version]); $message = $parameters['message'] ?? ''; $notification->setParsedSubject($subject) ->setParsedMessage($message); + $donateAction = $notification->createAction() + ->setParsedLabel($l->t('Donate')) + ->setPrimary(true) + ->setLink('https://github.com/sponsors/LibreSign', \OCP\Notification\IAction::TYPE_WEB); + + $notification->addParsedAction($donateAction); + $dismissAction = $notification->createAction() ->setParsedLabel($l->t('Dismiss notification')) ->setPrimary(false) @@ -235,7 +243,8 @@ private function parseUpgrade( ], ), IAction::TYPE_DELETE - ); + ); + $notification->addParsedAction($dismissAction); return $notification;