Skip to content
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require (
github.com/go-playground/validator/v10 v10.30.3
github.com/go-resty/resty/v2 v2.17.2
github.com/go-viper/mapstructure/v2 v2.5.0
github.com/gofrs/flock v0.13.1
github.com/golang-jwt/jwt/v5 v5.3.1
github.com/golang/protobuf v1.5.4
github.com/google/go-cmp v0.7.0
Expand Down Expand Up @@ -65,7 +66,7 @@ require (
github.com/open-policy-agent/opa v1.19.1
github.com/opencloud-eu/icap-client v0.0.0-20250930132611-28a2afe62d89
github.com/opencloud-eu/libre-graph-api-go v1.0.8
github.com/opencloud-eu/reva/v2 v2.51.0
github.com/opencloud-eu/reva/v2 v2.51.1-0.20261006112042-7d9dd4c07424
github.com/opensearch-project/opensearch-go/v4 v4.7.3
github.com/orcaman/concurrent-map v1.0.0
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -229,7 +230,6 @@ require (
github.com/gobwas/ws v1.4.0 // indirect
github.com/goccy/go-json v0.10.6 // indirect
github.com/goccy/go-yaml v1.19.2 // indirect
github.com/gofrs/flock v0.13.1 // indirect
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/golang/snappy v1.0.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,8 @@ github.com/opencloud-eu/icap-client v0.0.0-20250930132611-28a2afe62d89 h1:W1ms+l
github.com/opencloud-eu/icap-client v0.0.0-20250930132611-28a2afe62d89/go.mod h1:vigJkNss1N2QEceCuNw/ullDehncuJNFB6mEnzfq9UI=
github.com/opencloud-eu/libre-graph-api-go v1.0.8 h1:VTkFLkLNna+T4RN6JUZnVQ1bqVAfPtMeORXbFzEYGKs=
github.com/opencloud-eu/libre-graph-api-go v1.0.8/go.mod h1:lTM8JeGblNpoMySTW7Lui2+c5TTLI95mwxtdUIHHrhU=
github.com/opencloud-eu/reva/v2 v2.51.0 h1:PbvUtLlbCpS5em48cSGk2sHRdjVA7htRQVKjpckI2w4=
github.com/opencloud-eu/reva/v2 v2.51.0/go.mod h1:ngLsDakKnt8zCFCeULhuSZFESGy5NIuSq5/JGeOhPdU=
github.com/opencloud-eu/reva/v2 v2.51.1-0.20261006112042-7d9dd4c07424 h1:rvopdGQTsI0PT7P3MRamrDsO1yYIKJBOxJAbbYmc4P8=
github.com/opencloud-eu/reva/v2 v2.51.1-0.20261006112042-7d9dd4c07424/go.mod h1:ngLsDakKnt8zCFCeULhuSZFESGy5NIuSq5/JGeOhPdU=
github.com/opencloud-eu/secure v0.0.0-20260312082735-b6f5cb2244e4 h1:l2oB/RctH+t8r7QBj5p8thfEHCM/jF35aAY3WQ3hADI=
github.com/opencloud-eu/secure v0.0.0-20260312082735-b6f5cb2244e4/go.mod h1:BmF5hyM6tXczk3MpQkFf1hpKSRqCyhqcbiQtiAF7+40=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
Expand Down
3 changes: 3 additions & 0 deletions services/frontend/pkg/revaconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ func FrontendConfigFromStruct(cfg *config.Config, logger log.Logger) (map[string
"outgoing": cfg.EnableFederatedSharingOutgoing,
"incoming": cfg.EnableFederatedSharingIncoming,
},
"guest_links": map[string]any{
"enabled": cfg.Commons.EnableGuestLinks,
},
},
"spaces": map[string]any{
"version": "1.0.0",
Expand Down
1 change: 1 addition & 0 deletions services/notifications/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func Server(cfg *config.Config) *cobra.Command {
events.ScienceMeshInviteTokenGenerated{},
events.SendEmailsEvent{},
ocEvents.ResourceMention{},
ocEvents.GuestTokenCreated{},
}
registeredEvents := make(map[string]events.Unmarshaller)
for _, e := range evs {
Expand Down
18 changes: 18 additions & 0 deletions services/notifications/pkg/email/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ Even though this share has been revoked you still might have access through othe
Even though this share has been revoked you still might have access through other shares and/or space memberships.`),
}

// Guest link templates
GuestLinkShareCreated = MessageTemplate{
textTemplate: _textTemplate,
htmlTemplate: _htmlTemplate,
// GuestLinkShareCreated email template, Subject field (resolves directly)
Subject: l10n.Template(`{ShareSharer} shared '{ShareFolder}' with you`),
// GuestLinkShareCreated email template, resolves via {{ .Greeting }}
Greeting: l10n.Template(`Hello,`),
// GuestLinkShareCreated email template, resolves via {{ .MessageBody }}
MessageBody: l10n.Template(`{ShareSharer} has shared "{ShareFolder}" with you.

The link below is personal and can only be used once. Please do not forward it.

The link is only valid for 30 minutes.`),
// GuestLinkShareCreated email template, resolves via {{ .CallToAction }}
CallToAction: l10n.Template(`Click here to view it: {ShareLink}`),
}

// Spaces templates
SharedSpace = MessageTemplate{
textTemplate: _textTemplate,
Expand Down
84 changes: 84 additions & 0 deletions services/notifications/pkg/service/guestlinks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2026 OpenCloud GmbH <mail@opencloud.eu>
// SPDX-License-Identifier: Apache-2.0

package service

import (
"context"

"github.com/opencloud-eu/reva/v2/pkg/utils"
"google.golang.org/protobuf/types/known/fieldmaskpb"

ocevents "github.com/opencloud-eu/opencloud/pkg/events"
"github.com/opencloud-eu/opencloud/services/notifications/pkg/channels"
"github.com/opencloud-eu/opencloud/services/notifications/pkg/email"
)

// handleGuestTokenCreated sends the guest link to the guest's email address.
// Guests have no account, settings or locale, so the mail is always sent
// instantly (the token is short-lived) in the default language.
func (s eventsNotifier) handleGuestTokenCreated(e ocevents.GuestTokenCreated) {
logger := s.logger.With().
Str("event", "GuestTokenCreated").
Str("itemid", e.ItemID.GetOpaqueId()).
Logger()

if err := validate.Var(e.GranteeEmail, "required,email"); err != nil {
logger.Error().Err(err).Msg("invalid guest email address")
return
}
if e.Token == "" {
logger.Error().Msg("guest token is empty")
return
}

gatewayClient, err := s.gatewaySelector.Next()
if err != nil {
logger.Error().Err(err).Msg("could not select next gateway client")
return
}

ctx, err := utils.GetServiceUserContextWithContext(context.Background(), gatewayClient, s.serviceAccountID, s.serviceAccountSecret)
if err != nil {
logger.Error().Err(err).Msg("could not get service user context")
return
}

owner, err := utils.GetUserNoGroups(ctx, e.Sharer, gatewayClient)
if err != nil {
logger.Error().Err(err).Msg("could not get user")
return
}

shareFolder := e.ResourceName
if shareFolder == "" {
resourceInfo, err := s.getResourceInfo(ctx, e.ItemID, &fieldmaskpb.FieldMask{Paths: []string{"name"}})
if err != nil {
logger.Error().Err(err).Msg("could not stat resource")
return
}
shareFolder = resourceInfo.GetName()
}

shareLink, err := urlJoinPath(s.openCloudURL, "g", e.Token)
if err != nil {
logger.Error().Err(err).Msg("could not create guest link")
return
}

msg, err := email.RenderEmailTemplate(email.GuestLinkShareCreated, s.defaultLanguage, s.defaultLanguage,
s.emailTemplatePath, s.translationPath,
map[string]string{
"ShareSharer": owner.GetDisplayName(),
"ShareFolder": shareFolder,
"ShareLink": shareLink,
})
if err != nil {
logger.Error().Err(err).Msg("could not render the email")
return
}
msg.Sender = owner.GetDisplayName()
msg.Recipient = []string{e.GranteeEmail}

s.send(ctx, []*channels.Message{msg})
}
6 changes: 6 additions & 0 deletions services/notifications/pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ EventLoop:
s.handleShareExpired(e, evt.ID)
case events.ShareRemoved:
s.handleShareRemoved(e, evt.ID)
case ocEvents.GuestTokenCreated:
s.handleGuestTokenCreated(e)
case events.ScienceMeshInviteTokenGenerated:
s.handleScienceMeshInviteTokenGenerated(e)
case events.SendEmailsEvent:
Expand Down Expand Up @@ -202,6 +204,10 @@ func (s eventsNotifier) ensureGranteeList(ctx context.Context, executant, u *use
func (s eventsNotifier) getGranteeList(ctx context.Context, executant, u *user.UserId, g *group.GroupId) ([]*user.User, error) {
switch {
case u != nil:
// guests aren't users, they are notified via GuestTokenCreated
if u.GetType() == user.UserType_USER_TYPE_GUEST {
return nil, nil
}
if s.disableEmails(ctx, u) {
return nil, nil
}
Expand Down
Loading