Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reuse share object instead of getting it again when sending invite mail #1122

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions lib/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ public function handlePostShare(ShareCreatedEvent $event): void {
$this->mail->sendGuestInviteMail(
$uid,
$shareWith,
$share->getNodeType(),
$share->getNodeId(),
$share,
$token,
$lang
);
Expand Down
25 changes: 9 additions & 16 deletions lib/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __construct(
* @param $uid
* @throws \Exception
*/
public function sendGuestInviteMail(string $uid, string $shareWith, string $itemType, string $itemSource, string $token, string $language = ''): void {
public function sendGuestInviteMail(string $uid, string $shareWith, Share\IShare $share, string $token, string $language = ''): void {
if ($language === '') {
$language = null;
}
Expand All @@ -99,25 +99,18 @@ public function sendGuestInviteMail(string $uid, string $shareWith, string $item

$targetUser = $this->userManager->get($shareWith);
$shareWithEmail = $targetUser->getEMailAddress();
if (!$shareWithEmail) {
throw new \Exception("Guest user created without email");
}
$replyTo = $this->userManager->get($uid)->getEMailAddress();
$senderDisplayName = $this->userSession->getUser()->getDisplayName();

$items = Share::getItemSharedWithUser($itemType, $itemSource, $shareWith);
$filename = trim($items[0]['file_target'], '/');
$subject = (string)$l10n->t('%s shared »%s« with you', [$senderDisplayName, $filename]);
$expiration = null;
if (isset($items[0]['expiration'])) {
try {
$date = new \DateTime($items[0]['expiration']);
$expiration = $date->getTimestamp();
} catch (\Exception $e) {
$this->logger->error("Couldn't read date: " . $e->getMessage(), ['app' => 'sharing']);
}
}

$filename = trim($share->getTarget(), '/');
$subject = $l10n->t('%s shared »%s« with you', [$senderDisplayName, $filename]);
$expiration = $share->getExpirationDate();

$link = $this->urlGenerator->linkToRouteAbsolute(
'files.viewcontroller.showFile', ['fileid' => $itemSource]
'files.viewcontroller.showFile', ['fileid' => $share->getNodeId()]
);

$emailTemplate = $this->mailer->createEMailTemplate('guest.invite');
Expand Down Expand Up @@ -163,7 +156,7 @@ public function sendGuestInviteMail(string $uid, string $shareWith, string $item
$message->setPlainBody($emailTemplate->renderText());
$message->setFrom([
Util::getDefaultEmailAddress('sharing-noreply') =>
(string)$l10n->t('%s via %s', [
$l10n->t('%s via %s', [
$senderDisplayName,
$this->defaults->getName()
]),
Expand Down
15 changes: 1 addition & 14 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.14.1@b9d355e0829c397b9b3b47d0c0ed042a8a70284d">
<files psalm-version="5.21.1@8c473e2437be8b6a8fd8f630f0f11a16b114c494">
<file src="lib/AppConfigOverwrite.php">
<MethodSignatureMismatch>
<code>public function getValue($app, $key, $default = null) {</code>
Expand All @@ -10,19 +10,6 @@
<code>listen</code>
</UndefinedInterfaceMethod>
</file>
<file src="lib/AppWhitelist.php">
<UndefinedMethod/>
</file>
<file src="lib/Hooks.php">
<InvalidScalarArgument>
<code><![CDATA[$share->getNodeId()]]></code>
</InvalidScalarArgument>
</file>
<file src="lib/Mail.php">
<MissingDependency>
<code>Share</code>
</MissingDependency>
</file>
<file src="lib/RestrictionManager.php">
<UndefinedClass>
<code>ExternalMountPoint</code>
Expand Down
Loading