Skip to content

Commit

Permalink
add spaceshared event (cs3org#3252)
Browse files Browse the repository at this point in the history
* add spaceshared event

Signed-off-by: Christian Richter <[email protected]>

* add changelog

Signed-off-by: Christian Richter <[email protected]>

* fix typo

Signed-off-by: Christian Richter <[email protected]>

Signed-off-by: Christian Richter <[email protected]>
  • Loading branch information
dragonchaser authored Sep 20, 2022
1 parent 7bafbc9 commit 282e405
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/add-spaceshared-event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Add SpaceShared event

We added an event that is emmitted when somebody shares a space.

https://github.com/owncloud/ocis/pull/4564
https://github.com/owncloud/ocis/issues/4303
https://github.com/cs3org/reva/pull/3252
12 changes: 12 additions & 0 deletions internal/grpc/interceptors/eventsmiddleware/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,18 @@ 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 {
return events.SpaceShared{
Executant: executant,
Creator: req.Grant.Creator,
GranteeUserID: req.Grant.GetGrantee().GetUserId(),
GranteeGroupID: req.Grant.GetGrantee().GetGroupId(),
ID: req.Ref.ResourceId,
}
}

// SpaceDisabled converts the response to an event
func SpaceDisabled(r *provider.DeleteStorageSpaceResponse, req *provider.DeleteStorageSpaceRequest, executant *user.UserId) events.SpaceDisabled {
return events.SpaceDisabled{
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 @@ -49,6 +49,7 @@ func init() {

// NewUnary returns a new unary interceptor that emits events when needed
// no lint because of the switch statement that should be extendable
//
//nolint:gocritic
func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error) {
publisher, err := publisherFromConfig(m)
Expand Down Expand Up @@ -104,6 +105,14 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error
} else {
ev = LinkAccessFailed(v, req.(*link.GetPublicShareByTokenRequest), executantID)
}
case *provider.AddGrantResponse:
// TODO: update CS3 APIs
// FIXME these should be part of the RemoveGrantRequest object
// https://github.com/owncloud/ocis/issues/4312
r := req.(*provider.AddGrantRequest)
if isSuccess(v) && utils.ExistsInOpaque(r.Opaque, "spacegrant") {
ev = SpaceShared(v, r, executantID)
}
case *provider.CreateContainerResponse:
if isSuccess(v) {
ev = ContainerCreated(v, req.(*provider.CreateContainerRequest), executantID)
Expand Down
17 changes: 17 additions & 0 deletions pkg/events/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package events
import (
"encoding/json"

group "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1"
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
Expand Down Expand Up @@ -99,3 +100,19 @@ func (SpaceDeleted) Unmarshal(v []byte) (interface{}, error) {
err := json.Unmarshal(v, &e)
return e, err
}

// SpaceShared is emitted when a space is shared
type SpaceShared struct {
Executant *user.UserId
GranteeUserID *user.UserId
GranteeGroupID *group.GroupId
Creator *user.UserId
ID *provider.ResourceId
}

// Unmarshal to fulfill umarshaller interface
func (SpaceShared) Unmarshal(v []byte) (interface{}, error) {
e := SpaceShared{}
err := json.Unmarshal(v, &e)
return e, err
}

0 comments on commit 282e405

Please sign in to comment.