Skip to content

Commit

Permalink
handle spaceshared event
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Richter <[email protected]>
  • Loading branch information
dragonchaser committed Sep 19, 2022
1 parent ac35fc7 commit 786af00
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions services/audit/pkg/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func RegisteredEvents() []events.Unmarshaller {
events.SpaceEnabled{},
events.SpaceDisabled{},
events.SpaceDeleted{},
events.SpaceShared{},
events.UserCreated{},
events.UserDeleted{},
events.UserFeatureChanged{},
Expand Down
2 changes: 2 additions & 0 deletions services/notifications/pkg/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ func Server(cfg *config.Config) *cli.Command {
Action: func(c *cli.Context) error {
logger := logging.Configure(cfg.Service.Name, cfg.Log)

// evs defines a list of events to subscribe to
evs := []events.Unmarshaller{
events.ShareCreated{},
events.SpaceShared{},
}

evtsCfg := cfg.Notifications.Events
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{{ .SpaceSharer }} has invited you to join {{ .SpaceName }}
{{ .SpaceSharer }} has invited you to join {{ .SpaceName }}

Link: {{ .ShareLink }}
31 changes: 22 additions & 9 deletions services/notifications/pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (s eventsNotifier) Run() error {

func (s eventsNotifier) handleSpaceShared(e events.SpaceShared) {
userResponse, err := s.gwClient.GetUser(context.Background(), &userv1beta1.GetUserRequest{
UserId: e.Owner,
UserId: e.Creator,
})
if err != nil || userResponse.Status.Code != rpcv1beta1.Code_CODE_OK {
s.logger.Error().
Expand Down Expand Up @@ -120,7 +120,8 @@ func (s eventsNotifier) handleSpaceShared(e events.SpaceShared) {
Ref: &providerv1beta1.Reference{
ResourceId: &resourceID,
},
FieldMask: &fieldmaskpb.FieldMask{Paths: []string{"name"}},
// TODO: this filter needs to be implemented
//FieldMask: &fieldmaskpb.FieldMask{Paths: []string{"space.name"}},
})

if err != nil || md.Status.Code != rpcv1beta1.Code_CODE_OK {
Expand All @@ -142,11 +143,21 @@ func (s eventsNotifier) handleSpaceShared(e events.SpaceShared) {
return
}

// old code
shareLink, err := url.JoinPath(e.Executant.Idp, "files/spaces/projects", storagespace.FormatResourceID(*e.ID))

if err != nil {
s.logger.Error().
Err(err).
Str("event", "ShareCreated").
Msg("could not create link to the share")
return
}

msg, err := email.RenderEmailTemplate("sharedSpace.email.tmpl", map[string]string{
// TODO: add additional fields here (like link etc.)
"SpaceSharer": "spacesharer",
"SpaceName": md.Info.Space.Name,
"SpaceSharer": userResponse.GetUser().DisplayName,
"SpaceName": md.GetInfo().GetSpace().Name,
"ShareLink": shareLink,
}, s.emailTemplatePath)

if err != nil {
Expand All @@ -155,8 +166,10 @@ func (s eventsNotifier) handleSpaceShared(e events.SpaceShared) {
Str("event", "SpaceCreated").
Msg("Could not render E-Mail template for spaces")
}
if e.Executant != nil {
err = s.channel.SendMessage([]string{e.Executant.OpaqueId}, msg, "You were invited to join a space")
if e.GranteeUserID != nil {
err = s.channel.SendMessage([]string{e.GranteeUserID.OpaqueId}, msg, "You have received a share.")
} else if e.GranteeGroupID != nil {
err = s.channel.SendMessageToGroup(e.GranteeGroupID, msg, "You have received a share.")
}
if err != nil {
s.logger.Error().
Expand Down Expand Up @@ -241,8 +254,8 @@ func (s eventsNotifier) handleShareCreated(e events.ShareCreated) {

msg, err := email.RenderEmailTemplate("shareCreated.email.tmpl", map[string]string{
// TODO: add additional fields here (like link etc.)
"ShareSharer": userResponse.User.DisplayName,
"ShareFolder": md.Info.Name,
"ShareSharer": userResponse.GetUser().DisplayName,
"ShareFolder": md.GetInfo().Name,
"ShareLink": shareLink,
}, s.emailTemplatePath)

Expand Down

0 comments on commit 786af00

Please sign in to comment.