mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-07 04:40:05 -06:00
link created/updated event
Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
@@ -45,8 +45,12 @@ func StartAuditLogger(ctx context.Context, ch <-chan interface{}, log log.Logger
|
||||
switch ev := i.(type) {
|
||||
case events.ShareCreated:
|
||||
auditEvent = types.ShareCreated(ev)
|
||||
case events.LinkCreated:
|
||||
auditEvent = types.LinkCreated(ev)
|
||||
case events.ShareUpdated:
|
||||
auditEvent = types.ShareUpdated(ev)
|
||||
case events.LinkUpdated:
|
||||
auditEvent = types.LinkUpdated(ev)
|
||||
default:
|
||||
log.Error().Interface("event", ev).Msg(fmt.Sprintf("can't handle event of type '%T'", ev))
|
||||
continue
|
||||
|
||||
@@ -7,6 +7,8 @@ const (
|
||||
ActionShareCreated = "share_created"
|
||||
ActionSharePermissionUpdated = "share_permission_updated"
|
||||
ActionShareDisplayNameUpdated = "share_name_updated"
|
||||
ActionSharePasswordUpdated = "share_password_updated"
|
||||
ActionShareExpirationUpdated = "share_expiration_updated"
|
||||
)
|
||||
|
||||
// MessageShareCreated returns the human readable string that describes the action
|
||||
@@ -14,7 +16,17 @@ func MessageShareCreated(sharer, item, grantee string) string {
|
||||
return fmt.Sprintf("user '%s' shared file '%s' with '%s'", sharer, item, grantee)
|
||||
}
|
||||
|
||||
// MessageLinkCreated returns the human readable string that describes the action
|
||||
func MessageLinkCreated(sharer, item, shareid string) string {
|
||||
return fmt.Sprintf("user '%s' created a public to file '%s' with id '%s'", sharer, item, shareid)
|
||||
}
|
||||
|
||||
// MessageShareUpdated returns the human readable string that describes the action
|
||||
func MessageShareUpdated(sharer, shareID, fieldUpdated string) string {
|
||||
return fmt.Sprintf("user '%s' updated field '%s' of share '%s'", sharer, fieldUpdated, shareID)
|
||||
}
|
||||
|
||||
// MessageLinkUpdated returns the human readable string that describes the action
|
||||
func MessageLinkUpdated(sharer, shareid, fieldUpdated string) string {
|
||||
return fmt.Sprintf("user '%s' modified field '%s' of public link '%s'", sharer, fieldUpdated, shareid)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/cs3org/reva/v2/pkg/events"
|
||||
@@ -62,6 +63,26 @@ func ShareCreated(ev events.ShareCreated) AuditEventShareCreated {
|
||||
}
|
||||
}
|
||||
|
||||
// LinkCreated converts a ShareCreated Event to an AuditEventShareCreated
|
||||
func LinkCreated(ev events.LinkCreated) AuditEventShareCreated {
|
||||
uid := ev.Sharer.OpaqueId
|
||||
with, typ := "", "link"
|
||||
base := BasicAuditEvent(uid, formatTime(ev.CTime), MessageLinkCreated(uid, ev.ItemID.OpaqueId, ev.ShareID.OpaqueId), ActionShareCreated)
|
||||
return AuditEventShareCreated{
|
||||
AuditEventSharing: SharingAuditEvent("", ev.ItemID.OpaqueId, uid, base),
|
||||
ShareOwner: uid,
|
||||
ShareWith: with,
|
||||
ShareType: typ,
|
||||
ExpirationDate: formatTime(ev.Expiration),
|
||||
SharePass: ev.PasswordProtected,
|
||||
Permissions: ev.Permissions.String(),
|
||||
ShareToken: ev.Token,
|
||||
|
||||
// NOTE: those values are not in the event and can therefore not be filled at the moment
|
||||
ItemType: "",
|
||||
}
|
||||
}
|
||||
|
||||
// ShareUpdated converts a ShareUpdated event to an AuditEventShareUpdated
|
||||
func ShareUpdated(ev events.ShareUpdated) AuditEventShareUpdated {
|
||||
uid := ev.Sharer.OpaqueId
|
||||
@@ -82,6 +103,25 @@ func ShareUpdated(ev events.ShareUpdated) AuditEventShareUpdated {
|
||||
}
|
||||
}
|
||||
|
||||
// LinkUpdated converts a LinkUpdated event to an AuditEventShareUpdated
|
||||
func LinkUpdated(ev events.LinkUpdated) AuditEventShareUpdated {
|
||||
uid := ev.Sharer.OpaqueId
|
||||
with, typ := "", "link"
|
||||
base := BasicAuditEvent(uid, formatTime(ev.CTime), MessageLinkUpdated(uid, ev.ShareID.OpaqueId, ev.FieldUpdated), updateType(ev.FieldUpdated))
|
||||
return AuditEventShareUpdated{
|
||||
AuditEventSharing: SharingAuditEvent(ev.ShareID.GetOpaqueId(), ev.ItemID.OpaqueId, uid, base),
|
||||
ShareOwner: uid,
|
||||
ShareWith: with,
|
||||
ShareType: typ,
|
||||
Permissions: ev.Permissions.Permissions.String(),
|
||||
ExpirationDate: formatTime(ev.Expiration),
|
||||
SharePass: ev.PasswordProtected,
|
||||
ShareToken: ev.Token,
|
||||
|
||||
// NOTE: those values are not in the event and can therefore not be filled at the moment
|
||||
ItemType: "",
|
||||
}
|
||||
}
|
||||
func extractGrantee(uid *user.UserId, gid *group.GroupId) (string, string) {
|
||||
switch {
|
||||
case uid != nil && uid.OpaqueId != "":
|
||||
@@ -94,6 +134,9 @@ func extractGrantee(uid *user.UserId, gid *group.GroupId) (string, string) {
|
||||
}
|
||||
|
||||
func formatTime(t *types.Timestamp) string {
|
||||
if t == nil {
|
||||
return ""
|
||||
}
|
||||
return time.Unix(int64(t.Seconds), int64(t.Nanos)).Format(time.RFC3339)
|
||||
}
|
||||
|
||||
@@ -103,7 +146,16 @@ func updateType(u string) string {
|
||||
return ActionSharePermissionUpdated
|
||||
case u == "displayname":
|
||||
return ActionShareDisplayNameUpdated
|
||||
case u == "TYPE_PERMISSIONS":
|
||||
return ActionSharePermissionUpdated
|
||||
case u == "TYPE_DISPLAYNAME":
|
||||
return ActionShareDisplayNameUpdated
|
||||
case u == "TYPE_PASSWORD":
|
||||
return ActionSharePasswordUpdated
|
||||
case u == "TYPE_EXPIRATION":
|
||||
return ActionShareExpirationUpdated
|
||||
default:
|
||||
fmt.Println("Unknown update type", u)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,5 +9,7 @@ func RegisteredEvents() []events.Unmarshaller {
|
||||
return []events.Unmarshaller{
|
||||
events.ShareCreated{},
|
||||
events.ShareUpdated{},
|
||||
events.LinkCreated{},
|
||||
events.LinkUpdated{},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user