diff --git a/changelog/unreleased/events-executant.md b/changelog/unreleased/events-executant.md new file mode 100644 index 0000000000..da8af25c56 --- /dev/null +++ b/changelog/unreleased/events-executant.md @@ -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 diff --git a/internal/grpc/interceptors/eventsmiddleware/conversion.go b/internal/grpc/interceptors/eventsmiddleware/conversion.go index c8e01b430f..df095b402d 100644 --- a/internal/grpc/interceptors/eventsmiddleware/conversion.go +++ b/internal/grpc/interceptors/eventsmiddleware/conversion.go @@ -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(), @@ -48,15 +49,16 @@ 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" @@ -64,6 +66,7 @@ func ShareUpdated(r *collaboration.UpdateShareResponse, req *collaboration.Updat updated = "displayname" } return events.ShareUpdated{ + Executant: executant, ShareID: r.Share.Id, ItemID: r.Share.ResourceId, Permissions: r.Share.Permissions, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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 @@ -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(), } @@ -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, } } @@ -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, } } @@ -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, } } diff --git a/internal/grpc/interceptors/eventsmiddleware/events.go b/internal/grpc/interceptors/eventsmiddleware/events.go index a57a0a1316..05f5fdd29e 100644 --- a/internal/grpc/interceptors/eventsmiddleware/events.go +++ b/internal/grpc/interceptors/eventsmiddleware/events.go @@ -72,37 +72,37 @@ 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) { @@ -110,7 +110,7 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error } 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) { @@ -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) { @@ -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) } } } diff --git a/pkg/events/files.go b/pkg/events/files.go index 58603bf25e..c1722d3917 100644 --- a/pkg/events/files.go +++ b/pkg/events/files.go @@ -29,6 +29,7 @@ import ( type ContainerCreated struct { Executant *user.UserId Ref *provider.Reference + Owner *user.UserId } // Unmarshal to fulfill umarshaller interface @@ -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 diff --git a/pkg/events/groups.go b/pkg/events/groups.go index a55d1fc281..495eb90352 100644 --- a/pkg/events/groups.go +++ b/pkg/events/groups.go @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/pkg/events/sharing.go b/pkg/events/sharing.go index f6ee9a5072..78da830188 100644 --- a/pkg/events/sharing.go +++ b/pkg/events/sharing.go @@ -32,7 +32,8 @@ import ( // ShareCreated is emitted when a share is created type ShareCreated struct { - Sharer *user.UserId + Executant *user.UserId + Sharer *user.UserId // split the protobuf Grantee oneof so we can use stdlib encoding/json GranteeUserID *user.UserId GranteeGroupID *group.GroupId @@ -51,6 +52,7 @@ func (ShareCreated) Unmarshal(v []byte) (interface{}, error) { // ShareRemoved is emitted when a share is removed type ShareRemoved struct { + Executant *user.UserId // split protobuf Spec ShareID *collaboration.ShareId ShareKey *collaboration.ShareKey @@ -65,6 +67,7 @@ func (ShareRemoved) Unmarshal(v []byte) (interface{}, error) { // ShareUpdated is emitted when a share is updated type ShareUpdated struct { + Executant *user.UserId ShareID *collaboration.ShareId ItemID *provider.ResourceId Permissions *collaboration.SharePermissions @@ -86,6 +89,7 @@ func (ShareUpdated) Unmarshal(v []byte) (interface{}, error) { // ReceivedShareUpdated is emitted when a received share is accepted or declined type ReceivedShareUpdated struct { + Executant *user.UserId ShareID *collaboration.ShareId ItemID *provider.ResourceId Permissions *collaboration.SharePermissions @@ -106,6 +110,7 @@ func (ReceivedShareUpdated) Unmarshal(v []byte) (interface{}, error) { // LinkCreated is emitted when a public link is created type LinkCreated struct { + Executant *user.UserId ShareID *link.PublicShareId Sharer *user.UserId ItemID *provider.ResourceId @@ -126,6 +131,7 @@ func (LinkCreated) Unmarshal(v []byte) (interface{}, error) { // LinkUpdated is emitted when a public link is updated type LinkUpdated struct { + Executant *user.UserId ShareID *link.PublicShareId Sharer *user.UserId ItemID *provider.ResourceId @@ -148,6 +154,7 @@ func (LinkUpdated) Unmarshal(v []byte) (interface{}, error) { // LinkAccessed is emitted when a public link is accessed successfully (by token) type LinkAccessed struct { + Executant *user.UserId ShareID *link.PublicShareId Sharer *user.UserId ItemID *provider.ResourceId @@ -168,10 +175,11 @@ func (LinkAccessed) Unmarshal(v []byte) (interface{}, error) { // LinkAccessFailed is emitted when an access to a public link has resulted in an error (by token) type LinkAccessFailed struct { - ShareID *link.PublicShareId - Token string - Status rpc.Code - Message string + Executant *user.UserId + ShareID *link.PublicShareId + Token string + Status rpc.Code + Message string } // Unmarshal to fulfill umarshaller interface @@ -183,6 +191,7 @@ func (LinkAccessFailed) Unmarshal(v []byte) (interface{}, error) { // LinkRemoved is emitted when a share is removed type LinkRemoved struct { + Executant *user.UserId // split protobuf Ref ShareID *link.PublicShareId ShareToken string diff --git a/pkg/events/spaces.go b/pkg/events/spaces.go index 4f03d2a678..aa60b0a27e 100644 --- a/pkg/events/spaces.go +++ b/pkg/events/spaces.go @@ -28,13 +28,14 @@ import ( // SpaceCreated is emitted when a space is created type SpaceCreated struct { - ID *provider.StorageSpaceId - Owner *user.UserId - Root *provider.ResourceId - Name string - Type string - Quota *provider.Quota - MTime *types.Timestamp + Executant *user.UserId + ID *provider.StorageSpaceId + Owner *user.UserId + Root *provider.ResourceId + Name string + Type string + Quota *provider.Quota + MTime *types.Timestamp } // Unmarshal to fulfill umarshaller interface @@ -46,9 +47,10 @@ func (SpaceCreated) Unmarshal(v []byte) (interface{}, error) { // SpaceRenamed is emitted when a space is renamed type SpaceRenamed struct { - ID *provider.StorageSpaceId - Owner *user.UserId - Name string + Executant *user.UserId + ID *provider.StorageSpaceId + Owner *user.UserId + Name string } // Unmarshal to fulfill umarshaller interface @@ -60,7 +62,8 @@ func (SpaceRenamed) Unmarshal(v []byte) (interface{}, error) { // SpaceDisabled is emitted when a space is disabled type SpaceDisabled struct { - ID *provider.StorageSpaceId + Executant *user.UserId + ID *provider.StorageSpaceId } // Unmarshal to fulfill umarshaller interface @@ -72,8 +75,9 @@ func (SpaceDisabled) Unmarshal(v []byte) (interface{}, error) { // SpaceEnabled is emitted when a space is (re-)enabled type SpaceEnabled struct { - ID *provider.StorageSpaceId - Owner *user.UserId + Executant *user.UserId + ID *provider.StorageSpaceId + Owner *user.UserId } // Unmarshal to fulfill umarshaller interface @@ -85,7 +89,8 @@ func (SpaceEnabled) Unmarshal(v []byte) (interface{}, error) { // SpaceDeleted is emitted when a space is deleted type SpaceDeleted struct { - ID *provider.StorageSpaceId + Executant *user.UserId + ID *provider.StorageSpaceId } // Unmarshal to fulfill umarshaller interface diff --git a/pkg/events/users.go b/pkg/events/users.go index 2656f95cca..1b03acf8e3 100644 --- a/pkg/events/users.go +++ b/pkg/events/users.go @@ -20,11 +20,14 @@ package events import ( "encoding/json" + + user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" ) // UserCreated is emitted when a user was created type UserCreated struct { - UserID string + Executant *user.UserId + UserID string } // Unmarshal to fulfill umarshaller interface @@ -36,7 +39,8 @@ func (UserCreated) Unmarshal(v []byte) (interface{}, error) { // UserDeleted is emitted when a user was deleted type UserDeleted struct { - UserID string + Executant *user.UserId + UserID string } // Unmarshal to fulfill umarshaller interface @@ -54,8 +58,9 @@ type UserFeature struct { // UserFeatureChanged is emitted when a user feature was changed type UserFeatureChanged struct { - UserID string - Features []UserFeature + Executant *user.UserId + UserID string + Features []UserFeature } // Unmarshal to fulfill umarshaller interface