Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
74e1464
test: reproduce lost invitations for email signers with accounts
vitormattos Nov 10, 2026
1db9575
fix: deliver invitations to explicit email signers
vitormattos Nov 10, 2026
3caae58
test: preserve account email notification preferences
vitormattos Nov 10, 2026
e7cb695
refactor: centralize mail recipient resolution for sign events
vitormattos Nov 10, 2026
edf2f16
test: assert mail notification intents at listener boundary
vitormattos Nov 10, 2026
7f77c0b
fix: preserve cancellation opt-outs for email-identified signers
vitormattos Nov 10, 2026
34310bc
test: verify cancellation policy and mail outputs without call-count …
vitormattos Nov 10, 2026
dceb11b
test: mock absence of account for external cancellation signer
vitormattos Nov 10, 2026
8b091a3
fix: enforce admin email policy for email-identified invitations
vitormattos Nov 10, 2026
2bbf731
test: preserve notification event types and history ownership
vitormattos Nov 10, 2026
18f92ed
test: isolate Behat email invitation admin settings
vitormattos Nov 10, 2026
c47cc81
test: assert invitation type in admin email preference check
vitormattos Nov 14, 2026
00228af
refactor: clarify mail recipient resolution by identifier
vitormattos Nov 14, 2026
503c887
refactor: make email recipient policy self-documenting
vitormattos Nov 14, 2026
64334bd
fix(mail): honor resolved recipient policy on stable35
vitormattos Nov 14, 2026
dc199b7
test(mail): adapt recipient policy regressions to stable35 notificati…
vitormattos Nov 14, 2026
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
113 changes: 62 additions & 51 deletions lib/Listener/MailNotifyListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
use OCP\EventDispatcher\IEventListener;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use Psr\Log\LoggerInterface;

