diff --git a/internal/grpc/interceptors/eventsmiddleware/conversion.go b/internal/grpc/interceptors/eventsmiddleware/conversion.go index 9e5a739e0f..0bdedfe4ce 100644 --- a/internal/grpc/interceptors/eventsmiddleware/conversion.go +++ b/internal/grpc/interceptors/eventsmiddleware/conversion.go @@ -32,20 +32,21 @@ import ( ) // ContainerCreated converts the response to an event -func ContainerCreated(r *provider.CreateContainerResponse, req *provider.CreateContainerRequest, spaceOwner, executant *user.UserId) events.ContainerCreated { +func ContainerCreated(r *provider.CreateContainerResponse, req *provider.CreateContainerRequest, spaceOwner *user.UserId, executant *user.User) events.ContainerCreated { return events.ContainerCreated{ - SpaceOwner: spaceOwner, - Executant: executant, - Ref: req.Ref, - Timestamp: utils.TSNow(), + SpaceOwner: spaceOwner, + Executant: executant.GetId(), + Ref: req.Ref, + Timestamp: utils.TSNow(), + ImpersonatingUser: extractImpersonator(executant), } } // ShareCreated converts the response to an event -func ShareCreated(r *collaboration.CreateShareResponse, executant *user.UserId) events.ShareCreated { +func ShareCreated(r *collaboration.CreateShareResponse, executant *user.User) events.ShareCreated { return events.ShareCreated{ ShareID: r.Share.GetId(), - Executant: executant, + Executant: executant.GetId(), Sharer: r.Share.Creator, GranteeUserID: r.Share.GetGrantee().GetUserId(), GranteeGroupID: r.Share.GetGrantee().GetGroupId(), @@ -56,7 +57,7 @@ func ShareCreated(r *collaboration.CreateShareResponse, executant *user.UserId) } // ShareRemoved converts the response to an event -func ShareRemoved(r *collaboration.RemoveShareResponse, req *collaboration.RemoveShareRequest, executant *user.UserId) events.ShareRemoved { +func ShareRemoved(r *collaboration.RemoveShareResponse, req *collaboration.RemoveShareRequest, executant *user.User) events.ShareRemoved { var ( userid *user.UserId groupid *group.GroupId @@ -66,7 +67,7 @@ func ShareRemoved(r *collaboration.RemoveShareResponse, req *collaboration.Remov _ = utils.ReadJSONFromOpaque(r.Opaque, "granteegroupid", &userid) _ = utils.ReadJSONFromOpaque(r.Opaque, "resourceid", &rid) return events.ShareRemoved{ - Executant: executant, + Executant: executant.GetId(), ShareID: req.Ref.GetId(), ShareKey: req.Ref.GetKey(), GranteeUserID: userid, @@ -77,9 +78,9 @@ func ShareRemoved(r *collaboration.RemoveShareResponse, req *collaboration.Remov } // ShareUpdated converts the response to an event -func ShareUpdated(r *collaboration.UpdateShareResponse, req *collaboration.UpdateShareRequest, executant *user.UserId) events.ShareUpdated { +func ShareUpdated(r *collaboration.UpdateShareResponse, req *collaboration.UpdateShareRequest, executant *user.User) events.ShareUpdated { return events.ShareUpdated{ - Executant: executant, + Executant: executant.GetId(), ShareID: r.Share.Id, ItemID: r.Share.ResourceId, Permissions: r.Share.Permissions, @@ -92,9 +93,9 @@ func ShareUpdated(r *collaboration.UpdateShareResponse, req *collaboration.Updat } // ReceivedShareUpdated converts the response to an event -func ReceivedShareUpdated(r *collaboration.UpdateReceivedShareResponse, executant *user.UserId) events.ReceivedShareUpdated { +func ReceivedShareUpdated(r *collaboration.UpdateReceivedShareResponse, executant *user.User) events.ReceivedShareUpdated { return events.ReceivedShareUpdated{ - Executant: executant, + Executant: executant.GetId(), ShareID: r.Share.Share.Id, ItemID: r.Share.Share.ResourceId, Permissions: r.Share.Share.Permissions, @@ -107,9 +108,9 @@ func ReceivedShareUpdated(r *collaboration.UpdateReceivedShareResponse, executan } // LinkCreated converts the response to an event -func LinkCreated(r *link.CreatePublicShareResponse, executant *user.UserId) events.LinkCreated { +func LinkCreated(r *link.CreatePublicShareResponse, executant *user.User) events.LinkCreated { return events.LinkCreated{ - Executant: executant, + Executant: executant.GetId(), ShareID: r.Share.Id, Sharer: r.Share.Creator, ItemID: r.Share.ResourceId, @@ -123,9 +124,9 @@ func LinkCreated(r *link.CreatePublicShareResponse, executant *user.UserId) even } // LinkUpdated converts the response to an event -func LinkUpdated(r *link.UpdatePublicShareResponse, req *link.UpdatePublicShareRequest, executant *user.UserId) events.LinkUpdated { +func LinkUpdated(r *link.UpdatePublicShareResponse, req *link.UpdatePublicShareRequest, executant *user.User) events.LinkUpdated { return events.LinkUpdated{ - Executant: executant, + Executant: executant.GetId(), ShareID: r.Share.Id, Sharer: r.Share.Creator, ItemID: r.Share.ResourceId, @@ -140,9 +141,9 @@ func LinkUpdated(r *link.UpdatePublicShareResponse, req *link.UpdatePublicShareR } // LinkAccessed converts the response to an event -func LinkAccessed(r *link.GetPublicShareByTokenResponse, executant *user.UserId) events.LinkAccessed { +func LinkAccessed(r *link.GetPublicShareByTokenResponse, executant *user.User) events.LinkAccessed { return events.LinkAccessed{ - Executant: executant, + Executant: executant.GetId(), ShareID: r.Share.Id, Sharer: r.Share.Creator, ItemID: r.Share.ResourceId, @@ -156,9 +157,9 @@ func LinkAccessed(r *link.GetPublicShareByTokenResponse, executant *user.UserId) } // LinkAccessFailed converts the response to an event -func LinkAccessFailed(r *link.GetPublicShareByTokenResponse, req *link.GetPublicShareByTokenRequest, executant *user.UserId) events.LinkAccessFailed { +func LinkAccessFailed(r *link.GetPublicShareByTokenResponse, req *link.GetPublicShareByTokenRequest, executant *user.User) events.LinkAccessFailed { e := events.LinkAccessFailed{ - Executant: executant, + Executant: executant.GetId(), Status: r.Status.Code, Message: r.Status.Message, Timestamp: utils.TSNow(), @@ -172,11 +173,11 @@ func LinkAccessFailed(r *link.GetPublicShareByTokenResponse, req *link.GetPublic } // LinkRemoved converts the response to an event -func LinkRemoved(r *link.RemovePublicShareResponse, req *link.RemovePublicShareRequest, executant *user.UserId) events.LinkRemoved { +func LinkRemoved(r *link.RemovePublicShareResponse, req *link.RemovePublicShareRequest, executant *user.User) events.LinkRemoved { var rid *provider.ResourceId _ = utils.ReadJSONFromOpaque(r.Opaque, "resourceid", &rid) return events.LinkRemoved{ - Executant: executant, + Executant: executant.GetId(), ShareID: req.Ref.GetId(), ShareToken: req.Ref.GetToken(), Timestamp: utils.TSNow(), @@ -185,119 +186,129 @@ func LinkRemoved(r *link.RemovePublicShareResponse, req *link.RemovePublicShareR } // FileTouched converts the response to an event -func FileTouched(r *provider.TouchFileResponse, req *provider.TouchFileRequest, spaceOwner, executant *user.UserId) events.FileTouched { +func FileTouched(r *provider.TouchFileResponse, req *provider.TouchFileRequest, spaceOwner *user.UserId, executant *user.User) events.FileTouched { return events.FileTouched{ - SpaceOwner: spaceOwner, - Executant: executant, - Ref: req.Ref, - Timestamp: utils.TSNow(), + SpaceOwner: spaceOwner, + Executant: executant.GetId(), + Ref: req.Ref, + Timestamp: utils.TSNow(), + ImpersonatingUser: extractImpersonator(executant), } } // FileUploaded converts the response to an event -func FileUploaded(r *provider.InitiateFileUploadResponse, req *provider.InitiateFileUploadRequest, spaceOwner, executant *user.UserId) events.FileUploaded { +func FileUploaded(r *provider.InitiateFileUploadResponse, req *provider.InitiateFileUploadRequest, spaceOwner *user.UserId, executant *user.User) events.FileUploaded { return events.FileUploaded{ - SpaceOwner: spaceOwner, - Executant: executant, - Ref: req.Ref, - Timestamp: utils.TSNow(), + SpaceOwner: spaceOwner, + Executant: executant.GetId(), + Ref: req.Ref, + Timestamp: utils.TSNow(), + ImpersonatingUser: extractImpersonator(executant), } } // FileDownloaded converts the response to an event -func FileDownloaded(r *provider.InitiateFileDownloadResponse, req *provider.InitiateFileDownloadRequest, executant *user.UserId) events.FileDownloaded { +func FileDownloaded(r *provider.InitiateFileDownloadResponse, req *provider.InitiateFileDownloadRequest, executant *user.User) events.FileDownloaded { return events.FileDownloaded{ - Executant: executant, - Ref: req.Ref, - Timestamp: utils.TSNow(), + Executant: executant.GetId(), + Ref: req.Ref, + Timestamp: utils.TSNow(), + ImpersonatingUser: extractImpersonator(executant), } } // FileLocked converts the response to an events -func FileLocked(r *provider.SetLockResponse, req *provider.SetLockRequest, owner, executant *user.UserId) events.FileLocked { +func FileLocked(r *provider.SetLockResponse, req *provider.SetLockRequest, owner *user.UserId, executant *user.User) events.FileLocked { return events.FileLocked{ - Executant: executant, - Ref: req.Ref, - Timestamp: utils.TSNow(), + Executant: executant.GetId(), + Ref: req.Ref, + Timestamp: utils.TSNow(), + ImpersonatingUser: extractImpersonator(executant), } } // FileUnlocked converts the response to an event -func FileUnlocked(r *provider.UnlockResponse, req *provider.UnlockRequest, owner, executant *user.UserId) events.FileUnlocked { +func FileUnlocked(r *provider.UnlockResponse, req *provider.UnlockRequest, owner *user.UserId, executant *user.User) events.FileUnlocked { return events.FileUnlocked{ - Executant: executant, - Ref: req.Ref, - Timestamp: utils.TSNow(), + Executant: executant.GetId(), + Ref: req.Ref, + Timestamp: utils.TSNow(), + ImpersonatingUser: extractImpersonator(executant), } } // ItemTrashed converts the response to an event -func ItemTrashed(r *provider.DeleteResponse, req *provider.DeleteRequest, spaceOwner, executant *user.UserId) events.ItemTrashed { +func ItemTrashed(r *provider.DeleteResponse, req *provider.DeleteRequest, spaceOwner *user.UserId, executant *user.User) events.ItemTrashed { opaqueID := utils.ReadPlainFromOpaque(r.Opaque, "opaque_id") return events.ItemTrashed{ SpaceOwner: spaceOwner, - Executant: executant, + Executant: executant.GetId(), Ref: req.Ref, ID: &provider.ResourceId{ StorageId: req.Ref.GetResourceId().GetStorageId(), SpaceId: req.Ref.GetResourceId().GetSpaceId(), OpaqueId: opaqueID, }, - Timestamp: utils.TSNow(), + Timestamp: utils.TSNow(), + ImpersonatingUser: extractImpersonator(executant), } } // ItemMoved converts the response to an event -func ItemMoved(r *provider.MoveResponse, req *provider.MoveRequest, spaceOwner, executant *user.UserId) events.ItemMoved { +func ItemMoved(r *provider.MoveResponse, req *provider.MoveRequest, spaceOwner *user.UserId, executant *user.User) events.ItemMoved { return events.ItemMoved{ - SpaceOwner: spaceOwner, - Executant: executant, - Ref: req.Destination, - OldReference: req.Source, - Timestamp: utils.TSNow(), + SpaceOwner: spaceOwner, + Executant: executant.GetId(), + Ref: req.Destination, + OldReference: req.Source, + Timestamp: utils.TSNow(), + ImpersonatingUser: extractImpersonator(executant), } } // ItemPurged converts the response to an event -func ItemPurged(r *provider.PurgeRecycleResponse, req *provider.PurgeRecycleRequest, executant *user.UserId) events.ItemPurged { +func ItemPurged(r *provider.PurgeRecycleResponse, req *provider.PurgeRecycleRequest, executant *user.User) events.ItemPurged { return events.ItemPurged{ - Executant: executant, - Ref: req.Ref, - Timestamp: utils.TSNow(), + Executant: executant.GetId(), + Ref: req.Ref, + Timestamp: utils.TSNow(), + ImpersonatingUser: extractImpersonator(executant), } } // ItemRestored converts the response to an event -func ItemRestored(r *provider.RestoreRecycleItemResponse, req *provider.RestoreRecycleItemRequest, spaceOwner, executant *user.UserId) events.ItemRestored { +func ItemRestored(r *provider.RestoreRecycleItemResponse, req *provider.RestoreRecycleItemRequest, spaceOwner *user.UserId, executant *user.User) events.ItemRestored { ref := req.Ref if req.RestoreRef != nil { ref = req.RestoreRef } return events.ItemRestored{ - SpaceOwner: spaceOwner, - Executant: executant, - Ref: ref, - OldReference: req.Ref, - Key: req.Key, - Timestamp: utils.TSNow(), + SpaceOwner: spaceOwner, + Executant: executant.GetId(), + Ref: ref, + OldReference: req.Ref, + Key: req.Key, + Timestamp: utils.TSNow(), + ImpersonatingUser: extractImpersonator(executant), } } // FileVersionRestored converts the response to an event -func FileVersionRestored(r *provider.RestoreFileVersionResponse, req *provider.RestoreFileVersionRequest, spaceOwner, executant *user.UserId) events.FileVersionRestored { +func FileVersionRestored(r *provider.RestoreFileVersionResponse, req *provider.RestoreFileVersionRequest, spaceOwner *user.UserId, executant *user.User) events.FileVersionRestored { return events.FileVersionRestored{ - SpaceOwner: spaceOwner, - Executant: executant, - Ref: req.Ref, - Key: req.Key, - Timestamp: utils.TSNow(), + SpaceOwner: spaceOwner, + Executant: executant.GetId(), + Ref: req.Ref, + Key: req.Key, + Timestamp: utils.TSNow(), + ImpersonatingUser: extractImpersonator(executant), } } // SpaceCreated converts the response to an event -func SpaceCreated(r *provider.CreateStorageSpaceResponse, executant *user.UserId) events.SpaceCreated { +func SpaceCreated(r *provider.CreateStorageSpaceResponse, executant *user.User) events.SpaceCreated { return events.SpaceCreated{ - Executant: executant, + Executant: executant.GetId(), ID: r.StorageSpace.Id, Owner: extractOwner(r.StorageSpace.Owner), Root: r.StorageSpace.Root, @@ -309,9 +320,9 @@ func SpaceCreated(r *provider.CreateStorageSpaceResponse, executant *user.UserId } // SpaceRenamed converts the response to an event -func SpaceRenamed(r *provider.UpdateStorageSpaceResponse, req *provider.UpdateStorageSpaceRequest, executant *user.UserId) events.SpaceRenamed { +func SpaceRenamed(r *provider.UpdateStorageSpaceResponse, req *provider.UpdateStorageSpaceRequest, executant *user.User) events.SpaceRenamed { return events.SpaceRenamed{ - Executant: executant, + Executant: executant.GetId(), ID: r.StorageSpace.Id, Owner: extractOwner(r.StorageSpace.Owner), Name: r.StorageSpace.Name, @@ -320,9 +331,9 @@ func SpaceRenamed(r *provider.UpdateStorageSpaceResponse, req *provider.UpdateSt } // SpaceUpdated converts the response to an event -func SpaceUpdated(r *provider.UpdateStorageSpaceResponse, req *provider.UpdateStorageSpaceRequest, executant *user.UserId) events.SpaceUpdated { +func SpaceUpdated(r *provider.UpdateStorageSpaceResponse, req *provider.UpdateStorageSpaceRequest, executant *user.User) events.SpaceUpdated { return events.SpaceUpdated{ - Executant: executant, + Executant: executant.GetId(), ID: r.StorageSpace.Id, Space: r.StorageSpace, Timestamp: utils.TSNow(), @@ -330,9 +341,9 @@ func SpaceUpdated(r *provider.UpdateStorageSpaceResponse, req *provider.UpdateSt } // SpaceEnabled converts the response to an event -func SpaceEnabled(r *provider.UpdateStorageSpaceResponse, req *provider.UpdateStorageSpaceRequest, executant *user.UserId) events.SpaceEnabled { +func SpaceEnabled(r *provider.UpdateStorageSpaceResponse, req *provider.UpdateStorageSpaceRequest, executant *user.User) events.SpaceEnabled { return events.SpaceEnabled{ - Executant: executant, + Executant: executant.GetId(), ID: r.StorageSpace.Id, Owner: extractOwner(r.StorageSpace.Owner), Timestamp: utils.TSNow(), @@ -341,10 +352,10 @@ func SpaceEnabled(r *provider.UpdateStorageSpaceResponse, req *provider.UpdateSt // SpaceShared converts the response to an event // func SpaceShared(req *provider.AddGrantRequest, executant, sharer *user.UserId, grantee *provider.Grantee) events.SpaceShared { -func SpaceShared(r *provider.AddGrantResponse, req *provider.AddGrantRequest, executant *user.UserId) events.SpaceShared { +func SpaceShared(r *provider.AddGrantResponse, req *provider.AddGrantRequest, executant *user.User) events.SpaceShared { id := storagespace.FormatStorageID(req.Ref.ResourceId.StorageId, req.Ref.ResourceId.SpaceId) return events.SpaceShared{ - Executant: executant, + Executant: executant.GetId(), Creator: req.Grant.Creator, GranteeUserID: req.Grant.GetGrantee().GetUserId(), GranteeGroupID: req.Grant.GetGrantee().GetGroupId(), @@ -354,10 +365,10 @@ func SpaceShared(r *provider.AddGrantResponse, req *provider.AddGrantRequest, ex } // SpaceShareUpdated converts the response to an events -func SpaceShareUpdated(r *provider.UpdateGrantResponse, req *provider.UpdateGrantRequest, executant *user.UserId) events.SpaceShareUpdated { +func SpaceShareUpdated(r *provider.UpdateGrantResponse, req *provider.UpdateGrantRequest, executant *user.User) events.SpaceShareUpdated { id := storagespace.FormatStorageID(req.Ref.ResourceId.StorageId, req.Ref.ResourceId.SpaceId) return events.SpaceShareUpdated{ - Executant: executant, + Executant: executant.GetId(), GranteeUserID: req.Grant.GetGrantee().GetUserId(), GranteeGroupID: req.Grant.GetGrantee().GetGroupId(), ID: &provider.StorageSpaceId{OpaqueId: id}, @@ -366,10 +377,10 @@ func SpaceShareUpdated(r *provider.UpdateGrantResponse, req *provider.UpdateGran } // SpaceUnshared converts the response to an event -func SpaceUnshared(r *provider.RemoveGrantResponse, req *provider.RemoveGrantRequest, executant *user.UserId) events.SpaceUnshared { +func SpaceUnshared(r *provider.RemoveGrantResponse, req *provider.RemoveGrantRequest, executant *user.User) events.SpaceUnshared { id := storagespace.FormatStorageID(req.Ref.ResourceId.StorageId, req.Ref.ResourceId.SpaceId) return events.SpaceUnshared{ - Executant: executant, + Executant: executant.GetId(), GranteeUserID: req.Grant.GetGrantee().GetUserId(), GranteeGroupID: req.Grant.GetGrantee().GetGroupId(), ID: &provider.StorageSpaceId{OpaqueId: id}, @@ -378,20 +389,20 @@ func SpaceUnshared(r *provider.RemoveGrantResponse, req *provider.RemoveGrantReq } // SpaceDisabled converts the response to an event -func SpaceDisabled(r *provider.DeleteStorageSpaceResponse, req *provider.DeleteStorageSpaceRequest, executant *user.UserId) events.SpaceDisabled { +func SpaceDisabled(r *provider.DeleteStorageSpaceResponse, req *provider.DeleteStorageSpaceRequest, executant *user.User) events.SpaceDisabled { return events.SpaceDisabled{ - Executant: executant, + Executant: executant.GetId(), ID: req.Id, Timestamp: time.Now(), } } // SpaceDeleted converts the response to an event -func SpaceDeleted(r *provider.DeleteStorageSpaceResponse, req *provider.DeleteStorageSpaceRequest, executant *user.UserId) events.SpaceDeleted { +func SpaceDeleted(r *provider.DeleteStorageSpaceResponse, req *provider.DeleteStorageSpaceRequest, executant *user.User) events.SpaceDeleted { var final map[string]provider.ResourcePermissions _ = utils.ReadJSONFromOpaque(r.GetOpaque(), "grants", &final) return events.SpaceDeleted{ - Executant: executant, + Executant: executant.GetId(), ID: req.Id, SpaceName: utils.ReadPlainFromOpaque(r.GetOpaque(), "spacename"), FinalMembers: final, @@ -405,3 +416,11 @@ func extractOwner(u *user.User) *user.UserId { } return nil } + +func extractImpersonator(u *user.User) *user.User { + var impersonator user.User + if err := utils.ReadJSONFromOpaque(u.Opaque, "impersonating-user", &impersonator); err != nil { + return nil + } + return &impersonator +} diff --git a/internal/grpc/interceptors/eventsmiddleware/events.go b/internal/grpc/interceptors/eventsmiddleware/events.go index ca4086bfb2..961cd42920 100644 --- a/internal/grpc/interceptors/eventsmiddleware/events.go +++ b/internal/grpc/interceptors/eventsmiddleware/events.go @@ -73,47 +73,43 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error default: } - var executantID *user.UserId - u, ok := revactx.ContextGetUser(ctx) - if ok { - executantID = u.Id - } + executant, _ := revactx.ContextGetUser(ctx) var ev interface{} switch v := res.(type) { case *collaboration.CreateShareResponse: if isSuccess(v) { - ev = ShareCreated(v, executantID) + ev = ShareCreated(v, executant) } case *collaboration.RemoveShareResponse: if isSuccess(v) { - ev = ShareRemoved(v, req.(*collaboration.RemoveShareRequest), executantID) + ev = ShareRemoved(v, req.(*collaboration.RemoveShareRequest), executant) } case *collaboration.UpdateShareResponse: if isSuccess(v) { - ev = ShareUpdated(v, req.(*collaboration.UpdateShareRequest), executantID) + ev = ShareUpdated(v, req.(*collaboration.UpdateShareRequest), executant) } case *collaboration.UpdateReceivedShareResponse: if isSuccess(v) { - ev = ReceivedShareUpdated(v, executantID) + ev = ReceivedShareUpdated(v, executant) } case *link.CreatePublicShareResponse: if isSuccess(v) { - ev = LinkCreated(v, executantID) + ev = LinkCreated(v, executant) } case *link.UpdatePublicShareResponse: if isSuccess(v) { - ev = LinkUpdated(v, req.(*link.UpdatePublicShareRequest), executantID) + ev = LinkUpdated(v, req.(*link.UpdatePublicShareRequest), executant) } case *link.RemovePublicShareResponse: if isSuccess(v) { - ev = LinkRemoved(v, req.(*link.RemovePublicShareRequest), executantID) + ev = LinkRemoved(v, req.(*link.RemovePublicShareRequest), executant) } case *link.GetPublicShareByTokenResponse: if isSuccess(v) { - ev = LinkAccessed(v, executantID) + ev = LinkAccessed(v, executant) } else { - ev = LinkAccessFailed(v, req.(*link.GetPublicShareByTokenRequest), executantID) + ev = LinkAccessFailed(v, req.(*link.GetPublicShareByTokenRequest), executant) } case *provider.AddGrantResponse: // TODO: update CS3 APIs @@ -121,81 +117,81 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error // https://github.com/owncloud/ocis/issues/4312 r := req.(*provider.AddGrantRequest) if isSuccess(v) && utils.ExistsInOpaque(r.Opaque, "spacegrant") { - ev = SpaceShared(v, r, executantID) + ev = SpaceShared(v, r, executant) } case *provider.UpdateGrantResponse: r := req.(*provider.UpdateGrantRequest) if isSuccess(v) && utils.ExistsInOpaque(r.Opaque, "spacegrant") { - ev = SpaceShareUpdated(v, r, executantID) + ev = SpaceShareUpdated(v, r, executant) } case *provider.RemoveGrantResponse: r := req.(*provider.RemoveGrantRequest) if isSuccess(v) && utils.ExistsInOpaque(r.Opaque, "spacegrant") { - ev = SpaceUnshared(v, req.(*provider.RemoveGrantRequest), executantID) + ev = SpaceUnshared(v, req.(*provider.RemoveGrantRequest), executant) } case *provider.CreateContainerResponse: if isSuccess(v) { - ev = ContainerCreated(v, req.(*provider.CreateContainerRequest), ownerID, executantID) + ev = ContainerCreated(v, req.(*provider.CreateContainerRequest), ownerID, executant) } case *provider.InitiateFileDownloadResponse: if isSuccess(v) { - ev = FileDownloaded(v, req.(*provider.InitiateFileDownloadRequest), executantID) + ev = FileDownloaded(v, req.(*provider.InitiateFileDownloadRequest), executant) } case *provider.DeleteResponse: if isSuccess(v) { - ev = ItemTrashed(v, req.(*provider.DeleteRequest), ownerID, executantID) + ev = ItemTrashed(v, req.(*provider.DeleteRequest), ownerID, executant) } case *provider.MoveResponse: if isSuccess(v) { - ev = ItemMoved(v, req.(*provider.MoveRequest), ownerID, executantID) + ev = ItemMoved(v, req.(*provider.MoveRequest), ownerID, executant) } case *provider.PurgeRecycleResponse: if isSuccess(v) { - ev = ItemPurged(v, req.(*provider.PurgeRecycleRequest), executantID) + ev = ItemPurged(v, req.(*provider.PurgeRecycleRequest), executant) } case *provider.RestoreRecycleItemResponse: if isSuccess(v) { - ev = ItemRestored(v, req.(*provider.RestoreRecycleItemRequest), ownerID, executantID) + ev = ItemRestored(v, req.(*provider.RestoreRecycleItemRequest), ownerID, executant) } case *provider.RestoreFileVersionResponse: if isSuccess(v) { - ev = FileVersionRestored(v, req.(*provider.RestoreFileVersionRequest), ownerID, executantID) + ev = FileVersionRestored(v, req.(*provider.RestoreFileVersionRequest), ownerID, executant) } case *provider.CreateStorageSpaceResponse: if isSuccess(v) && v.StorageSpace != nil { // TODO: Why are there CreateStorageSpaceResponses with nil StorageSpace? - ev = SpaceCreated(v, executantID) + ev = SpaceCreated(v, executant) } case *provider.UpdateStorageSpaceResponse: if isSuccess(v) { r := req.(*provider.UpdateStorageSpaceRequest) if r.StorageSpace.Name != "" { - ev = SpaceRenamed(v, r, executantID) + ev = SpaceRenamed(v, r, executant) } else if utils.ExistsInOpaque(r.Opaque, "restore") { - ev = SpaceEnabled(v, r, executantID) + ev = SpaceEnabled(v, r, executant) } else { - ev = SpaceUpdated(v, r, executantID) + ev = SpaceUpdated(v, r, executant) } } case *provider.DeleteStorageSpaceResponse: if isSuccess(v) { r := req.(*provider.DeleteStorageSpaceRequest) if utils.ExistsInOpaque(r.Opaque, "purge") { - ev = SpaceDeleted(v, r, executantID) + ev = SpaceDeleted(v, r, executant) } else { - ev = SpaceDisabled(v, r, executantID) + ev = SpaceDisabled(v, r, executant) } } case *provider.TouchFileResponse: if isSuccess(v) { - ev = FileTouched(v, req.(*provider.TouchFileRequest), ownerID, executantID) + ev = FileTouched(v, req.(*provider.TouchFileRequest), ownerID, executant) } case *provider.SetLockResponse: if isSuccess(v) { - ev = FileLocked(v, req.(*provider.SetLockRequest), ownerID, executantID) + ev = FileLocked(v, req.(*provider.SetLockRequest), ownerID, executant) } case *provider.UnlockResponse: if isSuccess(v) { - ev = FileUnlocked(v, req.(*provider.UnlockRequest), ownerID, executantID) + ev = FileUnlocked(v, req.(*provider.UnlockRequest), ownerID, executant) } } diff --git a/pkg/events/files.go b/pkg/events/files.go index e4b1017fd2..0fb60d563d 100644 --- a/pkg/events/files.go +++ b/pkg/events/files.go @@ -28,11 +28,12 @@ import ( // ContainerCreated is emitted when a directory has been created type ContainerCreated struct { - SpaceOwner *user.UserId - Executant *user.UserId - Ref *provider.Reference - Owner *user.UserId - Timestamp *types.Timestamp + SpaceOwner *user.UserId + Executant *user.UserId + Ref *provider.Reference + Owner *user.UserId + Timestamp *types.Timestamp + ImpersonatingUser *user.User } // Unmarshal to fulfill umarshaller interface @@ -44,11 +45,12 @@ func (ContainerCreated) Unmarshal(v []byte) (interface{}, error) { // FileUploaded is emitted when a file is uploaded type FileUploaded struct { - SpaceOwner *user.UserId - Executant *user.UserId - Ref *provider.Reference - Owner *user.UserId - Timestamp *types.Timestamp + SpaceOwner *user.UserId + Executant *user.UserId + Ref *provider.Reference + Owner *user.UserId + Timestamp *types.Timestamp + ImpersonatingUser *user.User } // Unmarshal to fulfill umarshaller interface @@ -60,10 +62,11 @@ func (FileUploaded) Unmarshal(v []byte) (interface{}, error) { // FileTouched is emitted when a file is uploaded type FileTouched struct { - SpaceOwner *user.UserId - Executant *user.UserId - Ref *provider.Reference - Timestamp *types.Timestamp + SpaceOwner *user.UserId + Executant *user.UserId + Ref *provider.Reference + Timestamp *types.Timestamp + ImpersonatingUser *user.User } // Unmarshal to fulfill umarshaller interface @@ -75,10 +78,11 @@ func (FileTouched) Unmarshal(v []byte) (interface{}, error) { // FileDownloaded is emitted when a file is downloaded type FileDownloaded struct { - Executant *user.UserId - Ref *provider.Reference - Owner *user.UserId - Timestamp *types.Timestamp + Executant *user.UserId + Ref *provider.Reference + Owner *user.UserId + Timestamp *types.Timestamp + ImpersonatingUser *user.User } // Unmarshal to fulfill umarshaller interface @@ -90,10 +94,11 @@ func (FileDownloaded) Unmarshal(v []byte) (interface{}, error) { // FileLocked is emitted when a file is locked type FileLocked struct { - Executant *user.UserId - Ref *provider.Reference - Owner *user.UserId - Timestamp *types.Timestamp + Executant *user.UserId + Ref *provider.Reference + Owner *user.UserId + Timestamp *types.Timestamp + ImpersonatingUser *user.User } // Unmarshal to fulfill umarshaller interface @@ -105,10 +110,11 @@ func (FileLocked) Unmarshal(v []byte) (interface{}, error) { // FileUnlocked is emitted when a file is unlocked type FileUnlocked struct { - Executant *user.UserId - Ref *provider.Reference - Owner *user.UserId - Timestamp *types.Timestamp + Executant *user.UserId + Ref *provider.Reference + Owner *user.UserId + Timestamp *types.Timestamp + ImpersonatingUser *user.User } // Unmarshal to fulfill umarshaller interface @@ -120,12 +126,13 @@ func (FileUnlocked) Unmarshal(v []byte) (interface{}, error) { // ItemTrashed is emitted when a file or folder is trashed type ItemTrashed struct { - SpaceOwner *user.UserId - Executant *user.UserId - ID *provider.ResourceId - Ref *provider.Reference - Owner *user.UserId - Timestamp *types.Timestamp + SpaceOwner *user.UserId + Executant *user.UserId + ID *provider.ResourceId + Ref *provider.Reference + Owner *user.UserId + Timestamp *types.Timestamp + ImpersonatingUser *user.User } // Unmarshal to fulfill umarshaller interface @@ -137,12 +144,13 @@ func (ItemTrashed) Unmarshal(v []byte) (interface{}, error) { // ItemMoved is emitted when a file or folder is moved type ItemMoved struct { - SpaceOwner *user.UserId - Executant *user.UserId - Ref *provider.Reference - Owner *user.UserId - OldReference *provider.Reference - Timestamp *types.Timestamp + SpaceOwner *user.UserId + Executant *user.UserId + Ref *provider.Reference + Owner *user.UserId + OldReference *provider.Reference + Timestamp *types.Timestamp + ImpersonatingUser *user.User } // Unmarshal to fulfill umarshaller interface @@ -154,11 +162,12 @@ func (ItemMoved) Unmarshal(v []byte) (interface{}, error) { // ItemPurged is emitted when a file or folder is removed from trashbin type ItemPurged struct { - Executant *user.UserId - ID *provider.ResourceId - Ref *provider.Reference - Owner *user.UserId - Timestamp *types.Timestamp + Executant *user.UserId + ID *provider.ResourceId + Ref *provider.Reference + Owner *user.UserId + Timestamp *types.Timestamp + ImpersonatingUser *user.User } // Unmarshal to fulfill umarshaller interface @@ -170,14 +179,15 @@ func (ItemPurged) Unmarshal(v []byte) (interface{}, error) { // ItemRestored is emitted when a file or folder is restored from trashbin type ItemRestored struct { - SpaceOwner *user.UserId - Executant *user.UserId - ID *provider.ResourceId - Ref *provider.Reference - Owner *user.UserId - OldReference *provider.Reference - Key string - Timestamp *types.Timestamp + SpaceOwner *user.UserId + Executant *user.UserId + ID *provider.ResourceId + Ref *provider.Reference + Owner *user.UserId + OldReference *provider.Reference + Key string + Timestamp *types.Timestamp + ImpersonatingUser *user.User } // Unmarshal to fulfill umarshaller interface @@ -189,12 +199,13 @@ func (ItemRestored) Unmarshal(v []byte) (interface{}, error) { // FileVersionRestored is emitted when a file version is restored type FileVersionRestored struct { - SpaceOwner *user.UserId - Executant *user.UserId - Ref *provider.Reference - Owner *user.UserId - Key string - Timestamp *types.Timestamp + SpaceOwner *user.UserId + Executant *user.UserId + Ref *provider.Reference + Owner *user.UserId + Key string + Timestamp *types.Timestamp + ImpersonatingUser *user.User } // Unmarshal to fulfill umarshaller interface