From 22fb438c48dd21ecc671273c37c4769fa5f47d16 Mon Sep 17 00:00:00 2001 From: jkoberg Date: Thu, 7 Mar 2024 13:38:22 +0100 Subject: [PATCH] send fileunlocked events Signed-off-by: jkoberg --- changelog/unreleased/file-unlocked-events.md | 5 ++++ .../eventsmiddleware/conversion.go | 18 +++++++++++ .../interceptors/eventsmiddleware/events.go | 9 ++++++ pkg/events/files.go | 30 +++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 changelog/unreleased/file-unlocked-events.md diff --git a/changelog/unreleased/file-unlocked-events.md b/changelog/unreleased/file-unlocked-events.md new file mode 100644 index 0000000000..2d82a494a0 --- /dev/null +++ b/changelog/unreleased/file-unlocked-events.md @@ -0,0 +1,5 @@ +Enhancement: Send file locked/unlocked events + +Emit an event when a file is locked or unlocked + +https://github.com/cs3org/reva/pull/4564 diff --git a/internal/grpc/interceptors/eventsmiddleware/conversion.go b/internal/grpc/interceptors/eventsmiddleware/conversion.go index a4ff32f62b..edcab27e37 100644 --- a/internal/grpc/interceptors/eventsmiddleware/conversion.go +++ b/internal/grpc/interceptors/eventsmiddleware/conversion.go @@ -216,6 +216,24 @@ func FileDownloaded(r *provider.InitiateFileDownloadResponse, req *provider.Init } } +// FileLocked converts the response to an events +func FileLocked(r *provider.SetLockResponse, req *provider.SetLockRequest, owner, executant *user.UserId) events.FileLocked { + return events.FileLocked{ + Executant: executant, + Ref: req.Ref, + Timestamp: utils.TSNow(), + } +} + +// FileUnlocked converts the response to an event +func FileUnlocked(r *provider.UnlockResponse, req *provider.UnlockRequest, owner, executant *user.UserId) events.FileUnlocked { + return events.FileUnlocked{ + Executant: executant, + Ref: req.Ref, + Timestamp: utils.TSNow(), + } +} + // ItemTrashed converts the response to an event func ItemTrashed(r *provider.DeleteResponse, req *provider.DeleteRequest, spaceOwner, executant *user.UserId) events.ItemTrashed { opaqueID := utils.ReadPlainFromOpaque(r.Opaque, "opaque_id") diff --git a/internal/grpc/interceptors/eventsmiddleware/events.go b/internal/grpc/interceptors/eventsmiddleware/events.go index 8566f8bdef..558a96010d 100644 --- a/internal/grpc/interceptors/eventsmiddleware/events.go +++ b/internal/grpc/interceptors/eventsmiddleware/events.go @@ -184,6 +184,15 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error if isSuccess(v) { ev = FileTouched(v, req.(*provider.TouchFileRequest), ownerID, executantID) } + case *provider.SetLockResponse: + fmt.Println("set lock response", v) + if isSuccess(v) { + ev = FileLocked(v, req.(*provider.SetLockRequest), ownerID, executantID) + } + case *provider.UnlockResponse: + if isSuccess(v) { + ev = FileUnlocked(v, req.(*provider.UnlockRequest), ownerID, executantID) + } } if ev != nil { diff --git a/pkg/events/files.go b/pkg/events/files.go index cc21a4b07d..e4b1017fd2 100644 --- a/pkg/events/files.go +++ b/pkg/events/files.go @@ -88,6 +88,36 @@ func (FileDownloaded) Unmarshal(v []byte) (interface{}, error) { return e, err } +// FileLocked is emitted when a file is locked +type FileLocked struct { + Executant *user.UserId + Ref *provider.Reference + Owner *user.UserId + Timestamp *types.Timestamp +} + +// Unmarshal to fulfill umarshaller interface +func (FileLocked) Unmarshal(v []byte) (interface{}, error) { + e := FileLocked{} + err := json.Unmarshal(v, &e) + return e, err +} + +// FileUnlocked is emitted when a file is unlocked +type FileUnlocked struct { + Executant *user.UserId + Ref *provider.Reference + Owner *user.UserId + Timestamp *types.Timestamp +} + +// Unmarshal to fulfill umarshaller interface +func (FileUnlocked) Unmarshal(v []byte) (interface{}, error) { + e := FileUnlocked{} + err := json.Unmarshal(v, &e) + return e, err +} + // ItemTrashed is emitted when a file or folder is trashed type ItemTrashed struct { SpaceOwner *user.UserId