@@ -434,7 +434,10 @@ func (u *User) IsPasswordSet() bool {
434
434
435
435
// IsVisibleToUser check if viewer is able to see user profile
436
436
func (u * User ) IsVisibleToUser (viewer * User ) bool {
437
+ return u .isVisibleToUser (x , viewer )
438
+ }
437
439
440
+ func (u * User ) isVisibleToUser (e Engine , viewer * User ) bool {
438
441
if viewer != nil && viewer .IsAdmin {
439
442
return true
440
443
}
@@ -458,53 +461,28 @@ func (u *User) IsVisibleToUser(viewer *User) bool {
458
461
return true
459
462
}
460
463
461
- // Now we need to check if they in some team together
462
-
463
- var orgIds1 []int64
464
- var orgIds2 []int64
465
-
466
- // First user all teams organization
467
- if err := x .Table ("team_user" ).
468
- Cols ("team_user.org_id" ).
469
- Where ("team_user.uid = ?" , u .ID ).
470
- Find (& orgIds1 ); err != nil {
471
- return false
472
- }
473
- if len (orgIds1 ) == 0 {
474
- // No teams 1
475
- return false
476
- }
477
-
478
- // Second user all teams organization
479
- if err := x .Table ("team_user" ).
480
- Cols ("team_user.org_id" ).
481
- Where ("team_user.uid = ?" , viewer .ID ).
482
- Find (& orgIds2 ); err != nil {
483
- return false
484
- }
485
- if len (orgIds2 ) == 0 {
486
- // No teams 2
487
- return false
488
- }
489
-
490
- // Intersect they organizations
491
- var cond builder.Cond = builder .
492
- In ("id" , orgIds1 ).
493
- And (builder .In ("id" , orgIds2 )).
494
- And (builder.Eq {"type" : UserTypeOrganization })
495
- count , err := x .Table ("user" ).
496
- Cols ("id" ).
497
- Where (cond ).
498
- Count (1 )
464
+ // Now we need to check if they in some organization together
465
+ count , err := x .Table ("team_user" ).
466
+ Where (
467
+ builder .And (
468
+ builder.Eq {"uid" : viewer .ID },
469
+ builder .Or (
470
+ builder.Eq {"org_id" : u .ID },
471
+ builder .In ("org_id" ,
472
+ builder .Select ("org_id" ).
473
+ From ("team_user" , "t2" ).
474
+ Where (builder.Eq {"uid" : u .ID }))))).
475
+ Count (new (TeamUser ))
499
476
if err != nil {
500
477
return false
501
478
}
502
- if count == 0 {
503
- // they teams from different orgs?
479
+
480
+ if count < 0 {
481
+ // No common organization
504
482
return false
505
483
}
506
484
507
- // they in some organizations together
485
+ // they are in an organization together
508
486
return true
509
487
}
510
488
return false
0 commit comments