/** @template-implements IEventListener<Event> */
class MailNotifyListener implements IEventListener {
public function __construct(
protected IUserSession $userSession,
protected IUserManager $userManager,
protected IdentifyService $identifyService,
protected MailService $mail,
Expand Down Expand Up @@ -65,34 +63,11 @@ protected function sendSignMailNotification(
IIdentifyMethod $identifyMethod,
): void {
try {
if ($identifyMethod->getEntity()->isDeletedAccount()) {
return;
}
$email = '';
if ($identifyMethod->getName() === 'account') {
$userId = $identifyMethod->getEntity()->getIdentifierValue();
$email = $this->userManager
->get($userId)
->getEMailAddress();
} elseif ($identifyMethod->getName() === 'email') {
$email = $identifyMethod->getEntity()->getIdentifierValue();
}
if (empty($email)) {
$email = $this->resolveEligibleRecipientEmail($identifyMethod, SendSignNotificationEvent::FILE_TO_SIGN);
if ($email === null) {
return;
}

$users = $this->userManager->getByEmail($email);
if (count($users) === 1) {
$userId = $users[0]->getUID();
if ($this->notificationPreferenceResolver->isEmailNotificationDisabled(
$userId,
SendSignNotificationEvent::FILE_TO_SIGN,
true,
)) {
return;
}
}

$isFirstNotification = $this->signRequestMapper->incrementNotificationCounter($signRequest, 'mail');
if ($isFirstNotification) {
$this->mail->notifyUnsignedUser($signRequest, $email, $signRequest->getDescription());
Expand Down Expand Up @@ -146,38 +121,74 @@ protected function sendCanceledMailNotification(
FileEntity $libreSignFile,
): void {
try {
if ($identifyMethod->getEntity()->isDeletedAccount()) {
return;
}

$email = '';
if ($identifyMethod->getName() === 'account') {
$userId = $identifyMethod->getEntity()->getIdentifierValue();
$user = $this->userManager->get($userId);
if ($user) {
$email = $user->getEMailAddress();
}
} elseif ($identifyMethod->getName() === 'email') {
$email = $identifyMethod->getEntity()->getIdentifierValue();
}

if (empty($email)) {
$email = $this->resolveEligibleRecipientEmail($identifyMethod, SignRequestCanceledEvent::SIGN_REQUEST_CANCELED);
if ($email === null) {
return;
}

$users = $this->userManager->getByEmail($email);
if (count($users) === 1) {
$userId = $users[0]->getUID();
if ($this->notificationPreferenceResolver->isEmailNotificationDisabled($userId, SignRequestCanceledEvent::SIGN_REQUEST_CANCELED, true)) {
return;
}
}

$this->mail->notifyCanceledRequest($signRequest, $email, $libreSignFile);

} catch (\InvalidArgumentException $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
return;
}
}

private function resolveEligibleRecipientEmail(IIdentifyMethod $identifyMethod, string $notificationType): ?string {
$entity = $identifyMethod->getEntity();
if ($entity->isDeletedAccount()) {
return null;
}

return match ($identifyMethod->getName()) {
'email' => $this->resolveEmailIdentifiedRecipient($entity->getIdentifierValue(), $notificationType),
'account' => $this->resolveAccountIdentifiedRecipient($entity->getIdentifierValue(), $notificationType),
default => null,
};
}

private function resolveEmailIdentifiedRecipient(string $email, string $notificationType): ?string {
if ($email === '') {
return null;
}

$disabled = match ($notificationType) {
SendSignNotificationEvent::FILE_TO_SIGN
=> $this->notificationPreferenceResolver->isEmailNotificationGloballyDisabled($notificationType),
SignRequestCanceledEvent::SIGN_REQUEST_CANCELED
=> $this->isCancellationDisabledForUniqueLinkedAccount($email),
default => true,
};

return $disabled ? null : $email;
}

private function resolveAccountIdentifiedRecipient(string $uid, string $notificationType): ?string {
$user = $this->userManager->get($uid);
if (!$user instanceof IUser) {
return null;
}
$email = $user->getEMailAddress();
if (empty($email) || $this->notificationPreferenceResolver->isEmailNotificationDisabled(
$user->getUID(),
$notificationType,
true,
)) {
return null;
}
return $email;
}

private function isCancellationDisabledForUniqueLinkedAccount(string $email): bool {
$users = $this->userManager->getByEmail($email);
if (count($users) !== 1) {
return false;
}

return $this->notificationPreferenceResolver->isEmailNotificationDisabled(
$users[0]->getUID(),
SignRequestCanceledEvent::SIGN_REQUEST_CANCELED,
true,
);
}
}
19 changes: 19 additions & 0 deletions lib/Service/NotificationPreferenceResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ public function isEmailNotificationDisabled(
return $this->isNotificationDisabled($userId, 'email', $type, $requireKnownActivitySetting);
}

/**
* Apply the administrator's mail policy without consulting a linked user's opt-out.
*/
public function isEmailNotificationGloballyDisabled(
string $type,
bool $requireKnownActivitySetting = true,
): bool {
if ($this->activitySettingsStore->isAvailable()) {
if ($requireKnownActivitySetting && !$this->activitySettingsStore->hasSetting($type)) {
return false;
}
return !$this->isActivitySettingEnabled($this->activitySettingsStore->getAdminSetting('email', $type));
}

return !$this->isActivitySettingEnabled(
$this->appConfig->getValueString('activity', sprintf('notify_email_%s', $type), '1'),
);
}

public function isInAppNotificationDisabled(
string $userId,
string $type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,4 @@ Feature: search
| (jq).ocs.data[0].identify | notification-global-off |
| (jq).ocs.data[0].method | account |
| (jq).ocs.data[0].acceptsEmailNotifications | false |
And run the command "config:app:set activity notify_email_libresign_file_to_sign --value=1" with result code 0
1 change: 1 addition & 0 deletions tests/integration/features/page/validate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Feature: page/validate

Scenario: Unauthenticated email signer can fetch PDF and gets controlled error after source deletion
Given as user "admin"
And run the command "config:app:set activity notify_email_libresign_file_to_sign --value=1" with result code 0
And sending "post" to ocs "/apps/libresign/api/v1/policies/system/identify_methods"
| value | (string){"can_create_account":false,"factors":[{"name":"email","enabled":true,"requirement":"required","signatureMethods":{"clickToSign":{"enabled":true}}}]} |
And my inbox is empty
Expand Down
Loading
Loading