@@ -163,16 +163,17 @@ func (m *mgr) Share(ctx context.Context, md *provider.ResourceInfo, g *collabora
163
163
Nanos : uint32 (now % 1000000000 ),
164
164
}
165
165
166
- // do not allow share to myself if share is for a user
166
+ // do not allow share to myself or the owner if share is for a user
167
167
// TODO(labkode): should not this be caught already at the gw level?
168
168
if g .Grantee .Type == provider .GranteeType_GRANTEE_TYPE_USER &&
169
- g .Grantee .Id .Idp == user .Id .Idp && g .Grantee .Id .OpaqueId == user .Id .OpaqueId {
170
- return nil , errors .New ("json: user and grantee are the same" )
169
+ ((g .Grantee .Id .Idp == user .Id .Idp && g .Grantee .Id .OpaqueId == user .Id .OpaqueId ) ||
170
+ (g .Grantee .Id .Idp == md .Owner .Idp && g .Grantee .Id .OpaqueId == md .Owner .OpaqueId )) {
171
+ return nil , errors .New ("json: owner/creator and grantee are the same" )
171
172
}
172
173
173
174
// check if share already exists.
174
175
key := & collaboration.ShareKey {
175
- Owner : user . Id ,
176
+ Owner : md . Owner ,
176
177
ResourceId : md .Id ,
177
178
Grantee : g .Grantee ,
178
179
}
@@ -190,7 +191,7 @@ func (m *mgr) Share(ctx context.Context, md *provider.ResourceInfo, g *collabora
190
191
ResourceId : md .Id ,
191
192
Permissions : g .Permissions ,
192
193
Grantee : g .Grantee ,
193
- Owner : user . Id ,
194
+ Owner : md . Owner ,
194
195
Creator : user .Id ,
195
196
Ctime : ts ,
196
197
Mtime : ts ,
@@ -223,7 +224,8 @@ func (m *mgr) getByKey(ctx context.Context, key *collaboration.ShareKey) (*colla
223
224
m .Lock ()
224
225
defer m .Unlock ()
225
226
for _ , s := range m .model .Shares {
226
- if key .Owner .Idp == s .Owner .Idp && key .Owner .OpaqueId == s .Owner .OpaqueId &&
227
+ if ((key .Owner .Idp == s .Owner .Idp && key .Owner .OpaqueId == s .Owner .OpaqueId ) ||
228
+ (key .Owner .Idp == s .Creator .Idp && key .Owner .OpaqueId == s .Creator .OpaqueId )) &&
227
229
key .ResourceId .StorageId == s .ResourceId .StorageId && key .ResourceId .OpaqueId == s .ResourceId .OpaqueId &&
228
230
key .Grantee .Type == s .Grantee .Type && key .Grantee .Id .Idp == s .Grantee .Id .Idp && key .Grantee .Id .OpaqueId == s .Grantee .Id .OpaqueId {
229
231
return s , nil
@@ -247,9 +249,9 @@ func (m *mgr) get(ctx context.Context, ref *collaboration.ShareReference) (s *co
247
249
}
248
250
249
251
// check if we are the owner
250
- // TODO(labkode): check for creator also.
251
252
user := user .ContextMustGetUser (ctx )
252
- if user .Id .Idp == s .Owner .Idp && user .Id .OpaqueId == s .Owner .OpaqueId {
253
+ if (user .Id .Idp == s .Owner .Idp && user .Id .OpaqueId == s .Owner .OpaqueId ) ||
254
+ (user .Id .Idp == s .Creator .Idp && user .Id .OpaqueId == s .Creator .OpaqueId ) {
253
255
return s , nil
254
256
}
255
257
@@ -272,7 +274,8 @@ func (m *mgr) Unshare(ctx context.Context, ref *collaboration.ShareReference) er
272
274
user := user .ContextMustGetUser (ctx )
273
275
for i , s := range m .model .Shares {
274
276
if equal (ref , s ) {
275
- if user .Id .Idp == s .Owner .Idp && user .Id .OpaqueId == s .Owner .OpaqueId {
277
+ if (user .Id .Idp == s .Owner .Idp && user .Id .OpaqueId == s .Owner .OpaqueId ) ||
278
+ (user .Id .Idp == s .Creator .Idp && user .Id .OpaqueId == s .Creator .OpaqueId ) {
276
279
m .model .Shares [len (m .model .Shares )- 1 ], m .model .Shares [i ] = m .model .Shares [i ], m .model .Shares [len (m .model .Shares )- 1 ]
277
280
m .model .Shares = m .model .Shares [:len (m .model .Shares )- 1 ]
278
281
if err := m .model .Save (); err != nil {
@@ -293,7 +296,8 @@ func equal(ref *collaboration.ShareReference, s *collaboration.Share) bool {
293
296
return true
294
297
}
295
298
} else if ref .GetKey () != nil {
296
- if reflect .DeepEqual (* ref .GetKey ().Owner , * s .Owner ) && reflect .DeepEqual (* ref .GetKey ().ResourceId , * s .ResourceId ) && reflect .DeepEqual (* ref .GetKey ().Grantee , * s .Grantee ) {
299
+ if (reflect .DeepEqual (* ref .GetKey ().Owner , * s .Owner ) || reflect .DeepEqual (* ref .GetKey ().Owner , * s .Creator )) &&
300
+ reflect .DeepEqual (* ref .GetKey ().ResourceId , * s .ResourceId ) && reflect .DeepEqual (* ref .GetKey ().Grantee , * s .Grantee ) {
297
301
return true
298
302
}
299
303
}
@@ -306,7 +310,8 @@ func (m *mgr) UpdateShare(ctx context.Context, ref *collaboration.ShareReference
306
310
user := user .ContextMustGetUser (ctx )
307
311
for i , s := range m .model .Shares {
308
312
if equal (ref , s ) {
309
- if user .Id .Idp == s .Owner .Idp && user .Id .OpaqueId == s .Owner .OpaqueId {
313
+ if (user .Id .Idp == s .Owner .Idp && user .Id .OpaqueId == s .Owner .OpaqueId ) ||
314
+ (user .Id .Idp == s .Creator .Idp && user .Id .OpaqueId == s .Creator .OpaqueId ) {
310
315
now := time .Now ().UnixNano ()
311
316
m .model .Shares [i ].Permissions = p
312
317
m .model .Shares [i ].Mtime = & typespb.Timestamp {
@@ -331,7 +336,8 @@ func (m *mgr) ListShares(ctx context.Context, filters []*collaboration.ListShare
331
336
user := user .ContextMustGetUser (ctx )
332
337
for _ , s := range m .model .Shares {
333
338
// TODO(labkode): add check for creator.
334
- if user .Id .Idp == s .Owner .Idp && user .Id .OpaqueId == s .Owner .OpaqueId {
339
+ if (user .Id .Idp == s .Owner .Idp && user .Id .OpaqueId == s .Owner .OpaqueId ) ||
340
+ (user .Id .Idp == s .Creator .Idp && user .Id .OpaqueId == s .Creator .OpaqueId ) {
335
341
// no filter we return earlier
336
342
if len (filters ) == 0 {
337
343
ss = append (ss , s )
@@ -358,9 +364,9 @@ func (m *mgr) ListReceivedShares(ctx context.Context) ([]*collaboration.Received
358
364
defer m .Unlock ()
359
365
user := user .ContextMustGetUser (ctx )
360
366
for _ , s := range m .model .Shares {
361
- if user .Id .Idp == s .Owner .Idp && user .Id .OpaqueId == s .Owner .OpaqueId {
367
+ if (user .Id .Idp == s .Owner .Idp && user .Id .OpaqueId == s .Owner .OpaqueId ) ||
368
+ (user .Id .Idp == s .Creator .Idp && user .Id .OpaqueId == s .Creator .OpaqueId ) {
362
369
// omit shares created by me
363
- // TODO(labkode): apply check for s.Creator also.
364
370
continue
365
371
}
366
372
if s .Grantee .Type == provider .GranteeType_GRANTEE_TYPE_USER {
0 commit comments