From fa50b6ac563da005d362df41d895e37ce5f82e63 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Fri, 22 Mar 2024 10:51:55 -0300 Subject: [PATCH 1/8] Store notification history at sign_request table Signed-off-by: Vitor Mattos --- lib/Activity/Listener.php | 7 +++-- lib/Db/SignRequestMapper.php | 28 +++++++++++++++++++ lib/Events/SendSignNotificationEvent.php | 5 ---- lib/Listener/MailNotifyListener.php | 7 +++-- lib/Listener/NotificationListener.php | 11 ++++---- .../IdentifyMethod/AbstractIdentifyMethod.php | 13 ++++----- .../IdentifyMethod/IIdentifyMethod.php | 2 +- .../IdentifyMethod/IdentifyMethodService.php | 9 ++---- 8 files changed, 52 insertions(+), 30 deletions(-) diff --git a/lib/Activity/Listener.php b/lib/Activity/Listener.php index d842d1b8de..3279b57126 100644 --- a/lib/Activity/Listener.php +++ b/lib/Activity/Listener.php @@ -27,6 +27,7 @@ use OCA\Libresign\AppInfo\Application; use OCA\Libresign\Db\File as FileEntity; use OCA\Libresign\Db\SignRequest; +use OCA\Libresign\Db\SignRequestMapper; use OCA\Libresign\Events\SendSignNotificationEvent; use OCA\Libresign\Service\AccountService; use OCA\Libresign\Service\IdentifyMethod\IIdentifyMethod; @@ -50,6 +51,7 @@ public function __construct( protected ITimeFactory $timeFactory, protected AccountService $accountService, protected IURLGenerator $url, + private SignRequestMapper $signRequestMapper, ) { } @@ -60,7 +62,6 @@ public function handle(Event $event): void { $event->getSignRequest(), $event->getLibreSignFile(), $event->getIdentifyMethod(), - $event->isNew() ), }; } @@ -75,7 +76,6 @@ protected function generateNewSignNotificationActivity( SignRequest $signRequest, FileEntity $libreSignFile, IIdentifyMethod $identifyMethod, - bool $isNew ): void { $actor = $this->userSession->getUser(); if (!$actor instanceof IUser) { @@ -96,7 +96,8 @@ protected function generateNewSignNotificationActivity( // At notification app we can define the view and dismiss action // Activity dont have this feature ->setGenerateNotification(false); - if ($isNew) { + $isFirstNotification = $this->signRequestMapper->incrementNotificationCounter($signRequest, 'activity'); + if ($isFirstNotification) { $subject = 'new_sign_request'; } else { $subject = 'update_sign_request'; diff --git a/lib/Db/SignRequestMapper.php b/lib/Db/SignRequestMapper.php index 52f827e206..ee5c0ad434 100644 --- a/lib/Db/SignRequestMapper.php +++ b/lib/Db/SignRequestMapper.php @@ -48,6 +48,7 @@ class SignRequestMapper extends QBMapper { * @var SignRequest[] */ private $signers = []; + private bool $firstNotification = false; public function __construct( IDBConnection $db, @@ -60,6 +61,33 @@ public function __construct( parent::__construct($db, 'libresign_sign_request'); } + /** + * @return boolean true when is the first notification + */ + public function incrementNotificationCounter(SignRequest $signRequest, string $method): bool { + $this->db->beginTransaction(); + try { + $fromDatabase = $this->getById($signRequest->getId()); + $metadata = $fromDatabase->getMetadata(); + if (!empty($metadata)) { + $metadata = json_decode($metadata, true); + } + if (!isset($metadata['notify'])) { + $this->firstNotification = true; + } + $metadata['notify'][] = [ + 'method' => $method, + 'date' => time(), + ]; + $fromDatabase->setMetadata($metadata); + $this->update($fromDatabase); + $this->db->commit(); + } catch (\Throwable) { + $this->db->rollBack(); + } + return $this->firstNotification; + } + /** * @inheritDoc */ diff --git a/lib/Events/SendSignNotificationEvent.php b/lib/Events/SendSignNotificationEvent.php index c3dcfc437c..6dad2579f8 100644 --- a/lib/Events/SendSignNotificationEvent.php +++ b/lib/Events/SendSignNotificationEvent.php @@ -34,7 +34,6 @@ public function __construct( private SignRequest $signRequest, private FileEntity $libreSignFile, private IIdentifyMethod $identifyMethod, - private bool $isNew ) { } @@ -46,10 +45,6 @@ public function getSignRequest(): SignRequest { return $this->signRequest; } - public function isNew(): bool { - return $this->isNew; - } - public function getIdentifyMethod(): IIdentifyMethod { return $this->identifyMethod; } diff --git a/lib/Listener/MailNotifyListener.php b/lib/Listener/MailNotifyListener.php index d8547272c4..abdadcc8a0 100644 --- a/lib/Listener/MailNotifyListener.php +++ b/lib/Listener/MailNotifyListener.php @@ -26,6 +26,7 @@ use OCA\Libresign\Db\File as FileEntity; use OCA\Libresign\Db\SignRequest; +use OCA\Libresign\Db\SignRequestMapper; use OCA\Libresign\Events\SendSignNotificationEvent; use OCA\Libresign\Service\IdentifyMethod\IdentifyMethodService; use OCA\Libresign\Service\IdentifyMethod\IIdentifyMethod; @@ -43,6 +44,7 @@ public function __construct( protected IUserManager $userManager, protected IdentifyMethodService $identifyMethodService, protected MailService $mail, + private SignRequestMapper $signRequestMapper, private LoggerInterface $logger, ) { } @@ -54,7 +56,6 @@ public function handle(Event $event): void { $event->getSignRequest(), $event->getLibreSignFile(), $event->getIdentifyMethod(), - $event->isNew() ), }; } @@ -63,7 +64,6 @@ protected function sendMailNotification( SignRequest $signRequest, FileEntity $libreSignFile, IIdentifyMethod $identifyMethod, - bool $isNew, ): void { $actor = $this->userSession->getUser(); if (!$actor instanceof IUser) { @@ -81,7 +81,8 @@ protected function sendMailNotification( if (empty($email)) { return; } - if ($isNew) { + $isFirstNotification = $this->signRequestMapper->incrementNotificationCounter($signRequest, 'mail'); + if ($isFirstNotification) { $this->mail->notifyUnsignedUser($signRequest, $email); return; } diff --git a/lib/Listener/NotificationListener.php b/lib/Listener/NotificationListener.php index ef7695e28f..110503b072 100644 --- a/lib/Listener/NotificationListener.php +++ b/lib/Listener/NotificationListener.php @@ -27,6 +27,7 @@ use OCA\Libresign\AppInfo\Application as AppInfoApplication; use OCA\Libresign\Db\File as FileEntity; use OCA\Libresign\Db\SignRequest; +use OCA\Libresign\Db\SignRequestMapper; use OCA\Libresign\Events\SendSignNotificationEvent; use OCA\Libresign\Service\IdentifyMethod\IIdentifyMethod; use OCP\AppFramework\Utility\ITimeFactory; @@ -46,25 +47,24 @@ public function __construct( protected IUserSession $userSession, private ITimeFactory $timeFactory, protected IURLGenerator $url, + private SignRequestMapper $signRequestMapper, ) { } public function handle(Event $event): void { if ($event instanceof SendSignNotificationEvent) { - $this->sendNewSignNotification( + $this->sendSignNotification( $event->getSignRequest(), $event->getLibreSignFile(), $event->getIdentifyMethod(), - $event->isNew() ); } } - private function sendNewSignNotification( + private function sendSignNotification( SignRequest $signRequest, FileEntity $libreSignFile, IIdentifyMethod $identifyMethod, - bool $isNew ): void { $actor = $this->userSession->getUser(); if (!$actor instanceof IUser) { @@ -79,7 +79,8 @@ private function sendNewSignNotification( ->setObject('signRequest', (string) $signRequest->getId()) ->setDateTime((new \DateTime())->setTimestamp($this->timeFactory->now()->getTimestamp())) ->setUser($identifyMethod->getEntity()->getIdentifierValue()); - if ($isNew) { + $isFirstNotification = $this->signRequestMapper->incrementNotificationCounter($signRequest, 'notify'); + if ($isFirstNotification) { $subject = 'new_sign_request'; } else { $subject = 'update_sign_request'; diff --git a/lib/Service/IdentifyMethod/AbstractIdentifyMethod.php b/lib/Service/IdentifyMethod/AbstractIdentifyMethod.php index 5e7a475f62..f80e0a053a 100644 --- a/lib/Service/IdentifyMethod/AbstractIdentifyMethod.php +++ b/lib/Service/IdentifyMethod/AbstractIdentifyMethod.php @@ -103,7 +103,7 @@ public function getSettings(): array { return $this->settings; } - public function notify(bool $isNew): bool { + public function notify(): bool { if (!$this->willNotify) { return false; } @@ -112,8 +112,7 @@ public function notify(bool $isNew): bool { $this->identifyMethodService->getEventDispatcher()->dispatchTyped(new SendSignNotificationEvent( $signRequest, $libresignFile, - $this, - $isNew + $this )); return true; } @@ -189,8 +188,8 @@ protected function updateIdentifiedAt(): void { } $this->getEntity()->setIdentifiedAtDate($this->identifyMethodService->getTimeFactory()->getDateTime()); $this->willNotify = false; - $isNew = $this->identifyMethodService->save($this->getEntity()); - $this->notify($isNew); + $this->identifyMethodService->save($this->getEntity()); + $this->notify(); } protected function throwIfRenewalIntervalExpired(): void { @@ -320,8 +319,8 @@ private function applyDefault(array $customConfig, array $default): array { } public function save(): void { - $isNew = $this->identifyMethodService->save($this->getEntity()); - $this->notify($isNew); + $this->identifyMethodService->save($this->getEntity()); + $this->notify(); } public function delete(): void { diff --git a/lib/Service/IdentifyMethod/IIdentifyMethod.php b/lib/Service/IdentifyMethod/IIdentifyMethod.php index 6d6fcba9f0..a64f3a14d9 100644 --- a/lib/Service/IdentifyMethod/IIdentifyMethod.php +++ b/lib/Service/IdentifyMethod/IIdentifyMethod.php @@ -43,7 +43,7 @@ public function getSignatureMethods(): array; public function signatureMethodsToArray(): array; public function getSettings(): array; public function willNotifyUser(bool $willNotify): void; - public function notify(bool $isNew): bool; + public function notify(): bool; public function validateToRequest(): void; public function validateToCreateAccount(string $value): void; public function validateToIdentify(): void; diff --git a/lib/Service/IdentifyMethod/IdentifyMethodService.php b/lib/Service/IdentifyMethod/IdentifyMethodService.php index 0c4ca480eb..5fe726e0f6 100644 --- a/lib/Service/IdentifyMethod/IdentifyMethodService.php +++ b/lib/Service/IdentifyMethod/IdentifyMethodService.php @@ -60,17 +60,14 @@ public function __construct( ) { } - /** - * @return boolean is new instance - */ - public function save(IdentifyMethod $identifyMethod): bool { + public function save(IdentifyMethod $identifyMethod): void { $this->refreshIdFromDatabaseIfNecessary($identifyMethod); if ($identifyMethod->getId()) { $this->identifyMethodMapper->update($identifyMethod); - return false; + return; } $this->identifyMethodMapper->insertOrUpdate($identifyMethod); - return true; + return; } public function delete(IdentifyMethod $identifyMethod): void { From 76550bda0bce07faf956d39b0774f1aa7362d664 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Fri, 22 Mar 2024 12:12:27 -0300 Subject: [PATCH 2/8] Bump dependencies Signed-off-by: Vitor Mattos --- tests/integration/composer.json | 2 +- tests/integration/composer.lock | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/integration/composer.json b/tests/integration/composer.json index fc8907bf54..a3570a9877 100644 --- a/tests/integration/composer.json +++ b/tests/integration/composer.json @@ -9,7 +9,7 @@ "rpkamp/mailhog-behat-extension": "^1.0" }, "require-dev": { - "libresign/nextcloud-behat": "^0.12.0" + "libresign/nextcloud-behat": "^0.13.0" }, "config": { "allow-plugins": { diff --git a/tests/integration/composer.lock b/tests/integration/composer.lock index b230948b53..0efb976ee3 100644 --- a/tests/integration/composer.lock +++ b/tests/integration/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6f23626703cfda8ee02f4e9d949e8901", + "content-hash": "7318ccb58fd0f6556a5a28597c2c8538", "packages": [ { "name": "behat/behat", @@ -1586,16 +1586,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.17", + "version": "9.6.18", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "1a156980d78a6666721b7e8e8502fe210b587fcd" + "reference": "32c2c2d6580b1d8ab3c10b1e9e4dc263cc69bb04" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1a156980d78a6666721b7e8e8502fe210b587fcd", - "reference": "1a156980d78a6666721b7e8e8502fe210b587fcd", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/32c2c2d6580b1d8ab3c10b1e9e4dc263cc69bb04", + "reference": "32c2c2d6580b1d8ab3c10b1e9e4dc263cc69bb04", "shasum": "" }, "require": { @@ -1669,7 +1669,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.17" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.18" }, "funding": [ { @@ -1685,7 +1685,7 @@ "type": "tidelift" } ], - "time": "2024-02-23T13:14:51+00:00" + "time": "2024-03-21T12:07:32+00:00" }, { "name": "psr-discovery/discovery", @@ -5184,16 +5184,16 @@ }, { "name": "libresign/nextcloud-behat", - "version": "v0.12.1", + "version": "v0.13.0", "source": { "type": "git", "url": "https://github.com/LibreSign/nextcloud-behat.git", - "reference": "f194953e7366ac05e64f44852bbc25a49cf4779a" + "reference": "172923ce909e6904d5ab30dfc6a8ef0882b5b49b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/LibreSign/nextcloud-behat/zipball/f194953e7366ac05e64f44852bbc25a49cf4779a", - "reference": "f194953e7366ac05e64f44852bbc25a49cf4779a", + "url": "https://api.github.com/repos/LibreSign/nextcloud-behat/zipball/172923ce909e6904d5ab30dfc6a8ef0882b5b49b", + "reference": "172923ce909e6904d5ab30dfc6a8ef0882b5b49b", "shasum": "" }, "require": { @@ -5238,9 +5238,9 @@ ], "support": { "issues": "https://github.com/LibreSign/nextcloud-behat/issues", - "source": "https://github.com/LibreSign/nextcloud-behat/tree/v0.12.1" + "source": "https://github.com/LibreSign/nextcloud-behat/tree/v0.13.0" }, - "time": "2024-03-20T21:39:15+00:00" + "time": "2024-03-22T15:09:04+00:00" }, { "name": "symfony/process", From 2a890b1b848a4d5fa7455916a75ca99053d96c7b Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Fri, 22 Mar 2024 12:14:04 -0300 Subject: [PATCH 3/8] Promote steps Signed-off-by: Vitor Mattos --- .../features/bootstrap/FeatureContext.php | 36 +------------------ 1 file changed, 1 insertion(+), 35 deletions(-) diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index ff39a63c32..63eddfb6da 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -14,7 +14,6 @@ class FeatureContext extends NextcloudApiContext implements OpenedEmailStorageAwareContext { private array $signer = []; private array $file = []; - private array $fields = []; private OpenedEmailStorage $openedEmailStorage; /** @@ -125,25 +124,6 @@ protected function beforeRequest(string $fullUrl, array $options): array { return [$fullUrl, $options]; } - protected function parseFormParams(array $options): array { - if (!empty($options['form_params'])) { - $this->parseTextRcursive($options['form_params']); - } - return $options; - } - - private function parseTextRcursive(&$array): array { - array_walk_recursive($array, function (&$value) { - if (is_string($value)) { - $value = $this->parseText($value); - } elseif ($value instanceof \stdClass) { - $value = (array) $value; - $value = json_decode(json_encode($this->parseTextRcursive($value))); - } - }); - return $array; - } - protected function parseText(string $text): string { $patterns = [ '//', @@ -160,6 +140,7 @@ protected function parseText(string $text): string { $replacements[] = $value; } $text = preg_replace($patterns, $replacements, $text); + $text = parent::parseText($text); return $text; } @@ -287,21 +268,6 @@ public function deleteSignerFromFileOfPreviousListing(int $signerSequence, int $ $this->sendOCSRequest('delete', '/apps/libresign/api/v1/sign/file_id/' . $fileId . '/'. $signRequestId); } - /** - * @When fetch field :path from prevous JSON response - */ - public function fetchFieldFromPreviousJsonResponse(string $path): void { - $this->response->getBody()->seek(0); - $responseArray = json_decode($this->response->getBody()->getContents(), true); - $keys = explode('.', $path); - $value = $responseArray; - foreach ($keys as $key) { - Assert::assertArrayHasKey($key, $value, 'Key [' . $key . '] of path [' . $path . '] not found.'); - $value = $value[$key]; - } - $this->fields[$path] = $value; - } - /** * @When /^wait for ([0-9]+) (second|seconds)$/ */ From 3f405b380d665d670c83c5ed236c43f182a4d0cc Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Fri, 22 Mar 2024 13:37:45 -0300 Subject: [PATCH 4/8] Bump dependencies Signed-off-by: Vitor Mattos --- tests/integration/composer.json | 2 +- tests/integration/composer.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/integration/composer.json b/tests/integration/composer.json index a3570a9877..73f1c43538 100644 --- a/tests/integration/composer.json +++ b/tests/integration/composer.json @@ -9,7 +9,7 @@ "rpkamp/mailhog-behat-extension": "^1.0" }, "require-dev": { - "libresign/nextcloud-behat": "^0.13.0" + "libresign/nextcloud-behat": "^0.14.1" }, "config": { "allow-plugins": { diff --git a/tests/integration/composer.lock b/tests/integration/composer.lock index 0efb976ee3..e8cb1bd8ca 100644 --- a/tests/integration/composer.lock +++ b/tests/integration/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7318ccb58fd0f6556a5a28597c2c8538", + "content-hash": "980e59106d706cd9ffe23545da632cfd", "packages": [ { "name": "behat/behat", @@ -5184,16 +5184,16 @@ }, { "name": "libresign/nextcloud-behat", - "version": "v0.13.0", + "version": "v0.14.1", "source": { "type": "git", "url": "https://github.com/LibreSign/nextcloud-behat.git", - "reference": "172923ce909e6904d5ab30dfc6a8ef0882b5b49b" + "reference": "6ba7c59e59f0b4aaaa5ce67d16affb9479874d0d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/LibreSign/nextcloud-behat/zipball/172923ce909e6904d5ab30dfc6a8ef0882b5b49b", - "reference": "172923ce909e6904d5ab30dfc6a8ef0882b5b49b", + "url": "https://api.github.com/repos/LibreSign/nextcloud-behat/zipball/6ba7c59e59f0b4aaaa5ce67d16affb9479874d0d", + "reference": "6ba7c59e59f0b4aaaa5ce67d16affb9479874d0d", "shasum": "" }, "require": { @@ -5238,9 +5238,9 @@ ], "support": { "issues": "https://github.com/LibreSign/nextcloud-behat/issues", - "source": "https://github.com/LibreSign/nextcloud-behat/tree/v0.13.0" + "source": "https://github.com/LibreSign/nextcloud-behat/tree/v0.14.1" }, - "time": "2024-03-22T15:09:04+00:00" + "time": "2024-03-22T16:35:47+00:00" }, { "name": "symfony/process", From c9961a91bc94f0c4425918af0b3b0e34b502d8df Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Fri, 22 Mar 2024 14:21:43 -0300 Subject: [PATCH 5/8] Use the pattern of parent class Now is possible get values with label from response. Signed-off-by: Vitor Mattos --- tests/integration/features/bootstrap/FeatureContext.php | 4 ---- tests/integration/features/page/sign_identify_account.feature | 1 + tests/integration/features/sign/request.feature | 3 +++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 63eddfb6da..32567ba67a 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -127,12 +127,10 @@ protected function beforeRequest(string $fullUrl, array $options): array { protected function parseText(string $text): string { $patterns = [ '//', - '//', '//', ]; $replacements = [ $this->signer['sign_uuid'] ?? null, - $this->file['uuid'] ?? $this->getFileUuidFromText($text), $this->baseUrl . '/index.php', ]; foreach ($this->fields as $key => $value) { @@ -196,8 +194,6 @@ public function iFetchTheLinkOnOpenedEmail(): void { */ public function iSendAFileToBeSigned(TableNode $body): void { $this->sendOCSRequest('post', '/apps/libresign/api/v1/request-signature', $body); - $realResponseArray = json_decode($this->response->getBody()->getContents(), true); - $this->file['uuid'] = $realResponseArray['data']['uuid']; } /** diff --git a/tests/integration/features/page/sign_identify_account.feature b/tests/integration/features/page/sign_identify_account.feature index 6fd4efeacc..325cd48b5f 100644 --- a/tests/integration/features/page/sign_identify_account.feature +++ b/tests/integration/features/page/sign_identify_account.feature @@ -13,6 +13,7 @@ Feature: page/sign_identify_account | users | [{"identify":{"account":"signer1"}}] | | name | document | And the response should have a status code 200 + And fetch field "(FILE_UUID)data.uuid" from prevous JSON response When as user "signer1" And sending "get" to ocs "/apps/notifications/api/v2/notifications" Then the response should be a JSON array with the following mandatory values diff --git a/tests/integration/features/sign/request.feature b/tests/integration/features/sign/request.feature index 29ab65abe2..1a5f47a6a3 100644 --- a/tests/integration/features/sign/request.feature +++ b/tests/integration/features/sign/request.feature @@ -191,6 +191,7 @@ Feature: request-signature | users | [{"identify":{"account":"signer1"}}] | | name | document | Then the response should have a status code 200 + And fetch field "(FILE_UUID)data.uuid" from prevous JSON response When as user "signer1" Then sending "get" to ocs "/apps/notifications/api/v2/notifications" And the response should be a JSON array with the following mandatory values @@ -279,6 +280,7 @@ Feature: request-signature | users | [{"identify":{"email":"signer1@domain.test"}}] | | status | 0 | | name | document | + And fetch field "(FILE_UUID)data.uuid" from prevous JSON response And the response should have a status code 200 And sending "get" to ocs "/apps/libresign/api/v1/file/list" And fetch field "data.0.signers.0.signRequestId" from prevous JSON response @@ -323,6 +325,7 @@ Feature: request-signature | file | {"base64":"data:application/pdf;base64,JVBERi0xLjYKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0ZpbHRlci9GbGF0ZURlY29kZT4+CnN0cmVhbQp4nDPQM1Qo5ypUMFAw0DMwslAwtTTVMzIxV7AwMdSzMDNUKErlCtdSyOMyVADBonQuA4iUhaVCLheKYqBIDlw7xLAcuLEgFlwVVwZXmhZXoAIAI+sZGAplbmRzdHJlYW0KZW5kb2JqCgozIDAgb2JqCjg2CmVuZG9iagoKNSAwIG9iago8PAo+PgplbmRvYmoKCjYgMCBvYmoKPDwvRm9udCA1IDAgUgovUHJvY1NldFsvUERGL1RleHRdCj4+CmVuZG9iagoKMSAwIG9iago8PC9UeXBlL1BhZ2UvUGFyZW50IDQgMCBSL1Jlc291cmNlcyA2IDAgUi9NZWRpYUJveFswIDAgNTk1LjI3NTU5MDU1MTE4MSA4NDEuODg5NzYzNzc5NTI4XS9Hcm91cDw8L1MvVHJhbnNwYXJlbmN5L0NTL0RldmljZVJHQi9JIHRydWU+Pi9Db250ZW50cyAyIDAgUj4+CmVuZG9iagoKNCAwIG9iago8PC9UeXBlL1BhZ2VzCi9SZXNvdXJjZXMgNiAwIFIKL01lZGlhQm94WyAwIDAgNTk1IDg0MSBdCi9LaWRzWyAxIDAgUiBdCi9Db3VudCAxPj4KZW5kb2JqCgo3IDAgb2JqCjw8L1R5cGUvQ2F0YWxvZy9QYWdlcyA0IDAgUgovT3BlbkFjdGlvblsxIDAgUiAvWFlaIG51bGwgbnVsbCAwXQo+PgplbmRvYmoKCjggMCBvYmoKPDwvQ3JlYXRvcjxGRUZGMDA0NDAwNzIwMDYxMDA3Nz4KL1Byb2R1Y2VyPEZFRkYwMDRDMDA2OTAwNjIwMDcyMDA2NTAwNEYwMDY2MDA2NjAwNjkwMDYzMDA2NTAwMjAwMDM3MDAyRTAwMzA+Ci9DcmVhdGlvbkRhdGUoRDoyMDIxMDIyMzExMDgwOS0wMycwMCcpPj4KZW5kb2JqCgp4cmVmCjAgOQowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAwMDAyNzAgMDAwMDAgbiAKMDAwMDAwMDAxOSAwMDAwMCBuIAowMDAwMDAwMTc2IDAwMDAwIG4gCjAwMDAwMDA0MzggMDAwMDAgbiAKMDAwMDAwMDE5NSAwMDAwMCBuIAowMDAwMDAwMjE3IDAwMDAwIG4gCjAwMDAwMDA1MzYgMDAwMDAgbiAKMDAwMDAwMDYxOSAwMDAwMCBuIAp0cmFpbGVyCjw8L1NpemUgOS9Sb290IDcgMCBSCi9JbmZvIDggMCBSCi9JRCBbIDw1RkQ4MDlEMTdFODMwQUU5OTRDODkxNDVBMTMwNUQyQz4KPDVGRDgwOUQxN0U4MzBBRTk5NEM4OTE0NUExMzA1RDJDPiBdCi9Eb2NDaGVja3N1bSAvRDZBQThGQTBBQjMwODg2QkQ5ODU0QzYyMTg5QjI2NDQKPj4Kc3RhcnR4cmVmCjc4NQolJUVPRgo="} | | users | [{"identify":{"email":"signer1@domain.test"}},{"identify":{"account":"signer1"}}] | | name | document | + And fetch field "(FILE_UUID)data.uuid" from prevous JSON response And the response should have a status code 200 When sending "get" to ocs "/apps/libresign/api/v1/file/list" Then the response of file list match with: From baf32b9616d72db746ac3fe3ff9f24d94e6e6df9 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Fri, 22 Mar 2024 14:22:39 -0300 Subject: [PATCH 6/8] Recactor integration tests to cover notifications of new and changed file Signed-off-by: Vitor Mattos --- .../integration/features/sign/request.feature | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/integration/features/sign/request.feature b/tests/integration/features/sign/request.feature index 1a5f47a6a3..f12452cef2 100644 --- a/tests/integration/features/sign/request.feature +++ b/tests/integration/features/sign/request.feature @@ -195,12 +195,28 @@ Feature: request-signature When as user "signer1" Then sending "get" to ocs "/apps/notifications/api/v2/notifications" And the response should be a JSON array with the following mandatory values - | key | value | - | ocs | (jq).data\|.[].subject == "admin requested your signature on document"| + | key | value | + | ocs | (jq).data\|.[0].subject == "admin requested your signature on document"| + | ocs | (jq).data\|.[0].message == "" | When sending "get" to ocs "/apps/activity/api/v2/activity/libresign?since=0" Then the response should be a JSON array with the following mandatory values - | key | value | - | ocs | (jq).data\|.[].subject == "admin requested your signature on document"| + | key | value | + | ocs | (jq).data\|.[0].subject == "admin requested your signature on document"| + When as user "admin" + And sending "patch" to ocs "/apps/libresign/api/v1/request-signature" + | uuid | | + | users | [{"identify":{"account":"signer1"}}] | + And the response should have a status code 200 + When as user "signer1" + Then sending "get" to ocs "/apps/notifications/api/v2/notifications" + And the response should be a JSON array with the following mandatory values + | key | value | + | ocs | (jq).data\|.[0].subject == "admin requested your signature on document" | + | ocs | (jq).data\|.[0].message == "Changes have been made in a file that you have to sign."| + When sending "get" to ocs "/apps/activity/api/v2/activity/libresign?since=0" + Then the response should be a JSON array with the following mandatory values + | key | value | + | ocs | (jq).data\|.[0].subject == "admin made changes on document"| Scenario: Request to sign with error using account as identifier with invalid email Given as user "admin" From 3390b66792448128b552cef0d81466d10b0d37e1 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Fri, 22 Mar 2024 14:29:20 -0300 Subject: [PATCH 7/8] Remove unused method Signed-off-by: Vitor Mattos --- .../features/bootstrap/FeatureContext.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 32567ba67a..f7185f1ceb 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -142,17 +142,6 @@ protected function parseText(string $text): string { return $text; } - private function getFileUuidFromText(string $text): ?string { - if (!$this->isJson($text)) { - return ''; - } - $json = json_decode($text, true); - if (isset($json['sign']['uuid']) && $json['sign']['uuid']) { - return $this->file['uuid'] = $json['sign']['uuid']; - } - return ''; - } - /** * @Given the signer contains */ @@ -204,7 +193,7 @@ public function iChangeTheFile(TableNode $body): void { foreach ($body->getTable() as $key => $row) { $newBody[$key] = $row; if ($row[1] === '') { - $newBody[$key][1] = $this->file['uuid']; + $newBody[$key][1] = $this->fields['FILE_UUID']; } } $body = new TableNode($newBody); From a48e4f9d4439027954d060002d5473bf4369a006 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Fri, 22 Mar 2024 14:40:17 -0300 Subject: [PATCH 8/8] Remove unecessary step Signed-off-by: Vitor Mattos --- .../features/bootstrap/FeatureContext.php | 16 ---------------- tests/integration/features/sign/request.feature | 3 +-- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index f7185f1ceb..f8fc8471e0 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -185,22 +185,6 @@ public function iSendAFileToBeSigned(TableNode $body): void { $this->sendOCSRequest('post', '/apps/libresign/api/v1/request-signature', $body); } - /** - * @When I change the file - */ - public function iChangeTheFile(TableNode $body): void { - $newBody = []; - foreach ($body->getTable() as $key => $row) { - $newBody[$key] = $row; - if ($row[1] === '') { - $newBody[$key][1] = $this->fields['FILE_UUID']; - } - } - $body = new TableNode($newBody); - $this->sendOCSRequest('patch', '/apps/libresign/api/v1/request-signature', $body); - $realResponseArray = json_decode($this->response->getBody()->getContents(), true); - } - /** * @When follow the link on opened email */ diff --git a/tests/integration/features/sign/request.feature b/tests/integration/features/sign/request.feature index f12452cef2..ddc1735690 100644 --- a/tests/integration/features/sign/request.feature +++ b/tests/integration/features/sign/request.feature @@ -408,10 +408,9 @@ Feature: request-signature } } """ - And I change the file + And sending "patch" to ocs "/apps/libresign/api/v1/request-signature" | uuid | | | users | [{"identify":{"email":"signer1@domain.test"}}] | - | name | document | And the response should have a status code 200 When sending "get" to ocs "/apps/libresign/api/v1/file/list" Then the response of file list match with: