feat: send notification to admins after LibreSign upgrade

Signed-off-by: Samuelson Brito <samuelsonma@gmail.com>
This commit is contained in:
Samuelson Brito 2025-05-24 22:46:47 -04:00 committed by samuelsonmesquita
parent 25e6961dfb
commit 56b59602ea
3 changed files with 54 additions and 0 deletions

View file

@ -60,6 +60,7 @@ Developed with ❤️ by [LibreCode](https://librecode.coop). Help us transform
<post-migration>
<step>OCA\Libresign\Migration\DeleteOldBinaries</step>
<step>OCA\Libresign\Migration\ResynchronizeDatabaseSequences</step>
<step>OCA\Libresign\Migration\NotifyAdminsAfterUpgrade</step>
</post-migration>
</repair-steps>
<commands>

View file

@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace OCA\Libresign\Migration;
use OCA\Libresign\AppInfo\Application as AppInfoApplication;
use OCP\IUserManager;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use OCP\Notification\IManager as NotificationManager;
class NotifyAdminsAfterUpgrade implements IRepairStep {
public function __construct(
private IUserManager $userManager,
private NotificationManager $notificationManager,
) {
}
public function getName(): string {
return 'Notify admins after LibreSign upgrade';
}
public function run(IOutput $output): void {
$admins = $this->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);
}
}
}

View file

@ -52,6 +52,7 @@ class Notifier implements INotifier {
'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 @@ class Notifier implements INotifier {
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;
}
}