Skip to content

Commit 56b5960

Browse files
samuelsonbritosamuelsonmesquita
authored andcommitted
feat: send notification to admins after LibreSign upgrade
Signed-off-by: Samuelson Brito <[email protected]>
1 parent 25e6961 commit 56b5960

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

appinfo/info.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Developed with ❤️ by [LibreCode](https://librecode.coop). Help us transform
6060
<post-migration>
6161
<step>OCA\Libresign\Migration\DeleteOldBinaries</step>
6262
<step>OCA\Libresign\Migration\ResynchronizeDatabaseSequences</step>
63+
<step>OCA\Libresign\Migration\NotifyAdminsAfterUpgrade</step>
6364
</post-migration>
6465
</repair-steps>
6566
<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
@@ -52,6 +52,7 @@ public function prepare(INotification $notification, string $languageCode): INot
5252
'new_sign_request' => $this->parseSignRequest($notification, $l, false),
5353
'update_sign_request' => $this->parseSignRequest($notification, $l, true),
5454
'file_signed' => $this->parseSigned($notification, $l),
55+
'libresign_upgrade' => $this->parseUpgrade($notification, $l),
5556
default => throw new UnknownNotificationException(),
5657
};
5758
}
@@ -206,4 +207,17 @@ private function parseSigned(
206207
return $notification;
207208

208209
}
210+
211+
private function parseUpgrade(
212+
INotification $notification,
213+
IL10N $l,
214+
): INotification {
215+
$parameters = $notification->getSubjectParameters();
216+
$notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg')));
217+
$subject = $l->t('LibreSign has been updated!');
218+
$message = $parameters['message'] ?? '';
219+
$notification->setParsedSubject($subject)
220+
->setParsedMessage($message);
221+
return $notification;
222+
}
209223
}

0 commit comments

Comments
 (0)