@@ -0,0 +1,20 @@
|
||||
package types
|
||||
|
||||
import "fmt"
|
||||
|
||||
// short identifiers for audit actions
|
||||
const (
|
||||
ActionShareCreated = "share_created"
|
||||
ActionSharePermissionUpdated = "share_permission_updated"
|
||||
ActionShareDisplayNameUpdated = "share_name_updated"
|
||||
)
|
||||
|
||||
// MessageShareCreated returns the human readable string that describes the action
|
||||
func MessageShareCreated(sharer, item, grantee string) string {
|
||||
return fmt.Sprintf("user '%s' shared file '%s' with '%s'", sharer, item, grantee)
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
@@ -1,20 +1,13 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/cs3org/reva/v2/pkg/events"
|
||||
)
|
||||
|
||||
// actions
|
||||
const (
|
||||
actionShareCreated = "file_shared"
|
||||
)
|
||||
|
||||
// messages
|
||||
const (
|
||||
messageShareCreated = "user '%s' shared file '%s' with '%s'"
|
||||
group "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1"
|
||||
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
|
||||
)
|
||||
|
||||
// BasicAuditEvent creates an AuditEvent from given values
|
||||
@@ -37,39 +30,30 @@ func BasicAuditEvent(uid string, ctime string, msg string, action string) AuditE
|
||||
}
|
||||
|
||||
// SharingAuditEvent creates an AuditEventSharing from given values
|
||||
func SharingAuditEvent(fileid string, uid string, base AuditEvent) AuditEventSharing {
|
||||
func SharingAuditEvent(shareid string, fileid string, uid string, base AuditEvent) AuditEventSharing {
|
||||
return AuditEventSharing{
|
||||
AuditEvent: base,
|
||||
FileID: fileid,
|
||||
Owner: uid,
|
||||
ShareID: shareid,
|
||||
|
||||
// NOTE: those values are not in the events and can therefore not be filled at the moment
|
||||
ShareID: "",
|
||||
Path: "",
|
||||
Path: "",
|
||||
}
|
||||
}
|
||||
|
||||
// ShareCreated converts a ShareCreated Event to an AuditEventShareCreated
|
||||
func ShareCreated(ev events.ShareCreated) AuditEventShareCreated {
|
||||
with := ""
|
||||
typ := ""
|
||||
if ev.GranteeUserID != nil && ev.GranteeUserID.OpaqueId != "" {
|
||||
with = ev.GranteeUserID.OpaqueId
|
||||
typ = "user"
|
||||
} else if ev.GranteeGroupID != nil && ev.GranteeGroupID.OpaqueId != "" {
|
||||
with = ev.GranteeGroupID.OpaqueId
|
||||
typ = "group"
|
||||
}
|
||||
uid := ev.Sharer.OpaqueId
|
||||
t := time.Unix(int64(ev.CTime.Seconds), int64(ev.CTime.Nanos)).Format(time.RFC3339)
|
||||
base := BasicAuditEvent(uid, t, fmt.Sprintf(messageShareCreated, uid, ev.ItemID.OpaqueId, with), actionShareCreated)
|
||||
with, typ := extractGrantee(ev.GranteeUserID, ev.GranteeGroupID)
|
||||
base := BasicAuditEvent(uid, formatTime(ev.CTime), MessageShareCreated(uid, ev.ItemID.OpaqueId, with), ActionShareCreated)
|
||||
return AuditEventShareCreated{
|
||||
AuditEventSharing: SharingAuditEvent(ev.ItemID.OpaqueId, uid, base),
|
||||
AuditEventSharing: SharingAuditEvent("", ev.ItemID.OpaqueId, uid, base),
|
||||
ShareOwner: uid,
|
||||
ShareWith: with,
|
||||
ShareType: typ,
|
||||
|
||||
// NOTE: those values are not in the events and can therefore not be filled at the moment
|
||||
// NOTE: those values are not in the event and can therefore not be filled at the moment
|
||||
ItemType: "",
|
||||
ExpirationDate: "",
|
||||
SharePass: false,
|
||||
@@ -77,3 +61,49 @@ func ShareCreated(ev events.ShareCreated) AuditEventShareCreated {
|
||||
ShareToken: "",
|
||||
}
|
||||
}
|
||||
|
||||
// ShareUpdated converts a ShareUpdated event to an AuditEventShareUpdated
|
||||
func ShareUpdated(ev events.ShareUpdated) AuditEventShareUpdated {
|
||||
uid := ev.Sharer.OpaqueId
|
||||
with, typ := extractGrantee(ev.GranteeUserID, ev.GranteeGroupID)
|
||||
base := BasicAuditEvent(uid, formatTime(ev.MTime), MessageShareUpdated(uid, ev.ShareID.OpaqueId, ev.Updated), updateType(ev.Updated))
|
||||
return AuditEventShareUpdated{
|
||||
AuditEventSharing: SharingAuditEvent(ev.ShareID.GetOpaqueId(), ev.ItemID.OpaqueId, uid, base),
|
||||
ShareOwner: uid,
|
||||
ShareWith: with,
|
||||
ShareType: typ,
|
||||
Permissions: ev.Permissions.Permissions.String(),
|
||||
|
||||
// NOTE: those values are not in the event and can therefore not be filled at the moment
|
||||
ItemType: "",
|
||||
ExpirationDate: "",
|
||||
SharePass: false,
|
||||
ShareToken: "",
|
||||
}
|
||||
}
|
||||
|
||||
func extractGrantee(uid *user.UserId, gid *group.GroupId) (string, string) {
|
||||
switch {
|
||||
case uid != nil && uid.OpaqueId != "":
|
||||
return uid.OpaqueId, "user"
|
||||
case gid != nil && gid.OpaqueId != "":
|
||||
return gid.OpaqueId, "group"
|
||||
}
|
||||
|
||||
return "", ""
|
||||
}
|
||||
|
||||
func formatTime(t *types.Timestamp) string {
|
||||
return time.Unix(int64(t.Seconds), int64(t.Nanos)).Format(time.RFC3339)
|
||||
}
|
||||
|
||||
func updateType(u string) string {
|
||||
switch {
|
||||
case u == "permissions":
|
||||
return ActionSharePermissionUpdated
|
||||
case u == "displayname":
|
||||
return ActionShareDisplayNameUpdated
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,5 +8,6 @@ import (
|
||||
func RegisteredEvents() []events.Unmarshaller {
|
||||
return []events.Unmarshaller{
|
||||
events.ShareCreated{},
|
||||
events.ShareUpdated{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,3 +38,17 @@ type AuditEventShareCreated struct {
|
||||
ShareOwner string // The UID of the share owner.
|
||||
ShareToken string // For link shares the unique token, else null
|
||||
}
|
||||
|
||||
// AuditEventShareUpdated is the event logged when a share is updated
|
||||
type AuditEventShareUpdated struct {
|
||||
AuditEventSharing
|
||||
|
||||
ItemType string // file or folder
|
||||
ExpirationDate string // The text expiration date in format 'yyyy-mm-dd'
|
||||
SharePass bool // If the share is password protected.
|
||||
Permissions string // The permissions string eg: "READ"
|
||||
ShareType string // group user or link
|
||||
ShareWith string // The UID or GID of the share recipient. (not available for public link)
|
||||
ShareOwner string // The UID of the share owner.
|
||||
ShareToken string // For link shares the unique token, else null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user