Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,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>
Expand Down
59 changes: 59 additions & 0 deletions lib/Migration/NotifyAdminsAfterUpgrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Libresign\Migration;

use OCA\Libresign\AppInfo\Application as AppInfoApplication;
use OCP\App\IAppManager;
use OCP\IConfig;
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,
private IConfig $config,
private IAppManager $appManager,
) {
}

public function getName(): string {
return 'Notify admins after LibreSign upgrade';
}

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();
$notification
->setApp(AppInfoApplication::APP_ID)
->setUser($admin->getUID())
->setDateTime(new \DateTime())
->setObject('upgrade', '1')
->setSubject('libresign_upgrade', [
'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);
}

$this->config->setAppValue(AppInfoApplication::APP_ID, 'last_notified_version', $currentVersion);
}

}
43 changes: 43 additions & 0 deletions lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,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 UnknownActivityException(),
};
}
Expand Down Expand Up @@ -221,4 +222,46 @@ private function parseSigned(
return $notification;

}

private function parseUpgrade(
INotification $notification,
IL10N $l,
): 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 to version %s!', [$version]);
$message = $parameters['message'] ?? '';
$notification->setParsedSubject($subject)
->setParsedMessage($message);

$donateAction = $notification->createAction()
->setParsedLabel($l->t('Donate'))
->setPrimary(true)
->setLink('https://libresign.coop', \OCP\Notification\IAction::TYPE_WEB);

$notification->addParsedAction($donateAction);

$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;
}
}
Loading