feat: Add email notification for share removed
(cherry picked from commit e3876dba13)
This commit is contained in:
1 parent
e4df64d739
commit
e85da1b1a1
8 files changed
+202
-1
No files matched your search
@@ -0,0 +1,4 @@
|
||||
Enhancement: Add email notification for share removed event
|
||||
|
||||
https://github.com/owncloud/ocis/pull/10915
|
||||
https://github.com/owncloud/ocis/issues/10904
|
||||
@@ -81,6 +81,7 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
evs := []events.Unmarshaller{
|
||||
events.ShareCreated{},
|
||||
events.ShareExpired{},
|
||||
events.ShareRemoved{},
|
||||
events.SpaceShared{},
|
||||
events.SpaceUnshared{},
|
||||
events.SpaceMembershipExpired{},
|
||||
|
||||
@@ -33,6 +33,19 @@ var (
|
||||
// ShareExpired email template, resolves via {{ .MessageBody }}
|
||||
MessageBody: l10n.Template(`Your share to {ShareFolder} has expired at {ExpiredAt}
|
||||
|
||||
Even though this share has been revoked you still might have access through other shares and/or space memberships.`),
|
||||
}
|
||||
|
||||
ShareRemoved = MessageTemplate{
|
||||
textTemplate: _textTemplate,
|
||||
htmlTemplate: _htmlTemplate,
|
||||
// ShareRemoved email template, Subject field (resolves directly)
|
||||
Subject: l10n.Template(`{ShareSharer} unshared '{ShareFolder}' with you`),
|
||||
// ShareRemoved email template, resolves via {{ .Greeting }}
|
||||
Greeting: l10n.Template(`Hello {ShareGrantee},`),
|
||||
// ShareRemoved email template, resolves via {{ .MessageBody }}
|
||||
MessageBody: l10n.Template(`{ShareSharer} has unshared '{ShareFolder}' with you.
|
||||
|
||||
Even though this share has been revoked you still might have access through other shares and/or space memberships.`),
|
||||
}
|
||||
|
||||
|
||||
@@ -130,6 +130,24 @@ func (s eventsNotifier) createGroupedMail(ctx context.Context, logger zerolog.Lo
|
||||
"ShareFolder": shareFolder,
|
||||
"ExpiredAt": te.ExpiredAt.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
case events.ShareRemoved:
|
||||
logger := logger.With().
|
||||
Str("event", "ShareRemoved").
|
||||
Str("eventId", te.ItemID.OpaqueId).
|
||||
Logger()
|
||||
executant, shareFolder, _, err := s.prepareShareRemoved(logger, te)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("could not prepare vars for grouped email")
|
||||
continue
|
||||
}
|
||||
|
||||
mts = append(mts, email.ShareRemoved)
|
||||
mtsVars = append(mtsVars, map[string]string{
|
||||
"ShareSharer": executant.GetDisplayName(),
|
||||
"ShareFolder": shareFolder,
|
||||
})
|
||||
default:
|
||||
logger.Error().Str("eventType", e.Type).Msg("unsupported event type for grouped email")
|
||||
}
|
||||
}
|
||||
if len(mts) == 0 && len(mtsVars) == 0 {
|
||||
|
||||
@@ -117,6 +117,8 @@ func (s eventsNotifier) Run() error {
|
||||
s.handleShareCreated(e, evt.ID)
|
||||
case events.ShareExpired:
|
||||
s.handleShareExpired(e, evt.ID)
|
||||
case events.ShareRemoved:
|
||||
s.handleShareRemoved(e, evt.ID)
|
||||
case events.ScienceMeshInviteTokenGenerated:
|
||||
s.handleScienceMeshInviteTokenGenerated(e)
|
||||
case events.SendEmailsEvent:
|
||||
|
||||
@@ -166,6 +166,30 @@ https://owncloud.com
|
||||
},
|
||||
}),
|
||||
|
||||
Entry("Share Removed", testChannel{
|
||||
expectedReceipients: []string{sharee.GetMail()},
|
||||
expectedSubject: "Dr. S. Harer unshared 'secrets of the board' with you",
|
||||
expectedTextBody: `Hello Eric Expireling,
|
||||
|
||||
Dr. S. Harer has unshared 'secrets of the board' with you.
|
||||
|
||||
Even though this share has been revoked you still might have access through other shares and/or space memberships.
|
||||
|
||||
|
||||
---
|
||||
ownCloud - Store. Share. Work.
|
||||
https://owncloud.com
|
||||
`,
|
||||
expectedSender: sharer.GetDisplayName(),
|
||||
done: make(chan struct{}),
|
||||
}, events.Event{
|
||||
Event: events.ShareRemoved{
|
||||
Executant: sharer.GetId(),
|
||||
GranteeUserID: sharee.GetId(),
|
||||
ItemID: resourceid,
|
||||
},
|
||||
}),
|
||||
|
||||
Entry("Added to Space", testChannel{
|
||||
expectedReceipients: []string{sharee.GetMail()},
|
||||
expectedSubject: "Dr. S. Harer invited you to join secret space",
|
||||
@@ -643,6 +667,17 @@ var _ = Describe("Notifications grouped store", func() {
|
||||
},
|
||||
"daily"),
|
||||
|
||||
Entry("Share Removed daily", testChannelGroupedStore{
|
||||
done: make(chan struct{}),
|
||||
}, events.Event{
|
||||
Event: events.ShareRemoved{
|
||||
Executant: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
ItemID: resourceid,
|
||||
},
|
||||
},
|
||||
"daily"),
|
||||
|
||||
Entry("Added to Space daily", testChannelGroupedStore{
|
||||
done: make(chan struct{}),
|
||||
}, events.Event{
|
||||
@@ -703,6 +738,17 @@ var _ = Describe("Notifications grouped store", func() {
|
||||
},
|
||||
"weekly"),
|
||||
|
||||
Entry("Share Removed weekly", testChannelGroupedStore{
|
||||
done: make(chan struct{}),
|
||||
}, events.Event{
|
||||
Event: events.ShareRemoved{
|
||||
Executant: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
ItemID: resourceid,
|
||||
},
|
||||
},
|
||||
"weekly"),
|
||||
|
||||
Entry("Added to Space weekly", testChannelGroupedStore{
|
||||
done: make(chan struct{}),
|
||||
}, events.Event{
|
||||
@@ -840,6 +886,7 @@ var _ = Describe("Notifications grouped send", func() {
|
||||
evs := []events.Unmarshaller{
|
||||
events.ShareCreated{},
|
||||
events.ShareExpired{},
|
||||
events.ShareRemoved{},
|
||||
events.SpaceShared{},
|
||||
events.SpaceUnshared{},
|
||||
events.SpaceMembershipExpired{},
|
||||
@@ -886,6 +933,7 @@ var _ = Describe("Notifications grouped send", func() {
|
||||
ItemID: resourceid,
|
||||
},
|
||||
}}, "daily"),
|
||||
|
||||
Entry("Share Expired daily", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
@@ -904,6 +952,25 @@ Even though this share has been revoked you still might have access through othe
|
||||
ItemID: resourceid,
|
||||
},
|
||||
}}, "daily"),
|
||||
|
||||
Entry("Share Removed daily", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
expectedSubject: subject,
|
||||
expectedTextBody: buildExpectedTextBodyGrouped(receiver.DisplayName, []string{`executant has unshared 'secrets of the board' with you.
|
||||
|
||||
Even though this share has been revoked you still might have access through other shares and/or space memberships.`}),
|
||||
expectedHTMLBody: buildExpectedHTMLBodyGrouped(receiver.DisplayName, []string{`executant has unshared 'secrets of the board' with you.<br><br>Even though this share has been revoked you still might have access through other shares and/or space memberships.`}),
|
||||
done: make(chan struct{}),
|
||||
}, []events.Event{{
|
||||
Type: reflect.TypeOf(events.ShareRemoved{}).String(),
|
||||
Event: events.ShareRemoved{
|
||||
Executant: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
ItemID: resourceid,
|
||||
},
|
||||
}}, "daily"),
|
||||
|
||||
Entry("Added to Space daily", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
@@ -920,6 +987,7 @@ Even though this share has been revoked you still might have access through othe
|
||||
ID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
},
|
||||
}}, "daily"),
|
||||
|
||||
Entry("Removed from Space daily", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
@@ -937,6 +1005,7 @@ You might still have access through your other groups or direct membership.`}),
|
||||
ID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
},
|
||||
}}, "daily"),
|
||||
|
||||
Entry("Space Expired daily", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
@@ -956,6 +1025,7 @@ Even though this membership has expired you still might have access through othe
|
||||
ExpiredAt: time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC),
|
||||
},
|
||||
}}, "daily"),
|
||||
|
||||
Entry("Share Created and Space Expired grouped daily", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
@@ -1007,6 +1077,7 @@ Even though this membership has expired you still might have access through othe
|
||||
ItemID: resourceid,
|
||||
},
|
||||
}}, "weekly"),
|
||||
|
||||
Entry("Share Expired weekly", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
@@ -1025,6 +1096,25 @@ Even though this share has been revoked you still might have access through othe
|
||||
ItemID: resourceid,
|
||||
},
|
||||
}}, "weekly"),
|
||||
|
||||
Entry("Share Removed weekly", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
expectedSubject: subject,
|
||||
expectedTextBody: buildExpectedTextBodyGrouped(receiver.DisplayName, []string{`executant has unshared 'secrets of the board' with you.
|
||||
|
||||
Even though this share has been revoked you still might have access through other shares and/or space memberships.`}),
|
||||
expectedHTMLBody: buildExpectedHTMLBodyGrouped(receiver.DisplayName, []string{`executant has unshared 'secrets of the board' with you.<br><br>Even though this share has been revoked you still might have access through other shares and/or space memberships.`}),
|
||||
done: make(chan struct{}),
|
||||
}, []events.Event{{
|
||||
Type: reflect.TypeOf(events.ShareRemoved{}).String(),
|
||||
Event: events.ShareRemoved{
|
||||
Executant: executant.GetId(),
|
||||
GranteeGroupID: &group.GroupId{},
|
||||
ItemID: resourceid,
|
||||
},
|
||||
}}, "weekly"),
|
||||
|
||||
Entry("Added to Space weekly", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
@@ -1041,6 +1131,7 @@ Even though this share has been revoked you still might have access through othe
|
||||
ID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
},
|
||||
}}, "weekly"),
|
||||
|
||||
Entry("Removed from Space weekly", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
@@ -1058,6 +1149,7 @@ You might still have access through your other groups or direct membership.`}),
|
||||
ID: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||
},
|
||||
}}, "weekly"),
|
||||
|
||||
Entry("Space Expired weekly", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
@@ -1077,6 +1169,7 @@ Even though this membership has expired you still might have access through othe
|
||||
ExpiredAt: time.Date(2023, 4, 17, 16, 42, 0, 0, time.UTC),
|
||||
},
|
||||
}}, "weekly"),
|
||||
|
||||
Entry("Share Created and Space Expired grouped weekly", testChannel{
|
||||
expectedReceipients: []string{receiver.GetMail()},
|
||||
expectedSender: sender,
|
||||
|
||||
@@ -160,3 +160,73 @@ func (s eventsNotifier) prepareShareExpired(logger zerolog.Logger, e events.Shar
|
||||
|
||||
return shareFolder, ctx, err
|
||||
}
|
||||
|
||||
func (s eventsNotifier) handleShareRemoved(e events.ShareRemoved, eventId string) {
|
||||
logger := s.logger.With().
|
||||
Str("event", "ShareRemoved").
|
||||
Str("itemid", e.ItemID.OpaqueId).
|
||||
Logger()
|
||||
|
||||
executant, shareFolder, ctx, err := s.prepareShareRemoved(logger, e)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("could not prepare vars for email")
|
||||
return
|
||||
}
|
||||
|
||||
granteeList := s.ensureGranteeList(ctx, executant.GetId(), e.GranteeUserID, e.GranteeGroupID)
|
||||
filteredGrantees := s.filter.execute(ctx, granteeList, defaults.SettingUUIDProfileEventShareRemoved)
|
||||
|
||||
recipientsInstant, recipientsDaily, recipientsInstantWeekly := s.splitter.execute(ctx, filteredGrantees)
|
||||
recipientsInstant = append(recipientsInstant, s.userEventStore.persist(_intervalDaily, eventId, recipientsDaily)...)
|
||||
recipientsInstant = append(recipientsInstant, s.userEventStore.persist(_intervalWeekly, eventId, recipientsInstantWeekly)...)
|
||||
if recipientsInstant == nil {
|
||||
return
|
||||
}
|
||||
|
||||
sharerDisplayName := executant.GetDisplayName()
|
||||
|
||||
emails, err := s.render(ctx, email.ShareRemoved,
|
||||
"ShareGrantee",
|
||||
map[string]string{
|
||||
"ShareSharer": sharerDisplayName,
|
||||
"ShareFolder": shareFolder,
|
||||
}, recipientsInstant, sharerDisplayName)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("could not get render the email")
|
||||
return
|
||||
}
|
||||
s.send(ctx, emails)
|
||||
}
|
||||
|
||||
func (s eventsNotifier) prepareShareRemoved(logger zerolog.Logger, e events.ShareRemoved) (executant *user.User, shareFolder string, ctx context.Context, err error) {
|
||||
gatewayClient, err := s.gatewaySelector.Next()
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msg("could not select next gateway client")
|
||||
return executant, shareFolder, ctx, err
|
||||
}
|
||||
|
||||
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 executant, shareFolder, ctx, err
|
||||
}
|
||||
|
||||
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 executant, shareFolder, ctx, err
|
||||
}
|
||||
shareFolder = resourceInfo.Name
|
||||
|
||||
executant, err = utils.GetUserWithContext(ctx, e.Executant, gatewayClient)
|
||||
if err != nil {
|
||||
logger.Error().
|
||||
Err(err).
|
||||
Msg("could not get user")
|
||||
return executant, shareFolder, ctx, err
|
||||
}
|
||||
|
||||
return executant, shareFolder, ctx, err
|
||||
}
|
||||
@@ -328,7 +328,7 @@ func generateBundleProfileRequest() *settingsmsg.Bundle {
|
||||
MultiChoiceCollectionValue: &settingsmsg.MultiChoiceCollection{
|
||||
Options: []*settingsmsg.MultiChoiceCollectionOption{
|
||||
&optionInAppTrue,
|
||||
&optionMailFalseDisabled,
|
||||
&optionMailTrue,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user