Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
63 changes: 63 additions & 0 deletions lib/Controller/IdentifyAccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\Collaboration\Collaborators\ISearch;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Share\IShare;

Expand All @@ -36,6 +38,8 @@ public function __construct(
private IURLGenerator $urlGenerator,
private Email $identifyEmailMethod,
private Account $identifyAccountMethod,
private IUserManager $userManager,
private IConfig $config,
) {
parent::__construct(Application::APP_ID, $request);
}
Expand Down Expand Up @@ -76,6 +80,7 @@ public function search(string $search = '', string $method = '', int $page = 1,
$return = $this->addHerselfAccount($return, $search);
$return = $this->addHerselfEmail($return, $search);
$return = $this->replaceShareTypeByMethod($return);
$return = $this->addEmailNotificationPreference($return);
$return = $this->excludeNotAllowed($return);

return new DataResponse($return);
Expand Down Expand Up @@ -239,4 +244,62 @@ private function replaceShareTypeByMethod(array $list): array {
}
return $list;
}

private function addEmailNotificationPreference(array $list): array {
foreach ($list as $key => $item) {
if ($item['method'] !== 'account') {
continue;
}

$user = $this->userManager->get($item['id']);
if ($user === null) {
$list[$key]['acceptsEmailNotifications'] = false;
continue;
}

$email = $user->getEMailAddress();
if (empty($email)) {
$list[$key]['acceptsEmailNotifications'] = false;
continue;
}

if ($this->isNotificationDisabledAtActivity($user->getUID(), 'libresign_file_to_sign')) {
$list[$key]['acceptsEmailNotifications'] = false;
continue;
}

$list[$key]['acceptsEmailNotifications'] = true;
}
return $list;
}

