Skip to content

Commit bb282fe

Browse files
committed
Emit event when ocm share is received
Partial Fixes: owncloud/ocis#10718
1 parent 2c9710a commit bb282fe

File tree

5 files changed

+78
-3
lines changed

5 files changed

+78
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Enhancement: Emit event when an ocm share is received
2+
3+
https://github.com/cs3org/reva/pull/4998
4+
https://github.com/owncloud/ocis/issues/10718

internal/grpc/interceptors/eventsmiddleware/conversion.go

+21
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
group "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1"
2525
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
26+
ocmcore "github.com/cs3org/go-cs3apis/cs3/ocm/core/v1beta1"
2627
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
2728
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
2829
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
@@ -191,6 +192,26 @@ func LinkRemoved(r *link.RemovePublicShareResponse, req *link.RemovePublicShareR
191192
}
192193
}
193194

195+
func OCMCoreShareCreated(r *ocmcore.CreateOCMCoreShareResponse, req *ocmcore.CreateOCMCoreShareRequest, executant *user.User) events.OCMCoreShareCreated {
196+
var permissions *provider.ResourcePermissions
197+
for _, p := range req.GetProtocols() {
198+
if p.GetWebdavOptions() != nil {
199+
permissions = p.GetWebdavOptions().GetPermissions().GetPermissions()
200+
break
201+
}
202+
}
203+
return events.OCMCoreShareCreated{
204+
ShareID: r.GetId(),
205+
Executant: executant.GetId(),
206+
Sharer: req.GetSender(),
207+
GranteeUserID: req.GetShareWith(),
208+
ItemID: req.GetResourceId(),
209+
ResourceName: req.GetName(),
210+
CTime: r.GetCreated(),
211+
Permissions: permissions,
212+
}
213+
}
214+
194215
// FileTouched converts the response to an event
195216
func FileTouched(r *provider.TouchFileResponse, req *provider.TouchFileRequest, spaceOwner *user.UserId, executant *user.User) events.FileTouched {
196217
return events.FileTouched{

internal/grpc/interceptors/eventsmiddleware/events.go

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424

2525
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
26+
ocmcore "github.com/cs3org/go-cs3apis/cs3/ocm/core/v1beta1"
2627
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
2728
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
2829
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
@@ -112,6 +113,10 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error
112113
} else {
113114
ev = LinkAccessFailed(v, req.(*link.GetPublicShareByTokenRequest), executant)
114115
}
116+
case *ocmcore.CreateOCMCoreShareResponse:
117+
if isSuccess(v) {
118+
ev = OCMCoreShareCreated(v, req.(*ocmcore.CreateOCMCoreShareRequest), executant)
119+
}
115120
case *provider.AddGrantResponse:
116121
// TODO: update CS3 APIs
117122
// FIXME these should be part of the RemoveGrantRequest object

pkg/events/ocmcore.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2018-2024 CERN
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// In applying this license, CERN does not waive the privileges and immunities
16+
// granted to it by virtue of its status as an Intergovernmental Organization
17+
// or submit itself to any jurisdiction.
18+
19+
package events
20+
21+
import (
22+
"encoding/json"
23+
24+
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
25+
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
26+
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
27+
)
28+
29+
// OCMCoreShareCreated is emitted when an ocm share is received
30+
type OCMCoreShareCreated struct {
31+
ShareID string
32+
Executant *user.UserId
33+
Sharer *user.UserId
34+
GranteeUserID *user.UserId
35+
ItemID string
36+
ResourceName string
37+
Permissions *provider.ResourcePermissions
38+
CTime *types.Timestamp
39+
}
40+
41+
// Unmarshal to fulfill umarshaller interface
42+
func (OCMCoreShareCreated) Unmarshal(v []byte) (interface{}, error) {
43+
e := OCMCoreShareCreated{}
44+
err := json.Unmarshal(v, &e)
45+
return e, err
46+
}

pkg/ocm/storage/received/ocm.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333

3434
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
3535
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
36-
userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
3736
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
3837
ocmpb "github.com/cs3org/go-cs3apis/cs3/sharing/ocm/v1beta1"
3938
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
@@ -539,7 +538,7 @@ func (d *driver) ListStorageSpaces(ctx context.Context, filters []*provider.List
539538
OpaqueId: storagespace.FormatResourceID(root),
540539
},
541540
SpaceType: "mountpoint",
542-
Owner: &userv1beta1.User{
541+
Owner: &userpb.User{
543542
Id: share.Grantee.GetUserId(),
544543
},
545544
Root: root,
@@ -558,7 +557,7 @@ func (d *driver) ListStorageSpaces(ctx context.Context, filters []*provider.List
558557
OpaqueId: storagespace.FormatResourceID(root),
559558
},
560559
SpaceType: "mountpoint",
561-
Owner: &userv1beta1.User{
560+
Owner: &userpb.User{
562561
Id: share.Grantee.GetUserId(),
563562
},
564563
Root: root,

0 commit comments

Comments
 (0)