notify a user when a file was deleted because of policies (#5912)

Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
kobergj
2023-03-24 11:14:02 +01:00
committed by GitHub
parent 0bc471007e
commit ce84163983
4 changed files with 58 additions and 13 deletions
@@ -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
+30 -4
View File
@@ -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
+17 -9
View File
@@ -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
@@ -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}"),