diff --git a/services/notifications/pkg/email/templates.go b/services/notifications/pkg/email/templates.go index 89a1ed01a4..38af45ed85 100644 --- a/services/notifications/pkg/email/templates.go +++ b/services/notifications/pkg/email/templates.go @@ -86,6 +86,23 @@ The link and the PIN are only valid for 30 minutes.`), CallToAction: l10n.Template(`Click here to view it: {ShareLink}`), } + GuestLinkShareRenewedWithoutPin = MessageTemplate{ + textTemplate: _textTemplate, + htmlTemplate: _htmlTemplate, + // GuestLinkShareRenewedWithoutPin email template, Subject field (resolves directly) + Subject: l10n.Template(`Your new link to '{ShareFolder}'`), + // GuestLinkShareRenewedWithoutPin email template, resolves via {{ .Greeting }} + Greeting: l10n.Template(`Hello,`), + // GuestLinkShareRenewedWithoutPin email template, resolves via {{ .MessageBody }} + MessageBody: l10n.Template(`A new link to "{ShareFolder}", shared with you by {ShareSharer}, has been requested. + +The link below is personal and can only be used once. Please do not forward it. + +The link is only valid for 30 minutes.`), + // GuestLinkShareRenewedWithoutPin email template, resolves via {{ .CallToAction }} + CallToAction: l10n.Template(`Click here to view it: {ShareLink}`), + } + // Spaces templates SharedSpace = MessageTemplate{ textTemplate: _textTemplate, diff --git a/services/notifications/pkg/service/guestlinks.go b/services/notifications/pkg/service/guestlinks.go index 3c4cb7f85a..af7e9135b5 100644 --- a/services/notifications/pkg/service/guestlinks.go +++ b/services/notifications/pkg/service/guestlinks.go @@ -29,8 +29,9 @@ func (s eventsNotifier) handleGuestTokenCreated(e ocevents.GuestTokenCreated) { s.sendGuestLinkMail(logger, email.GuestLinkShareCreated, e.Sharer, e.GranteeEmail, e.ItemID, e.ResourceName, e.Token, nil) } -// handleGuestTokenRenewed sends the renewed guest link and the PIN to the -// guest's email address, like handleGuestTokenCreated. +// handleGuestTokenRenewed sends the renewed guest link to the guest's email +// address, like handleGuestTokenCreated. The event only carries a PIN when the +// renewal was authorized by a guest session; otherwise just the link is sent. func (s eventsNotifier) handleGuestTokenRenewed(e ocevents.GuestTokenRenewed) { logger := s.logger.With(). Str("event", "GuestTokenRenewed"). @@ -38,7 +39,7 @@ func (s eventsNotifier) handleGuestTokenRenewed(e ocevents.GuestTokenRenewed) { Logger() if e.Pin == "" { - logger.Error().Msg("guest pin is empty") + s.sendGuestLinkMail(logger, email.GuestLinkShareRenewedWithoutPin, e.Sharer, e.GranteeEmail, e.ItemID, "", e.Token, nil) return } diff --git a/services/notifications/pkg/service/service_test.go b/services/notifications/pkg/service/service_test.go index bb19fc8306..5b7de3bc44 100644 --- a/services/notifications/pkg/service/service_test.go +++ b/services/notifications/pkg/service/service_test.go @@ -371,6 +371,36 @@ https://opencloud.eu Pin: "123456", }, }), + + Entry("Guest Token Renewed without PIN", testChannel{ + expectedReceipients: []string{"guest@example.com"}, + expectedSubject: "Your new link to 'secrets of the board'", + expectedTextBody: `Hello, + +A new link to "secrets of the board", shared with you by Dr. S. Harer, has been requested. + +The link below is personal and can only be used once. Please do not forward it. + +The link is only valid for 30 minutes. + +Click here to view it: https://cloud.example.com/g/v1.sharehash.newsecret + + +--- +OpenCloud - a safe home for all your data +https://opencloud.eu +`, + expectedSender: sharer.GetDisplayName(), + expectedLink: testOpenCloudURL + "/g/v1.sharehash.newsecret", + done: make(chan struct{}), + }, events.Event{ + Event: ocEvents.GuestTokenRenewed{ + Sharer: sharer.GetId(), + GranteeEmail: "guest@example.com", + ItemID: resourceid, + Token: "v1.sharehash.newsecret", + }, + }), ) })