diff --git a/changelog/unreleased/notify-about-policies.md b/changelog/unreleased/notify-about-policies.md new file mode 100644 index 000000000..c234ae839 --- /dev/null +++ b/changelog/unreleased/notify-about-policies.md @@ -0,0 +1,5 @@ +Enhancement: Notify about policies + +Notify the user when a file was deleted due to policies (policies service) + +https://github.com/owncloud/ocis/pull/5912 diff --git a/services/userlog/pkg/service/conversion.go b/services/userlog/pkg/service/conversion.go index 90e9579f5..2848ce239 100644 --- a/services/userlog/pkg/service/conversion.go +++ b/services/userlog/pkg/service/conversion.go @@ -100,11 +100,15 @@ func (c *Converter) ConvertEvent(event *ehmsg.Event) (OC10Notification, error) { return OC10Notification{}, fmt.Errorf("unknown event type: %T", ev) // file related case events.PostprocessingStepFinished: - if ev.FinishedStep != events.PPStepAntivirus { - return OC10Notification{}, fmt.Errorf("unknown event type: %T", ev) + switch ev.FinishedStep { + case events.PPStepAntivirus: + res := ev.Result.(events.VirusscanResult) + return c.virusMessage(event.Id, VirusFound, ev.ExecutingUser, res.ResourceID, ev.Filename, res.Description, res.Scandate) + case events.PPStepPolicies: + return c.policiesMessage(event.Id, PoliciesEnforced, ev.ExecutingUser, ev.Filename, time.Now()) + default: + return OC10Notification{}, fmt.Errorf("unknown postprocessing step: %s", ev.FinishedStep) } - res := ev.Result.(events.VirusscanResult) - return c.virusMessage(event.Id, VirusFound, ev.ExecutingUser, res.ResourceID, ev.Filename, res.Description, res.Scandate) // space related case events.SpaceDisabled: return c.spaceMessage(event.Id, SpaceDisabled, ev.Executant, ev.ID.GetOpaqueId(), ev.Timestamp) @@ -260,6 +264,28 @@ func (c *Converter) virusMessage(eventid string, nt NotificationTemplate, execut }, nil } +func (c *Converter) policiesMessage(eventid string, nt NotificationTemplate, executant *user.User, filename string, ts time.Time) (OC10Notification, error) { + subj, subjraw, msg, msgraw, err := composeMessage(nt, c.locale, c.translationPath, map[string]interface{}{ + "resourcename": filename, + }) + if err != nil { + return OC10Notification{}, err + } + + return OC10Notification{ + EventID: eventid, + Service: c.serviceName, + UserName: executant.GetUsername(), + Timestamp: ts.Format(time.RFC3339Nano), + ResourceType: _resourceTypeResource, + Subject: subj, + SubjectRaw: subjraw, + Message: msg, + MessageRaw: msgraw, + MessageDetails: generateDetails(nil, nil, nil, nil), + }, nil +} + func (c *Converter) authenticate(usr *user.User) (context.Context, error) { if ctx, ok := c.contexts[usr.GetId().GetOpaqueId()]; ok { return ctx, nil diff --git a/services/userlog/pkg/service/service.go b/services/userlog/pkg/service/service.go index a95a3a7b7..f3f028aad 100644 --- a/services/userlog/pkg/service/service.go +++ b/services/userlog/pkg/service/service.go @@ -93,16 +93,24 @@ func (ul *UserlogService) MemorizeEvents(ch <-chan events.Event) { err = errors.New("unhandled event") // file related case events.PostprocessingStepFinished: - if e.FinishedStep != events.PPStepAntivirus { - continue - } - result := e.Result.(events.VirusscanResult) - if !result.Infected { - continue - } + switch e.FinishedStep { + case events.PPStepAntivirus: + result := e.Result.(events.VirusscanResult) + if !result.Infected { + continue + } - // TODO: should space mangers also be informed? - users = append(users, e.ExecutingUser.GetId().GetOpaqueId()) + // TODO: should space mangers also be informed? + users = append(users, e.ExecutingUser.GetId().GetOpaqueId()) + case events.PPStepPolicies: + if e.Outcome == events.PPOutcomeContinue { + continue + } + users = append(users, e.ExecutingUser.GetId().GetOpaqueId()) + default: + continue + + } // space related // TODO: how to find spaceadmins? case events.SpaceDisabled: executant = e.Executant diff --git a/services/userlog/pkg/service/templates.go b/services/userlog/pkg/service/templates.go index b80d59159..a6616d02e 100644 --- a/services/userlog/pkg/service/templates.go +++ b/services/userlog/pkg/service/templates.go @@ -9,6 +9,12 @@ var ( Subject: Template("Virus found"), Message: Template("Virus found in {resource}. Upload not possible. Virus: {virus}"), } + + PoliciesEnforced = NotificationTemplate{ + Subject: Template("Policies enforced"), + Message: Template("File {resource} was deleted because it violates the policies"), + } + SpaceShared = NotificationTemplate{ Subject: Template("Space shared"), Message: Template("{user} added you to Space {space}"),