private function isNotificationDisabledAtActivity(string $userId, string $type): bool {
if (!class_exists(\OCA\Activity\UserSettings::class)) {
return false;
}
$activityUserSettings = \OCP\Server::get(\OCA\Activity\UserSettings::class);
if ($activityUserSettings) {
$manager = \OCP\Server::get(\OCP\Activity\IManager::class);
try {
$manager->getSettingById($type);
} catch (\Exception $e) {
return false;
}

$adminSetting = $activityUserSettings->getAdminSetting('email', $type);
if (!$adminSetting) {
return true;
}

$notificationSetting = $activityUserSettings->getUserSetting(
$userId,
'email',
$type
);
if (!$notificationSetting) {
return true;
}
}
return false;
}
}
1 change: 1 addition & 0 deletions lib/Db/IdentifyMethodMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function searchByIdentifierValue(string $search, string $userId, string $
->join('im', 'libresign_sign_request', 'sr',
$qb->expr()->eq('sr.id', 'im.sign_request_id'),
)
->where($qb->expr()->neq('im.identifier_value', $qb->createNamedParameter('deleted_users')))
->setMaxResults($limit)
->setFirstResult($offset);

Expand Down
9 changes: 8 additions & 1 deletion lib/Db/SignRequestMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,17 @@ public function incrementNotificationCounter(SignRequest $signRequest, string $m
if (!isset($metadata['notify'])) {
$this->firstNotification = true;
}
$metadata['notify'][] = [

$notificationEntry = [
'method' => $method,
'date' => time(),
];

if (!empty($fromDatabase->getDescription())) {
$notificationEntry['description'] = $fromDatabase->getDescription();
}

$metadata['notify'][] = $notificationEntry;
$fromDatabase->setMetadata($metadata);
$this->update($fromDatabase);
$this->db->commit();
Expand Down
15 changes: 13 additions & 2 deletions lib/Listener/MailNotifyListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ protected function sendSignMailNotification(

$isFirstNotification = $this->signRequestMapper->incrementNotificationCounter($signRequest, 'mail');
if ($isFirstNotification) {
$this->mail->notifyUnsignedUser($signRequest, $email);
$this->mail->notifyUnsignedUser($signRequest, $email, $signRequest->getDescription());
return;
}
$this->mail->notifySignDataUpdated($signRequest, $email);
$this->mail->notifySignDataUpdated($signRequest, $email, $signRequest->getDescription());
} catch (\InvalidArgumentException $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
return;
Expand Down Expand Up @@ -173,6 +173,17 @@ private function isNotificationDisabledAtActivity(string $userId, string $type):
}
$activityUserSettings = \OCP\Server::get(\OCA\Activity\UserSettings::class);
if ($activityUserSettings) {
$manager = \OCP\Server::get(\OCP\Activity\IManager::class);
try {
$manager->getSettingById($type);
} catch (\Exception $e) {
return false;
}

$adminSetting = $activityUserSettings->getAdminSetting('email', $type);
if (!$adminSetting) {
return true;
}
$notificationSetting = $activityUserSettings->getUserSetting(
$userId,
'email',
Expand Down
14 changes: 12 additions & 2 deletions lib/Listener/NotificationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,23 @@ private function isNotificationDisabledAtActivity(string $userId, string $type):
}
$activityUserSettings = \OCP\Server::get(\OCA\Activity\UserSettings::class);
if ($activityUserSettings) {
$manager = \OCP\Server::get(\OCP\Activity\IManager::class);
try {
$manager->getSettingById($type);
} catch (\Exception $e) {
return false;
}

$adminSetting = $activityUserSettings->getAdminSetting('notification', $type);
if (!$adminSetting) {
return true;
}

$notificationSetting = $activityUserSettings->getUserSetting(
$userId,
'notification',
$type
);
// If setting is explicitly false, notifications are disabled
// If setting is null/not configured, notifications are enabled by default
if ($notificationSetting === false) {
return true;
}
Expand Down
10 changes: 8 additions & 2 deletions lib/Listener/TwofactorGatewayListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,16 @@ protected function sendSignNotification(
}

$isFirstNotification = $this->signRequestMapper->incrementNotificationCounter($signRequest, $entity->getIdentifierKey());

$message = '';
if (!empty($signRequest->getDescription())) {
$message = $signRequest->getDescription() . "\n\n";
}

if ($isFirstNotification) {
$message = $this->l10n->t('There is a document for you to sign. Access the link below:');
$message .= $this->l10n->t('There is a document for you to sign. Access the link below:');
} else {
$message = $this->l10n->t('Changes have been made in a file that you have to sign. Access the link below:');
$message .= $this->l10n->t('Changes have been made in a file that you have to sign. Access the link below:');
}
$message .= "\n";
$link = $this->urlGenerator->linkToRouteAbsolute('libresign.page.sign', ['uuid' => $signRequest->getUuid()]);
Expand Down
4 changes: 4 additions & 0 deletions lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
* email?: string,
* account?: string,
* },
* displayName?: string,
* description?: string,
* notify?: non-negative-int,
* signingOrder?: non-negative-int,
* }
* @psalm-type LibresignNewFile = array{
Expand Down Expand Up @@ -55,6 +58,7 @@
* subname: string,
* shareType: 0|4,
* icon?: 'icon-mail'|'icon-user',
* acceptsEmailNotifications?: boolean,
* }
* @psalm-type LibresignPagination = array{
* total: non-negative-int,
Expand Down
16 changes: 14 additions & 2 deletions lib/Service/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ private function getFileById(int $fileId): File {
/**
* @psalm-suppress MixedMethodCall
*/
public function notifySignDataUpdated(SignRequest $data, string $email): void {
public function notifySignDataUpdated(SignRequest $data, string $email, ?string $description = null): void {
$emailTemplate = $this->mailer->createEMailTemplate('settings.TestEmail');
// TRANSLATORS The subject of the email that is sent after changes are made to the signature request that may affect something for the signer who will sign the document. Some possible reasons: URL for signature changed (when the URL expires), the person who requested the signature sent a notification
$emailTemplate->setSubject($this->l10n->t('LibreSign: Changes into a file for you to sign'));
$emailTemplate->addHeader();
$emailTemplate->addHeading($this->l10n->t('File to sign'), false);

if (!empty($description)) {
$emailTemplate->addBodyText($description);
$emailTemplate->addBodyText('');
}

$emailTemplate->addBodyText($this->l10n->t('Changes have been made in a file that you have to sign. Access the link below:'));
$link = $this->urlGenerator->linkToRouteAbsolute('libresign.page.sign', ['uuid' => $data->getUuid()]);
$file = $this->getFileById($data->getFileId());
Expand All @@ -76,11 +82,17 @@ public function notifySignDataUpdated(SignRequest $data, string $email): void {
/**
* @psalm-suppress MixedMethodCall
*/
public function notifyUnsignedUser(SignRequest $data, string $email): void {
public function notifyUnsignedUser(SignRequest $data, string $email, ?string $description = null): void {
$emailTemplate = $this->mailer->createEMailTemplate('settings.TestEmail');
$emailTemplate->setSubject($this->l10n->t('LibreSign: There is a file for you to sign'));
$emailTemplate->addHeader();
$emailTemplate->addHeading($this->l10n->t('File to sign'), false);

if (!empty($description)) {
$emailTemplate->addBodyText($description);
$emailTemplate->addBodyText('');
}

$emailTemplate->addBodyText($this->l10n->t('There is a document for you to sign. Access the link below:'));
$link = $this->urlGenerator->linkToRouteAbsolute('libresign.page.sign', ['uuid' => $data->getUuid()]);
$file = $this->getFileById($data->getFileId());
Expand Down
14 changes: 14 additions & 0 deletions openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@
"icon-mail",
"icon-user"
]
},
"acceptsEmailNotifications": {
"type": "boolean"
}
}
},
Expand Down Expand Up @@ -514,6 +517,17 @@
}
}
},
"displayName": {
"type": "string"
},
"description": {
"type": "string"
},
"notify": {
"type": "integer",
"format": "int64",
"minimum": 0
},
"signingOrder": {
"type": "integer",
"format": "int64",
Expand Down
14 changes: 14 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@
"icon-mail",
"icon-user"
]
},
"acceptsEmailNotifications": {
"type": "boolean"
}
}
},
Expand Down Expand Up @@ -444,6 +447,17 @@
}
}
},
"displayName": {
"type": "string"
},
"description": {
"type": "string"
},
"notify": {
"type": "integer",
"format": "int64",
"minimum": 0
},
"signingOrder": {
"type": "integer",
"format": "int64",
Expand Down
Loading
Loading