@@ -55,6 +55,7 @@ type config struct {
55
55
Drivers map [string ]map [string ]interface {} `mapstructure:"drivers"`
56
56
GatewayAddr string `mapstructure:"gateway_addr"`
57
57
AllowedPathsForShares []string `mapstructure:"allowed_paths_for_shares"`
58
+ DisableResharing bool `mapstructure:"disable_resharing"`
58
59
}
59
60
60
61
func (c * config ) init () {
@@ -67,6 +68,7 @@ type service struct {
67
68
sm share.Manager
68
69
gatewaySelector pool.Selectable [gateway.GatewayAPIClient ]
69
70
allowedPathsForShares []* regexp.Regexp
71
+ disableResharing bool
70
72
}
71
73
72
74
func getShareManager (c * config ) (share.Manager , error ) {
@@ -127,15 +129,16 @@ func NewDefault(m map[string]interface{}, ss *grpc.Server) (rgrpc.Service, error
127
129
return nil , err
128
130
}
129
131
130
- return New (gatewaySelector , sm , allowedPathsForShares ), nil
132
+ return New (gatewaySelector , sm , allowedPathsForShares , c . DisableResharing ), nil
131
133
}
132
134
133
135
// New creates a new user share provider svc
134
- func New (gatewaySelector pool.Selectable [gateway.GatewayAPIClient ], sm share.Manager , allowedPathsForShares []* regexp.Regexp ) rgrpc.Service {
136
+ func New (gatewaySelector pool.Selectable [gateway.GatewayAPIClient ], sm share.Manager , allowedPathsForShares []* regexp.Regexp , disableResharing bool ) rgrpc.Service {
135
137
service := & service {
136
138
sm : sm ,
137
139
gatewaySelector : gatewaySelector ,
138
140
allowedPathsForShares : allowedPathsForShares ,
141
+ disableResharing : disableResharing ,
139
142
}
140
143
141
144
return service
@@ -157,6 +160,13 @@ func (s *service) CreateShare(ctx context.Context, req *collaboration.CreateShar
157
160
log := appctx .GetLogger (ctx )
158
161
user := ctxpkg .ContextMustGetUser (ctx )
159
162
163
+ // when resharing is disabled grants must not allow grant permissions
164
+ if s .disableResharing && HasGrantPermissions (req .GetGrant ().GetPermissions ().GetPermissions ()) {
165
+ return & collaboration.CreateShareResponse {
166
+ Status : status .NewInvalidArg (ctx , "resharing not supported" ),
167
+ }, nil
168
+ }
169
+
160
170
gatewayClient , err := s .gatewaySelector .Next ()
161
171
if err != nil {
162
172
return nil , err
@@ -235,6 +245,10 @@ func (s *service) CreateShare(ctx context.Context, req *collaboration.CreateShar
235
245
}, nil
236
246
}
237
247
248
+ func HasGrantPermissions (p * provider.ResourcePermissions ) bool {
249
+ return p .GetAddGrant () || p .GetUpdateGrant () || p .GetRemoveGrant () || p .GetDenyGrant ()
250
+ }
251
+
238
252
func (s * service ) RemoveShare (ctx context.Context , req * collaboration.RemoveShareRequest ) (* collaboration.RemoveShareResponse , error ) {
239
253
log := appctx .GetLogger (ctx )
240
254
user := ctxpkg .ContextMustGetUser (ctx )
@@ -327,6 +341,14 @@ func (s *service) ListShares(ctx context.Context, req *collaboration.ListSharesR
327
341
func (s * service ) UpdateShare (ctx context.Context , req * collaboration.UpdateShareRequest ) (* collaboration.UpdateShareResponse , error ) {
328
342
log := appctx .GetLogger (ctx )
329
343
user := ctxpkg .ContextMustGetUser (ctx )
344
+
345
+ // when resharing is disabled grants must not allow grant permissions
346
+ if s .disableResharing && HasGrantPermissions (req .GetShare ().GetPermissions ().GetPermissions ()) {
347
+ return & collaboration.UpdateShareResponse {
348
+ Status : status .NewInvalidArg (ctx , "resharing not supported" ),
349
+ }, nil
350
+ }
351
+
330
352
gatewayClient , err := s .gatewaySelector .Next ()
331
353
if err != nil {
332
354
return nil , err
0 commit comments