feat: add notification signed

Signed-off-by: Samuelson Brito <samuelsonma@gmail.com>
This commit is contained in:
Samuelson Brito 2025-05-12 16:39:46 -04:00 committed by Vitor Mattos
parent ed31177530
commit 8a6620595e
No known key found for this signature in database
GPG key ID: B7AB4B76A7CA7318
8 changed files with 96 additions and 32 deletions

View file

@ -150,8 +150,12 @@ class Listener implements IEventListener {
'link' => $this->url->linkToRouteAbsolute('libresign.page.validationFilePublic', [
'uuid' => $libreSignFile->getUuid(),
]),
]
],
'signedFile' => [
'type' => 'signed-file',
'id' => (string)$signRequest->getId(),
'name' => $signRequest->getDisplayName(),
],
]);
$this->activityManager->publish($activityEvent);

View file

@ -37,6 +37,25 @@ class Signed implements IProvider {
throw new UnknownActivityException('subject');
}
$this->definitions->definitions['signed-file'] = [
'author' => 'LibreSign',
'since' => '28.0.0',
'parameters' => [
'id' => [
'since' => '28.0.0',
'required' => true,
'description' => 'The id of SignRequest object',
'example' => '12345',
],
'name' => [
'since' => '28.0.0',
'required' => true,
'description' => 'The display name of signer',
'example' => 'John Doe',
],
],
];
if ($this->activityManager->getRequirePNG()) {
$event->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.png')));
} else {

View file

@ -111,9 +111,16 @@ class NotifyController extends AEnvironmentAwareController {
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'DELETE', url: '/api/{apiVersion}/notify/notification', requirements: ['apiVersion' => '(v1)'])]
public function notificationDismiss(int $signRequestId, int $timestamp): DataResponse {
public function notificationDismiss(
string $objectType,
int $objectId,
string $subject,
int $timestamp,
): DataResponse {
$this->notifyService->notificationDismiss(
$signRequestId,
$objectType,
$objectId,
$subject,
$this->userSession->getUser(),
$timestamp
);

View file

@ -2,7 +2,7 @@
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

View file

@ -91,7 +91,6 @@ class NotificationListener implements IEventListener {
$this->notificationManager->notify($notification);
}
//TODO dados mockados para testar notificação
private function sendSignedNotification(
SignRequest $signRequest,
FileEntity $libreSignFile,
@ -125,6 +124,11 @@ class NotificationListener implements IEventListener {
'uuid' => $libreSignFile->getUuid(),
]),
],
'signedFile' => [
'type' => 'signed-file',
'id' => (string)$signRequest->getId(),
'name' => $signRequest->getDisplayName(),
],
]);
$this->notificationManager->notify($notification);

View file

@ -43,25 +43,6 @@ class Notifier implements INotifier {
throw new UnknownActivityException();
}
$this->definitions->definitions['sign-request'] = [
'author' => 'LibreSign',
'since' => '28.0.0',
'parameters' => [
'id' => [
'since' => '28.0.0',
'required' => true,
'description' => 'The id of SignRequest object',
'example' => '12345',
],
'name' => [
'since' => '28.0.0',
'required' => true,
'description' => 'The display name of signer',
'example' => 'John Doe',
],
],
];
$l = $this->factory->get(Application::APP_ID, $languageCode);
switch ($notification->getSubject()) {
@ -81,6 +62,26 @@ class Notifier implements INotifier {
IL10N $l,
bool $update,
): INotification {
$this->definitions->definitions['sign-request'] = [
'author' => 'LibreSign',
'since' => '28.0.0',
'parameters' => [
'id' => [
'since' => '28.0.0',
'required' => true,
'description' => 'The id of SignRequest object',
'example' => '12345',
],
'name' => [
'since' => '28.0.0',
'required' => true,
'description' => 'The display name of signer',
'example' => 'John Doe',
],
],
];
$parameters = $notification->getSubjectParameters();
$notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg')));
if (isset($parameters['file'])) {
@ -120,7 +121,9 @@ class Notifier implements INotifier {
[
'apiVersion' => 'v1',
'timestamp' => $notification->getDateTime()->getTimestamp(),
'signRequestId' => $parameters['signRequest']['id'],
'objectType' => 'signRequest',
'objectId' => $parameters['signRequest']['id'],
'subject' => 'new_sign_request',
],
),
IAction::TYPE_DELETE
@ -136,6 +139,25 @@ class Notifier implements INotifier {
IL10N $l,
): INotification {
$this->definitions->definitions['signed-file'] = [
'author' => 'LibreSign',
'since' => '28.0.0',
'parameters' => [
'id' => [
'since' => '28.0.0',
'required' => true,
'description' => 'The id of SignRequest object',
'example' => '12345',
],
'name' => [
'since' => '28.0.0',
'required' => true,
'description' => 'The display name of signer',
'example' => 'John Doe',
],
],
];
$parameters = $notification->getSubjectParameters();
$notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath(Application::APP_ID, 'app-dark.svg')));
if (isset($parameters['file'])) {
@ -162,6 +184,7 @@ class Notifier implements INotifier {
->setRichSubject($subject, $parameters);
}
}
if (isset($parameters['signedFile']) && isset($parameters['signedFile']['id'])) {
$dismissAction = $notification->createAction()
->setParsedLabel($l->t('Dismiss notification'))
@ -171,7 +194,9 @@ class Notifier implements INotifier {
[
'apiVersion' => 'v1',
'timestamp' => $notification->getDateTime()->getTimestamp(),
'signRequestId' => $parameters['signedFile']['id'],
'objectType' => 'signedFile',
'objectId' => $parameters['signedFile']['id'],
'subject' => 'file_signed',
],
),
IAction::TYPE_DELETE

View file

@ -53,13 +53,19 @@ class NotifyService {
}
}
public function notificationDismiss(int $signRequestId, IUser $user, int $timestamp): void {
public function notificationDismiss(
string $objectType,
int $objectId,
string $subject,
IUser $user,
int $timestamp,
): void {
$notification = $this->notificationManager->createNotification();
$notification->setApp(Application::APP_ID)
->setObject('signRequest', (string)$signRequestId)
->setObject($objectType, (string)$objectId)
->setDateTime($this->timeFactory->getDateTime('@' . $timestamp))
->setUser($user->getUID())
->setSubject('new_sign_request');
->setSubject($subject);
$this->notificationManager->markProcessed($notification);
}

View file

@ -313,6 +313,7 @@ class SignFileService {
$this->signRequest->setSignedHash($hash);
if ($this->signRequest->getId()) {
$this->signRequestMapper->update($this->signRequest);
$this->eventDispatcher->dispatchTyped(new SignedEvent($this->signRequest, $this->libreSignFile, $this->identifyMethodService->getIdentifiedMethod($this->signRequest->getId())));
} else {
$this->signRequestMapper->insert($this->signRequest);
}
@ -324,8 +325,6 @@ class SignFileService {
$this->eventDispatcher->dispatchTyped(new SignedCallbackEvent($this, $signedFile, $allSigned));
$this->eventDispatcher->dispatchTyped(new SignedEvent($this->signRequest, $this->libreSignFile, $this->identifyMethodService->getIdentifiedMethod($this->signRequest->getId())));
return $signedFile;
}