@@ -27,14 +27,16 @@ import (
27
27
"strings"
28
28
"time"
29
29
30
- user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
30
+ userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
31
+ rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
31
32
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
32
33
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
33
34
typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
34
35
"github.com/cs3org/reva"
35
36
"github.com/cs3org/reva/pkg/appctx"
36
37
conversions "github.com/cs3org/reva/pkg/cbox/utils"
37
38
"github.com/cs3org/reva/pkg/errtypes"
39
+ "github.com/cs3org/reva/pkg/rgrpc/status"
38
40
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
39
41
"github.com/cs3org/reva/pkg/share"
40
42
"github.com/cs3org/reva/pkg/sharedconf"
@@ -120,7 +122,7 @@ func (m *mgr) Share(ctx context.Context, md *provider.ResourceInfo, g *collabora
120
122
ResourceId : md .Id ,
121
123
Grantee : g .Grantee ,
122
124
}
123
- _ , err := m .getByKey (ctx , key , true )
125
+ _ , err := m .getByKey (ctx , key , g . Grantee . GetUserId (). Type , true )
124
126
125
127
// share already exists
126
128
if err == nil {
@@ -175,7 +177,7 @@ func (m *mgr) Share(ctx context.Context, md *provider.ResourceInfo, g *collabora
175
177
}, nil
176
178
}
177
179
178
- func (m * mgr ) getByID (ctx context.Context , id * collaboration.ShareId , checkOwner bool ) (* collaboration.Share , error ) {
180
+ func (m * mgr ) getByID (ctx context.Context , id * collaboration.ShareId , gtype userpb. UserType , checkOwner bool ) (* collaboration.Share , error ) {
179
181
uid := conversions .FormatUserID (appctx .ContextMustGetUser (ctx ).Id )
180
182
s := conversions.DBShare {ID : id .OpaqueId }
181
183
query := "select coalesce(uid_owner, '') as uid_owner, coalesce(uid_initiator, '') as uid_initiator, lower(coalesce(share_with, '')) as share_with, coalesce(fileid_prefix, '') as fileid_prefix, coalesce(item_source, '') as item_source, coalesce(item_type, '') as item_type, stime, permissions, share_type FROM oc_share WHERE (orphan = 0 or orphan IS NULL) AND id=?"
@@ -190,10 +192,10 @@ func (m *mgr) getByID(ctx context.Context, id *collaboration.ShareId, checkOwner
190
192
}
191
193
return nil , err
192
194
}
193
- return conversions .ConvertToCS3Share (s ), nil
195
+ return conversions .ConvertToCS3Share (s , gtype ), nil
194
196
}
195
197
196
- func (m * mgr ) getByKey (ctx context.Context , key * collaboration.ShareKey , checkOwner bool ) (* collaboration.Share , error ) {
198
+ func (m * mgr ) getByKey (ctx context.Context , key * collaboration.ShareKey , gtype userpb. UserType , checkOwner bool ) (* collaboration.Share , error ) {
197
199
owner := conversions .FormatUserID (key .Owner )
198
200
uid := conversions .FormatUserID (appctx .ContextMustGetUser (ctx ).Id )
199
201
@@ -211,35 +213,36 @@ func (m *mgr) getByKey(ctx context.Context, key *collaboration.ShareKey, checkOw
211
213
}
212
214
return nil , err
213
215
}
214
- return conversions .ConvertToCS3Share (s ), nil
216
+ return conversions .ConvertToCS3Share (s , gtype ), nil
215
217
}
216
218
217
219
func (m * mgr ) GetShare (ctx context.Context , ref * collaboration.ShareReference ) (* collaboration.Share , error ) {
218
-
219
220
var s * collaboration.Share
220
221
var err error
221
222
switch {
222
223
case ref .GetId () != nil :
223
- s , err = m .getByID (ctx , ref .GetId (), false )
224
+ s , err = m .getByID (ctx , ref .GetId (), userpb . UserType_USER_TYPE_INVALID , false )
224
225
if err != nil {
225
226
return nil , err
226
227
}
227
228
case ref .GetKey () != nil :
228
- s , err = m .getByKey (ctx , ref .GetKey (), false )
229
+ s , err = m .getByKey (ctx , ref .GetKey (), userpb . UserType_USER_TYPE_INVALID , false )
229
230
if err != nil {
230
231
return nil , err
231
232
}
232
233
default :
233
234
err = errtypes .NotFound (ref .String ())
234
235
}
235
236
237
+ // resolve grantee's user type
238
+ s .Grantee .GetUserId ().Type , _ = m .getUserType (ctx , s .Grantee .GetUserId ().OpaqueId )
239
+
236
240
path , err := m .getPath (ctx , s .ResourceId )
237
241
if err != nil {
238
242
return nil , err
239
243
}
240
244
241
245
user := appctx .ContextMustGetUser (ctx )
242
-
243
246
if m .isProjectAdmin (user , path ) {
244
247
return s , nil
245
248
}
@@ -359,7 +362,8 @@ func (m *mgr) addPathIntoCtx(ctx context.Context, ref *collaboration.ShareRefere
359
362
var err error
360
363
switch {
361
364
case ref .GetId () != nil :
362
- share , err := m .getByID (ctx , ref .GetId (), false )
365
+ // here we don't manipulate the grantee's user type, so just assume PRIMARY
366
+ share , err := m .getByID (ctx , ref .GetId (), userpb .UserType_USER_TYPE_PRIMARY , false )
363
367
if err != nil {
364
368
return nil , err
365
369
}
@@ -379,15 +383,15 @@ func (m *mgr) addPathIntoCtx(ctx context.Context, ref *collaboration.ShareRefere
379
383
return appctx .ContextSetResourcePath (ctx , path ), nil
380
384
}
381
385
382
- func (m * mgr ) isProjectAdminFromCtx (ctx context.Context , u * user .User ) bool {
386
+ func (m * mgr ) isProjectAdminFromCtx (ctx context.Context , u * userpb .User ) bool {
383
387
path , ok := appctx .ContextGetResourcePath (ctx )
384
388
if ! ok {
385
389
return false
386
390
}
387
391
return m .isProjectAdmin (u , path )
388
392
}
389
393
390
- func (m * mgr ) isProjectAdmin (u * user .User , path string ) bool {
394
+ func (m * mgr ) isProjectAdmin (u * userpb .User , path string ) bool {
391
395
if strings .HasPrefix (path , projectPathPrefix ) {
392
396
// The path will look like /eos/project/c/cernbox, we need to extract the project name
393
397
parts := strings .SplitN (path , "/" , 6 )
@@ -451,7 +455,11 @@ func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.Filter) (
451
455
if err := rows .Scan (& s .UIDOwner , & s .UIDInitiator , & s .ShareWith , & s .Prefix , & s .ItemSource , & s .ItemType , & s .ID , & s .STime , & s .Permissions , & s .ShareType ); err != nil {
452
456
continue
453
457
}
454
- shares = append (shares , conversions .ConvertToCS3Share (s ))
458
+ gtype , _ := m .getUserType (ctx , s .ShareWith )
459
+ // if err != nil {
460
+ // failed to resolve grantee's user type, TODO Log
461
+ // }
462
+ shares = append (shares , conversions .ConvertToCS3Share (s , gtype ))
455
463
}
456
464
if err = rows .Err (); err != nil {
457
465
return nil , err
@@ -504,7 +512,11 @@ func (m *mgr) ListReceivedShares(ctx context.Context, filters []*collaboration.F
504
512
if err := rows .Scan (& s .UIDOwner , & s .UIDInitiator , & s .ShareWith , & s .Prefix , & s .ItemSource , & s .ItemType , & s .ID , & s .STime , & s .Permissions , & s .ShareType , & s .State ); err != nil {
505
513
continue
506
514
}
507
- shares = append (shares , conversions .ConvertToCS3ReceivedShare (s ))
515
+ gtype , _ := m .getUserType (ctx , s .ShareWith )
516
+ // if err != nil {
517
+ // failed to resolve grantee's user type, TODO Log
518
+ // }
519
+ shares = append (shares , conversions .ConvertToCS3ReceivedShare (s , gtype ))
508
520
}
509
521
if err = rows .Err (); err != nil {
510
522
return nil , err
@@ -513,7 +525,7 @@ func (m *mgr) ListReceivedShares(ctx context.Context, filters []*collaboration.F
513
525
return shares , nil
514
526
}
515
527
516
- func (m * mgr ) getReceivedByID (ctx context.Context , id * collaboration.ShareId ) (* collaboration.ReceivedShare , error ) {
528
+ func (m * mgr ) getReceivedByID (ctx context.Context , id * collaboration.ShareId , gtype userpb. UserType ) (* collaboration.ReceivedShare , error ) {
517
529
user := appctx .ContextMustGetUser (ctx )
518
530
uid := conversions .FormatUserID (user .Id )
519
531
@@ -539,10 +551,10 @@ func (m *mgr) getReceivedByID(ctx context.Context, id *collaboration.ShareId) (*
539
551
}
540
552
return nil , err
541
553
}
542
- return conversions .ConvertToCS3ReceivedShare (s ), nil
554
+ return conversions .ConvertToCS3ReceivedShare (s , gtype ), nil
543
555
}
544
556
545
- func (m * mgr ) getReceivedByKey (ctx context.Context , key * collaboration.ShareKey ) (* collaboration.ReceivedShare , error ) {
557
+ func (m * mgr ) getReceivedByKey (ctx context.Context , key * collaboration.ShareKey , gtype userpb. UserType ) (* collaboration.ReceivedShare , error ) {
546
558
user := appctx .ContextMustGetUser (ctx )
547
559
uid := conversions .FormatUserID (user .Id )
548
560
@@ -570,17 +582,17 @@ func (m *mgr) getReceivedByKey(ctx context.Context, key *collaboration.ShareKey)
570
582
}
571
583
return nil , err
572
584
}
573
- return conversions .ConvertToCS3ReceivedShare (s ), nil
585
+ return conversions .ConvertToCS3ReceivedShare (s , gtype ), nil
574
586
}
575
587
576
588
func (m * mgr ) GetReceivedShare (ctx context.Context , ref * collaboration.ShareReference ) (* collaboration.ReceivedShare , error ) {
577
589
var s * collaboration.ReceivedShare
578
590
var err error
579
591
switch {
580
592
case ref .GetId () != nil :
581
- s , err = m .getReceivedByID (ctx , ref .GetId ())
593
+ s , err = m .getReceivedByID (ctx , ref .GetId (), userpb . UserType_USER_TYPE_INVALID )
582
594
case ref .GetKey () != nil :
583
- s , err = m .getReceivedByKey (ctx , ref .GetKey ())
595
+ s , err = m .getReceivedByKey (ctx , ref .GetKey (), userpb . UserType_USER_TYPE_INVALID )
584
596
default :
585
597
err = errtypes .NotFound (ref .String ())
586
598
}
@@ -589,6 +601,9 @@ func (m *mgr) GetReceivedShare(ctx context.Context, ref *collaboration.ShareRefe
589
601
return nil , err
590
602
}
591
603
604
+ // resolve grantee's user type
605
+ s .Share .Grantee .GetUserId ().Type , _ = m .getUserType (ctx , s .Share .Grantee .GetUserId ().OpaqueId )
606
+
592
607
return s , nil
593
608
}
594
609
@@ -719,3 +734,22 @@ func translateFilters(filters map[collaboration.Filter_Type][]*collaboration.Fil
719
734
}
720
735
return filterQuery , params , nil
721
736
}
737
+
738
+ func (m * mgr ) getUserType (ctx context.Context , username string ) (userpb.UserType , error ) {
739
+ client , err := pool .GetGatewayServiceClient (pool .Endpoint (m .c .GatewaySvc ))
740
+ if err != nil {
741
+ return userpb .UserType_USER_TYPE_PRIMARY , err
742
+ }
743
+ userRes , err := client .GetUserByClaim (ctx , & userpb.GetUserByClaimRequest {
744
+ Claim : "username" ,
745
+ Value : username ,
746
+ })
747
+ if err != nil {
748
+ return userpb .UserType_USER_TYPE_PRIMARY , errors .Wrapf (err , "error getting user by username '%v'" , username )
749
+ }
750
+ if userRes .Status .Code != rpc .Code_CODE_OK {
751
+ return userpb .UserType_USER_TYPE_PRIMARY , status .NewErrorFromCode (userRes .Status .Code , "oidc" )
752
+ }
753
+
754
+ return userRes .GetUser ().Id .Type , nil
755
+ }
0 commit comments