Skip to content

Commit f663773

Browse files
authored
Fix limited user cannot view himself's profile (#21212)
backport #21210, fix #21206 If user and viewer are equal the method should return true. Also the common organization check was wrong as count can never be less then 0. Tests are on main branch.
1 parent a286772 commit f663773

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

models/user/user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ func isUserVisibleToViewerCond(viewer *User) builder.Cond {
12651265

12661266
// IsUserVisibleToViewer check if viewer is able to see user profile
12671267
func IsUserVisibleToViewer(ctx context.Context, u, viewer *User) bool {
1268-
if viewer != nil && viewer.IsAdmin {
1268+
if viewer != nil && (viewer.IsAdmin || viewer.ID == u.ID) {
12691269
return true
12701270
}
12711271

@@ -1304,7 +1304,7 @@ func IsUserVisibleToViewer(ctx context.Context, u, viewer *User) bool {
13041304
return false
13051305
}
13061306

1307-
if count < 0 {
1307+
if count == 0 {
13081308
// No common organization
13091309
return false
13101310
}

0 commit comments

Comments
 (0)