Skip to content

Commit

Permalink
send fileunlocked events
Browse files Browse the repository at this point in the history
Signed-off-by: jkoberg <[email protected]>
  • Loading branch information
kobergj committed Mar 7, 2024
1 parent 9da2e18 commit 22fb438
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/file-unlocked-events.md
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions internal/grpc/interceptors/eventsmiddleware/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 9 additions & 0 deletions internal/grpc/interceptors/eventsmiddleware/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
30 changes: 30 additions & 0 deletions pkg/events/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 22fb438

Please sign in to comment.