Skip to content

Commit 9968d31

Browse files
feat: send notification to admins after LibreSign upgrade
Signed-off-by: Samuelson Brito <[email protected]>
1 parent 80928e9 commit 9968d31

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

appinfo/info.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Developed with ❤️ by [LibreCode](https://librecode.coop). Help us transform
5454
<post-migration>
5555
<step>OCA\Libresign\Migration\DeleteOldBinaries</step>
5656
<step>OCA\Libresign\Migration\ResynchronizeDatabaseSequences</step>
57+
<step>OCA\Libresign\Migration\NotifyAdminsAfterUpgrade</step>
5758
</post-migration>
5859
</repair-steps>
5960
<commands>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OCA\Libresign\Migration;
6+
7+
use OCA\Libresign\AppInfo\Application as AppInfoApplication;
8+
use OCP\IUserManager;
9+
use OCP\Migration\IOutput;
10+
use OCP\Migration\IRepairStep;
11+
use OCP\Notification\IManager as NotificationManager;
12+
13+
class NotifyAdminsAfterUpgrade implements IRepairStep {
14+
public function __construct(
15+
private IUserManager $userManager,
16+
private NotificationManager $notificationManager,
17+
) {
18+
}
19+
20+
public function getName(): string {
21+
return 'Notify admins after LibreSign upgrade';
22+
}
23+
24+
public function run(IOutput $output): void {
25+
$admins = $this->userManager->search('', 1, 0, ['admin']);
26+
foreach ($admins as $admin) {
27+
$notification = $this->notificationManager->createNotification();
28+
$notification
29+
->setApp(AppInfoApplication::APP_ID)
30+
->setUser($admin->getUID())
31+
->setDateTime(new \DateTime())
32+
->setObject('upgrade', '1')
33+
->setSubject('libresign_upgrade', [
34+
'message' => 'LibreSign has been updated! Consider supporting the project: https://libresign.coop'
35+
]);
36+
$this->notificationManager->notify($notification);
37+
}
38+
}
39+
}

lib/Notification/Notifier.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function prepare(INotification $notification, string $languageCode): INot
4949
'new_sign_request' => $this->parseSignRequest($notification, $l, false),
5050
'update_sign_request' => $this->parseSignRequest($notification, $l, true),
5151
'file_signed' => $this->parseSigned($notification, $l),
52+
'libresign_upgrade' => $this->parseUpgrade($notification, $l),
5253
default => throw new UnknownActivityException(),
5354
};
5455
}
@@ -221,4 +222,17 @@ private function parseSigned(
221222
return $notification;
222223

223224
}
225+
226+
private function parseUpgrade(
227+
INotification $notification,
228+
IL10N $l,
229+
): INotification {
230+
$parameters = $notification->getSubjectParameters();
231+
$notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg')));
232+
$subject = $l->t('LibreSign has been updated!');
233+
$message = $parameters['message'] ?? '';
234+
$notification->setParsedSubject($subject)
235+
->setParsedMessage($message);
236+
return $notification;
237+
}
224238
}

0 commit comments

Comments
 (0)