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
2a5af83
test: reproduce lost invitations for email signers with accounts
vitormattos Nov 10, 2026
a687c13
fix: deliver invitations to explicit email signers
vitormattos Nov 10, 2026
e505b14
test: preserve account email notification preferences
vitormattos Nov 10, 2026
d301a4e
refactor: centralize mail recipient resolution for sign events
vitormattos Nov 10, 2026
076bcc9
test: assert mail notification intents at listener boundary
vitormattos Nov 10, 2026
84d5f89
fix: preserve cancellation opt-outs for email-identified signers
vitormattos Nov 10, 2026
f10a071
test: verify cancellation policy and mail outputs without call-count …
vitormattos Nov 10, 2026
749dcd4
test: mock absence of account for external cancellation signer
vitormattos Nov 10, 2026
e11900f
fix: enforce admin email policy for email-identified invitations
vitormattos Nov 10, 2026
67f698f
test: preserve notification event types and history ownership
vitormattos Nov 10, 2026
a70c85a
test: isolate Behat email invitation admin settings
vitormattos Nov 10, 2026
b01fbdc
test: assert invitation type in admin email preference check
vitormattos Nov 14, 2026
5819ac1
refactor: clarify mail recipient resolution by identifier
vitormattos Nov 14, 2026
a579308
refactor: make email recipient policy self-documenting
vitormattos Nov 14, 2026
da8918d
fix(mail): honor resolved recipient policy on stable33
vitormattos Nov 14, 2026
2dcdef5
test(mail): adapt recipient policy regressions to stable33 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 @@ -169,3 +169,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
Loading
Loading