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
f6d704f
test: reproduce lost invitations for email signers with accounts
vitormattos Nov 10, 2026
a388ad0
fix: deliver invitations to explicit email signers
vitormattos Nov 10, 2026
1cff602
test: preserve account email notification preferences
vitormattos Nov 10, 2026
008ff31
refactor: centralize mail recipient resolution for sign events
vitormattos Nov 10, 2026
0631d39
test: assert mail notification intents at listener boundary
vitormattos Nov 10, 2026
85567fd
fix: preserve cancellation opt-outs for email-identified signers
vitormattos Nov 10, 2026
4abd5cb
test: verify cancellation policy and mail outputs without call-count …
vitormattos Nov 10, 2026
00da4c1
test: mock absence of account for external cancellation signer
vitormattos Nov 10, 2026
fe4cf30
fix: enforce admin email policy for email-identified invitations
vitormattos Nov 10, 2026
9c813b3
test: preserve notification event types and history ownership
vitormattos Nov 10, 2026
6c2f762
test: isolate Behat email invitation admin settings
vitormattos Nov 10, 2026
4720412
test: assert invitation type in admin email preference check
vitormattos Nov 14, 2026
99173ab
refactor: clarify mail recipient resolution by identifier
vitormattos Nov 14, 2026
d07d017
refactor: make email recipient policy self-documenting
vitormattos Nov 14, 2026
62246f1
fix(mail): honor resolved recipient policy on stable34
vitormattos Nov 14, 2026
d49b647
test(mail): adapt recipient policy regressions to stable34 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