Skip to content

Commit d407ae8

Browse files
feat: send notification to admins after LibreSign upgrade
Signed-off-by: Samuelson Brito <samuelsonma@gmail.com>
1 parent 80928e9 commit d407ae8

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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\Migration\IOutput;
9+
use OCP\Migration\IRepairStep;
10+
use OCP\IUserManager;
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+
public function getName(): string {
20+
return 'Notify admins after LibreSign upgrade';
21+
}
22+
23+
public function run(IOutput $output): void {
24+
$admins = $this->userManager->search('', 1, 0, ['admin']);
25+
foreach ($admins as $admin) {
26+
$notification = $this->notificationManager->createNotification();
27+
$notification
28+
->setApp(AppInfoApplication::APP_ID)
29+
->setUser($admin->getUID())
30+
->setDateTime(new \DateTime())
31+
->setObject('upgrade', '1') // tipo e id fictícios, só para cumprir obrigatoriedade
32+
->setSubject('libresign_upgrade', [
33+
'message' => 'LibreSign has been updated! Consider supporting the project: https://libresign.coop'
34+
]);
35+
$this->notificationManager->notify($notification);
36+
}
37+
}
38+
}

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)