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 <fenn25.fn@gmail.com>
  • Loading branch information
nfebe committed Oct 24, 2024
1 parent a1efa39 commit dd82bef
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 @@ -659,7 +659,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 && strlen($shareWith) !== 0) {
// 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 @@ -719,7 +728,7 @@ public function createShare(
}

// Only share by mail have a recipient
if (is_string($shareWith) && $shareType === IShare::TYPE_EMAIL) {
if (!empty($shareWith) && $shareType === IShare::TYPE_EMAIL) {
// 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 @@ -1219,11 +1228,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 dd82bef

Please sign in to comment.