Skip to content

Commit

Permalink
Fix share/space link in notification mail
Browse files Browse the repository at this point in the history
Use OCIS_URL as the link base. This change also makes sure that the
top-level OcisURL config value gets a default assigned, even when
OCIS_URL is unset.

Fixes: #4688
  • Loading branch information
rhafer committed Sep 29, 2022
1 parent 621079a commit 95de35e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 11 deletions.
8 changes: 8 additions & 0 deletions changelog/unreleased/fix-share-notifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Bugfix: Mail notifications for group shares

We fixed multiple issues in the notifications service, which broke notifcation
mails new shares with groups.

https://github.com/owncloud/ocis/pull/4714
https://github.com/owncloud/ocis/issues/4703
https://github.com/owncloud/ocis/issues/4688
1 change: 1 addition & 0 deletions ocis-pkg/config/defaultconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (

func DefaultConfig() *Config {
return &Config{
OcisURL: "https://localhost:9200",
Runtime: Runtime{
Port: "9250",
Host: "localhost",
Expand Down
4 changes: 4 additions & 0 deletions ocis-pkg/config/parser/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ func EnsureCommons(cfg *config.Config) {
if cfg.AdminUserID != "" {
cfg.Commons.AdminUserID = cfg.AdminUserID
}

if cfg.OcisURL != "" {
cfg.Commons.OcisURL = cfg.OcisURL
}
}

func Validate(cfg *config.Config) error {
Expand Down
2 changes: 1 addition & 1 deletion services/notifications/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func Server(cfg *config.Config) *cli.Command {
logger.Fatal().Err(err).Str("addr", cfg.Notifications.RevaGateway).Msg("could not get reva client")
}

svc := service.NewEventsNotifier(evts, channel, logger, gwclient, cfg.Notifications.MachineAuthAPIKey, cfg.Notifications.EmailTemplatePath)
svc := service.NewEventsNotifier(evts, channel, logger, gwclient, cfg.Notifications.MachineAuthAPIKey, cfg.Notifications.EmailTemplatePath, cfg.Commons.OcisURL)
return svc.Run()
},
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Hello {{ .ShareGrantee }},

{{ .ShareSharer }} has shared {{ .ShareFolder }} with you.
{{ .ShareSharer }} has shared "{{ .ShareFolder }}" with you.

Click here to view it: {{ .ShareLink }}

----------------------------------------------------------

Hallo {{ .Grantee }},

{{ .ShareSharer }} hat dich zu {{ .ShareFolder }} eingeladen.
{{ .ShareSharer }} hat dich zu "{{ .ShareFolder }}" eingeladen.

Klicke hier zum Anzeigen: {{ .ShareLink }}


---
ownCloud - Store. Share. Work.
https://owncloud.com
https://owncloud.com
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Hello {{ .SpaceGrantee }},

{{ .SpaceSharer }} has invited you to join {{ .SpaceName }}.
{{ .SpaceSharer }} has invited you to join "{{ .SpaceName }}".

Click here to view it: {{ .ShareLink }}

----------------------------------------------------------

Hallo {{ .SpaceGrantee }},

{{ .SpaceSharer }} hat dich in den Space {{ .SpaceName }} eingeladen.
{{ .SpaceSharer }} hat dich in den Space "{{ .SpaceName }}" eingeladen.

Klicke hier zum Anzeigen: {{ .ShareLink }}


---
ownCloud - Store. Share. Work.
https://owncloud.com
https://owncloud.com
15 changes: 11 additions & 4 deletions services/notifications/pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ type Service interface {
}

// NewEventsNotifier provides a new eventsNotifier
func NewEventsNotifier(events <-chan interface{}, channel channels.Channel, logger log.Logger, gwClient gateway.GatewayAPIClient, machineAuthAPIKey, emailTemplatePath string) Service {
func NewEventsNotifier(
events <-chan interface{},
channel channels.Channel,
logger log.Logger,
gwClient gateway.GatewayAPIClient,
machineAuthAPIKey, emailTemplatePath, ocisURL string) Service {
return eventsNotifier{
logger: logger,
channel: channel,
Expand All @@ -38,6 +43,7 @@ func NewEventsNotifier(events <-chan interface{}, channel channels.Channel, logg
gwClient: gwClient,
machineAuthAPIKey: machineAuthAPIKey,
emailTemplatePath: emailTemplatePath,
ocisURL: ocisURL,
}
}

Expand All @@ -49,6 +55,7 @@ type eventsNotifier struct {
gwClient gateway.GatewayAPIClient
machineAuthAPIKey string
emailTemplatePath string
ocisURL string
}

func (s eventsNotifier) Run() error {
Expand Down Expand Up @@ -147,7 +154,7 @@ func (s eventsNotifier) handleSpaceShared(e events.SpaceShared) {
return
}

shareLink, err := urlJoinPath(e.Executant.Idp, "files/spaces/projects", storagespace.FormatResourceID(*e.ID))
shareLink, err := urlJoinPath(s.ocisURL, "files/spaces/projects", storagespace.FormatResourceID(*e.ID))

if err != nil {
s.logger.Error().
Expand Down Expand Up @@ -284,7 +291,7 @@ func (s eventsNotifier) handleShareCreated(e events.ShareCreated) {
return
}

shareLink, err := urlJoinPath(e.Executant.Idp, "files/shares/with-me")
shareLink, err := urlJoinPath(s.ocisURL, "files/shares/with-me")

if err != nil {
s.logger.Error().
Expand Down Expand Up @@ -345,7 +352,7 @@ func (s eventsNotifier) handleShareCreated(e events.ShareCreated) {
Msg("Could not render E-Mail template for shares")
}

emailSubject := fmt.Sprintf("%s shared %s with you", sharerUserResponse.GetUser().DisplayName, md.GetInfo().Name)
emailSubject := fmt.Sprintf("%s shared '%s' with you", sharerUserResponse.GetUser().DisplayName, md.GetInfo().Name)
if e.GranteeUserID != nil {
err = s.channel.SendMessage(ownerCtx, []string{e.GranteeUserID.OpaqueId}, msg, emailSubject, sharerDisplayName)
} else if e.GranteeGroupID != nil {
Expand Down

0 comments on commit 95de35e

Please sign in to comment.