Skip to content

Commit

Permalink
fix(ShareAPI): Send mails for mail shares by default
Browse files Browse the repository at this point in the history
It looks like, the frontend it needs to provide the `sendMail` param
for the backend to decide wether mails would be sent.

Our UI does not have that at the moment so it should default to sending
emails always for mail shares.

Not exactly sure how this was handled earlier but this is a good starting point.

Resolves : #48012

Signed-off-by: fenn-cs <[email protected]>
  • Loading branch information
Fenn-CS committed Oct 7, 2024
1 parent 363ba6b commit 91a3ce1
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,16 @@ public function createShare(
$this->checkInheritedAttributes($share);

// Handle mail send
if ($sendMail === 'true' || $sendMail === 'false') {
if (is_null($sendMail)) {
// Define a default behavior when sendMail is not provided
if ($shareType === IShare::TYPE_EMAIL) {
// For email shares, the default is to send the mail
$share->setMailSend(true);
} else {
// For all other share types, the default is to not send the mail
$share->setMailSend(false);
}
} else {
$share->setMailSend($sendMail === 'true');
}

Expand Down Expand Up @@ -718,7 +727,7 @@ public function createShare(
}

// Only share by mail have a recipient
if (is_string($shareWith) && $shareType === IShare::TYPE_EMAIL) {
if (!empty($shareWith) && !is_null($shareWith) && $shareType === IShare::TYPE_EMAIL) {

Check failure on line 730 in apps/files_sharing/lib/Controller/ShareAPIController.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

RedundantCondition

apps/files_sharing/lib/Controller/ShareAPIController.php:730:8: RedundantCondition: Type non-falsy-string for $shareWith is never null (see https://psalm.dev/122)
// If sending a mail have been requested, validate the mail address
if ($share->getMailSend() && !$this->mailer->validateMailAddress($shareWith)) {
throw new OCSNotFoundException($this->l->t('Please specify a valid email address'));
Expand Down Expand Up @@ -1218,11 +1227,6 @@ public function updateShare(
}
$this->checkInheritedAttributes($share);

// Handle mail send
if ($sendMail === 'true' || $sendMail === 'false') {
$share->setMailSend($sendMail === 'true');
}

/**
* expirationdate, password and publicUpload only make sense for link shares
*/
Expand Down

0 comments on commit 91a3ce1

Please sign in to comment.