Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an executant to all events #2945

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/events-executant.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Add executant to the events

Added the executant field to all events.

https://github.com/owncloud/ocis/issues/3753
https://github.com/cs3org/reva/pull/2945
88 changes: 52 additions & 36 deletions internal/grpc/interceptors/eventsmiddleware/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ func ContainerCreated(r *provider.CreateContainerResponse, req *provider.CreateC
}

// ShareCreated converts the response to an event
func ShareCreated(r *collaboration.CreateShareResponse) events.ShareCreated {
func ShareCreated(r *collaboration.CreateShareResponse, executant *user.UserId) events.ShareCreated {
return events.ShareCreated{
Executant: executant,
Sharer: r.Share.Creator,
GranteeUserID: r.Share.GetGrantee().GetUserId(),
GranteeGroupID: r.Share.GetGrantee().GetGroupId(),
Expand All @@ -48,22 +49,24 @@ func ShareCreated(r *collaboration.CreateShareResponse) events.ShareCreated {
}

// ShareRemoved converts the response to an event
func ShareRemoved(r *collaboration.RemoveShareResponse, req *collaboration.RemoveShareRequest) events.ShareRemoved {
func ShareRemoved(r *collaboration.RemoveShareResponse, req *collaboration.RemoveShareRequest, executant *user.UserId) events.ShareRemoved {
return events.ShareRemoved{
ShareID: req.Ref.GetId(),
ShareKey: req.Ref.GetKey(),
Executant: executant,
ShareID: req.Ref.GetId(),
ShareKey: req.Ref.GetKey(),
}
}

// ShareUpdated converts the response to an event
func ShareUpdated(r *collaboration.UpdateShareResponse, req *collaboration.UpdateShareRequest) events.ShareUpdated {
func ShareUpdated(r *collaboration.UpdateShareResponse, req *collaboration.UpdateShareRequest, executant *user.UserId) events.ShareUpdated {
updated := ""
if req.Field.GetPermissions() != nil {
updated = "permissions"
} else if req.Field.GetDisplayName() != "" {
updated = "displayname"
}
return events.ShareUpdated{
Executant: executant,
ShareID: r.Share.Id,
ItemID: r.Share.ResourceId,
Permissions: r.Share.Permissions,
Expand All @@ -76,8 +79,9 @@ func ShareUpdated(r *collaboration.UpdateShareResponse, req *collaboration.Updat
}

// ReceivedShareUpdated converts the response to an event
func ReceivedShareUpdated(r *collaboration.UpdateReceivedShareResponse) events.ReceivedShareUpdated {
func ReceivedShareUpdated(r *collaboration.UpdateReceivedShareResponse, executant *user.UserId) events.ReceivedShareUpdated {
return events.ReceivedShareUpdated{
Executant: executant,
ShareID: r.Share.Share.Id,
ItemID: r.Share.Share.ResourceId,
Permissions: r.Share.Share.Permissions,
Expand All @@ -90,8 +94,9 @@ func ReceivedShareUpdated(r *collaboration.UpdateReceivedShareResponse) events.R
}

// LinkCreated converts the response to an event
func LinkCreated(r *link.CreatePublicShareResponse) events.LinkCreated {
func LinkCreated(r *link.CreatePublicShareResponse, executant *user.UserId) events.LinkCreated {
return events.LinkCreated{
Executant: executant,
ShareID: r.Share.Id,
Sharer: r.Share.Creator,
ItemID: r.Share.ResourceId,
Expand All @@ -105,8 +110,9 @@ func LinkCreated(r *link.CreatePublicShareResponse) events.LinkCreated {
}

// LinkUpdated converts the response to an event
func LinkUpdated(r *link.UpdatePublicShareResponse, req *link.UpdatePublicShareRequest) events.LinkUpdated {
func LinkUpdated(r *link.UpdatePublicShareResponse, req *link.UpdatePublicShareRequest, executant *user.UserId) events.LinkUpdated {
return events.LinkUpdated{
Executant: executant,
ShareID: r.Share.Id,
Sharer: r.Share.Creator,
ItemID: r.Share.ResourceId,
Expand All @@ -121,8 +127,9 @@ func LinkUpdated(r *link.UpdatePublicShareResponse, req *link.UpdatePublicShareR
}

// LinkAccessed converts the response to an event
func LinkAccessed(r *link.GetPublicShareByTokenResponse) events.LinkAccessed {
func LinkAccessed(r *link.GetPublicShareByTokenResponse, executant *user.UserId) events.LinkAccessed {
return events.LinkAccessed{
Executant: executant,
ShareID: r.Share.Id,
Sharer: r.Share.Creator,
ItemID: r.Share.ResourceId,
Expand All @@ -136,10 +143,11 @@ func LinkAccessed(r *link.GetPublicShareByTokenResponse) events.LinkAccessed {
}

// LinkAccessFailed converts the response to an event
func LinkAccessFailed(r *link.GetPublicShareByTokenResponse, req *link.GetPublicShareByTokenRequest) events.LinkAccessFailed {
func LinkAccessFailed(r *link.GetPublicShareByTokenResponse, req *link.GetPublicShareByTokenRequest, executant *user.UserId) events.LinkAccessFailed {
e := events.LinkAccessFailed{
Status: r.Status.Code,
Message: r.Status.Message,
Executant: executant,
Status: r.Status.Code,
Message: r.Status.Message,
}
if r.Share != nil {
e.ShareID = r.Share.Id
Expand All @@ -149,8 +157,9 @@ func LinkAccessFailed(r *link.GetPublicShareByTokenResponse, req *link.GetPublic
}

// LinkRemoved converts the response to an event
func LinkRemoved(r *link.RemovePublicShareResponse, req *link.RemovePublicShareRequest) events.LinkRemoved {
func LinkRemoved(r *link.RemovePublicShareResponse, req *link.RemovePublicShareRequest, executant *user.UserId) events.LinkRemoved {
return events.LinkRemoved{
Executant: executant,
ShareID: req.Ref.GetId(),
ShareToken: req.Ref.GetToken(),
}
Expand All @@ -165,9 +174,10 @@ func FileUploaded(r *provider.InitiateFileUploadResponse, req *provider.Initiate
}

// FileDownloaded converts the response to an event
func FileDownloaded(r *provider.InitiateFileDownloadResponse, req *provider.InitiateFileDownloadRequest) events.FileDownloaded {
func FileDownloaded(r *provider.InitiateFileDownloadResponse, req *provider.InitiateFileDownloadRequest, executant *user.UserId) events.FileDownloaded {
return events.FileDownloaded{
Ref: req.Ref,
Executant: executant,
Ref: req.Ref,
}
}

Expand All @@ -194,9 +204,10 @@ func ItemMoved(r *provider.MoveResponse, req *provider.MoveRequest, executant *u
}

// ItemPurged converts the response to an event
func ItemPurged(r *provider.PurgeRecycleResponse, req *provider.PurgeRecycleRequest) events.ItemPurged {
func ItemPurged(r *provider.PurgeRecycleResponse, req *provider.PurgeRecycleRequest, executant *user.UserId) events.ItemPurged {
return events.ItemPurged{
Ref: req.Ref,
Executant: executant,
Ref: req.Ref,
}
}

Expand Down Expand Up @@ -224,46 +235,51 @@ func FileVersionRestored(r *provider.RestoreFileVersionResponse, req *provider.R
}

// SpaceCreated converts the response to an event
func SpaceCreated(r *provider.CreateStorageSpaceResponse) events.SpaceCreated {
func SpaceCreated(r *provider.CreateStorageSpaceResponse, executant *user.UserId) events.SpaceCreated {
return events.SpaceCreated{
ID: r.StorageSpace.Id,
Owner: extractOwner(r.StorageSpace.Owner),
Root: r.StorageSpace.Root,
Name: r.StorageSpace.Name,
Type: r.StorageSpace.SpaceType,
Quota: r.StorageSpace.Quota,
MTime: r.StorageSpace.Mtime,
Executant: executant,
ID: r.StorageSpace.Id,
Owner: extractOwner(r.StorageSpace.Owner),
Root: r.StorageSpace.Root,
Name: r.StorageSpace.Name,
Type: r.StorageSpace.SpaceType,
Quota: r.StorageSpace.Quota,
MTime: r.StorageSpace.Mtime,
}
}

// SpaceRenamed converts the response to an event
func SpaceRenamed(r *provider.UpdateStorageSpaceResponse, req *provider.UpdateStorageSpaceRequest) events.SpaceRenamed {
func SpaceRenamed(r *provider.UpdateStorageSpaceResponse, req *provider.UpdateStorageSpaceRequest, executant *user.UserId) events.SpaceRenamed {
return events.SpaceRenamed{
ID: r.StorageSpace.Id,
Owner: extractOwner(r.StorageSpace.Owner),
Name: r.StorageSpace.Name,
Executant: executant,
ID: r.StorageSpace.Id,
Owner: extractOwner(r.StorageSpace.Owner),
Name: r.StorageSpace.Name,
}
}

// SpaceEnabled converts the response to an event
func SpaceEnabled(r *provider.UpdateStorageSpaceResponse, req *provider.UpdateStorageSpaceRequest) events.SpaceEnabled {
func SpaceEnabled(r *provider.UpdateStorageSpaceResponse, req *provider.UpdateStorageSpaceRequest, executant *user.UserId) events.SpaceEnabled {
return events.SpaceEnabled{
ID: r.StorageSpace.Id,
Owner: extractOwner(r.StorageSpace.Owner),
Executant: executant,
ID: r.StorageSpace.Id,
Owner: extractOwner(r.StorageSpace.Owner),
}
}

// SpaceDisabled converts the response to an event
func SpaceDisabled(r *provider.DeleteStorageSpaceResponse, req *provider.DeleteStorageSpaceRequest) events.SpaceDisabled {
func SpaceDisabled(r *provider.DeleteStorageSpaceResponse, req *provider.DeleteStorageSpaceRequest, executant *user.UserId) events.SpaceDisabled {
return events.SpaceDisabled{
ID: req.Id,
Executant: executant,
ID: req.Id,
}
}

// SpaceDeleted converts the response to an event
func SpaceDeleted(r *provider.DeleteStorageSpaceResponse, req *provider.DeleteStorageSpaceRequest) events.SpaceDeleted {
func SpaceDeleted(r *provider.DeleteStorageSpaceResponse, req *provider.DeleteStorageSpaceRequest, executant *user.UserId) events.SpaceDeleted {
return events.SpaceDeleted{
ID: req.Id,
Executant: executant,
ID: req.Id,
}
}

Expand Down
32 changes: 16 additions & 16 deletions internal/grpc/interceptors/eventsmiddleware/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,45 +72,45 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error
switch v := res.(type) {
case *collaboration.CreateShareResponse:
if isSuccess(v) {
ev = ShareCreated(v)
ev = ShareCreated(v, executantID)
}
case *collaboration.RemoveShareResponse:
if isSuccess(v) {
ev = ShareRemoved(v, req.(*collaboration.RemoveShareRequest))
ev = ShareRemoved(v, req.(*collaboration.RemoveShareRequest), executantID)
}
case *collaboration.UpdateShareResponse:
if isSuccess(v) {
ev = ShareUpdated(v, req.(*collaboration.UpdateShareRequest))
ev = ShareUpdated(v, req.(*collaboration.UpdateShareRequest), executantID)
}
case *collaboration.UpdateReceivedShareResponse:
if isSuccess(v) {
ev = ReceivedShareUpdated(v)
ev = ReceivedShareUpdated(v, executantID)
}
case *link.CreatePublicShareResponse:
if isSuccess(v) {
ev = LinkCreated(v)
ev = LinkCreated(v, executantID)
}
case *link.UpdatePublicShareResponse:
if isSuccess(v) {
ev = LinkUpdated(v, req.(*link.UpdatePublicShareRequest))
ev = LinkUpdated(v, req.(*link.UpdatePublicShareRequest), executantID)
}
case *link.RemovePublicShareResponse:
if isSuccess(v) {
ev = LinkRemoved(v, req.(*link.RemovePublicShareRequest))
ev = LinkRemoved(v, req.(*link.RemovePublicShareRequest), executantID)
}
case *link.GetPublicShareByTokenResponse:
if isSuccess(v) {
ev = LinkAccessed(v)
ev = LinkAccessed(v, executantID)
} else {
ev = LinkAccessFailed(v, req.(*link.GetPublicShareByTokenRequest))
ev = LinkAccessFailed(v, req.(*link.GetPublicShareByTokenRequest), executantID)
}
case *provider.CreateContainerResponse:
if isSuccess(v) {
ev = ContainerCreated(v, req.(*provider.CreateContainerRequest), executantID)
}
case *provider.InitiateFileDownloadResponse:
if isSuccess(v) {
ev = FileDownloaded(v, req.(*provider.InitiateFileDownloadRequest))
ev = FileDownloaded(v, req.(*provider.InitiateFileDownloadRequest), executantID)
}
case *provider.DeleteResponse:
if isSuccess(v) {
Expand All @@ -122,7 +122,7 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error
}
case *provider.PurgeRecycleResponse:
if isSuccess(v) {
ev = ItemPurged(v, req.(*provider.PurgeRecycleRequest))
ev = ItemPurged(v, req.(*provider.PurgeRecycleRequest), executantID)
}
case *provider.RestoreRecycleItemResponse:
if isSuccess(v) {
Expand All @@ -134,26 +134,26 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error
}
case *provider.CreateStorageSpaceResponse:
if isSuccess(v) && v.StorageSpace != nil { // TODO: Why are there CreateStorageSpaceResponses with nil StorageSpace?
ev = SpaceCreated(v)
ev = SpaceCreated(v, executantID)
}
case *provider.UpdateStorageSpaceResponse:
if isSuccess(v) {
r := req.(*provider.UpdateStorageSpaceRequest)
if r.StorageSpace.Name != "" {
ev = SpaceRenamed(v, r)
ev = SpaceRenamed(v, r, executantID)
}

if utils.ExistsInOpaque(r.Opaque, "restore") {
ev = SpaceEnabled(v, r)
ev = SpaceEnabled(v, r, executantID)
}
}
case *provider.DeleteStorageSpaceResponse:
if isSuccess(v) {
r := req.(*provider.DeleteStorageSpaceRequest)
if utils.ExistsInOpaque(r.Opaque, "purge") {
ev = SpaceDeleted(v, r)
ev = SpaceDeleted(v, r, executantID)
} else {
ev = SpaceDisabled(v, r)
ev = SpaceDisabled(v, r, executantID)
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/events/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
type ContainerCreated struct {
Executant *user.UserId
Ref *provider.Reference
Owner *user.UserId
}

// Unmarshal to fulfill umarshaller interface
Expand All @@ -54,8 +55,9 @@ func (FileUploaded) Unmarshal(v []byte) (interface{}, error) {

// FileDownloaded is emitted when a file is downloaded
type FileDownloaded struct {
Ref *provider.Reference
Owner *user.UserId
Executant *user.UserId
Ref *provider.Reference
Owner *user.UserId
}

// Unmarshal to fulfill umarshaller interface
Expand Down
18 changes: 12 additions & 6 deletions pkg/events/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ package events

import (
"encoding/json"

user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
)

// GroupCreated is emitted when a group was created
type GroupCreated struct {
GroupID string
Executant *user.UserId
GroupID string
}

// Unmarshal to fulfill umarshaller interface
Expand All @@ -36,7 +39,8 @@ func (GroupCreated) Unmarshal(v []byte) (interface{}, error) {

// GroupDeleted is emitted when a group was deleted
type GroupDeleted struct {
GroupID string
Executant *user.UserId
GroupID string
}

// Unmarshal to fulfill umarshaller interface
Expand All @@ -48,8 +52,9 @@ func (GroupDeleted) Unmarshal(v []byte) (interface{}, error) {

// GroupMemberAdded is emitted when a user was added to a group
type GroupMemberAdded struct {
GroupID string
UserID string
Executant *user.UserId
GroupID string
UserID string
}

// Unmarshal to fulfill umarshaller interface
Expand All @@ -61,8 +66,9 @@ func (GroupMemberAdded) Unmarshal(v []byte) (interface{}, error) {

// GroupMemberRemoved is emitted when a user was removed from a group
type GroupMemberRemoved struct {
GroupID string
UserID string
Executant *user.UserId
GroupID string
UserID string
}

// Unmarshal to fulfill umarshaller interface
Expand Down
Loading