@@ -267,7 +267,6 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use
267
267
perm .units = repo .Units
268
268
269
269
// anonymous user visit private repo.
270
- // TODO: anonymous user visit public unit of private repo???
271
270
if user == nil && repo .IsPrivate {
272
271
perm .AccessMode = perm_model .AccessModeNone
273
272
return perm , nil
@@ -286,7 +285,8 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use
286
285
}
287
286
288
287
// Prevent strangers from checking out public repo of private organization/users
289
- // Allow user if they are collaborator of a repo within a private user or a private organization but not a member of the organization itself
288
+ // Allow user if they are a collaborator of a repo within a private user or a private organization but not a member of the organization itself
289
+ // TODO: rename it to "IsOwnerVisibleToDoer"
290
290
if ! organization .HasOrgOrUserVisible (ctx , repo .Owner , user ) && ! isCollaborator {
291
291
perm .AccessMode = perm_model .AccessModeNone
292
292
return perm , nil
@@ -304,7 +304,7 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use
304
304
return perm , nil
305
305
}
306
306
307
- // plain user
307
+ // plain user TODO: this check should be replaced, only need to check collaborator access mode
308
308
perm .AccessMode , err = accessLevel (ctx , user , repo )
309
309
if err != nil {
310
310
return perm , err
@@ -314,6 +314,19 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use
314
314
return perm , nil
315
315
}
316
316
317
+ // now: the owner is visible to doer, if the repo is public, then the min access mode is read
318
+ minAccessMode := util .Iif (! repo .IsPrivate && ! user .IsRestricted , perm_model .AccessModeRead , perm_model .AccessModeNone )
319
+ perm .AccessMode = max (perm .AccessMode , minAccessMode )
320
+
321
+ // get units mode from teams
322
+ teams , err := organization .GetUserRepoTeams (ctx , repo .OwnerID , user .ID , repo .ID )
323
+ if err != nil {
324
+ return perm , err
325
+ }
326
+ if len (teams ) == 0 {
327
+ return perm , nil
328
+ }
329
+
317
330
perm .unitsMode = make (map [unit.Type ]perm_model.AccessMode )
318
331
319
332
// Collaborators on organization
@@ -323,12 +336,6 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use
323
336
}
324
337
}
325
338
326
- // get units mode from teams
327
- teams , err := organization .GetUserRepoTeams (ctx , repo .OwnerID , user .ID , repo .ID )
328
- if err != nil {
329
- return perm , err
330
- }
331
-
332
339
// if user in an owner team
333
340
for _ , team := range teams {
334
341
if team .HasAdminAccess () {
@@ -339,19 +346,12 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use
339
346
}
340
347
341
348
for _ , u := range repo .Units {
342
- var found bool
343
349
for _ , team := range teams {
350
+ unitAccessMode := minAccessMode
344
351
if teamMode , exist := team .UnitAccessModeEx (ctx , u .Type ); exist {
345
- perm .unitsMode [u .Type ] = max (perm .unitsMode [u .Type ], teamMode )
346
- found = true
347
- }
348
- }
349
-
350
- // for a public repo on an organization, a non-restricted user has read permission on non-team defined units.
351
- if ! found && ! repo .IsPrivate && ! user .IsRestricted {
352
- if _ , ok := perm .unitsMode [u .Type ]; ! ok {
353
- perm .unitsMode [u .Type ] = perm_model .AccessModeRead
352
+ unitAccessMode = max (perm .unitsMode [u .Type ], unitAccessMode , teamMode )
354
353
}
354
+ perm .unitsMode [u .Type ] = unitAccessMode
355
355
}
356
356
}
357
357
0 commit comments