diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-09-20 16:00:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-20 16:00:46 +0800 |
commit | f66377320029e1cd4c4ed0c3e1d550e93ddb54eb (patch) | |
tree | 8ccd6d21a95fc47fa0b36d4b92f0a65b0b9e172e | |
parent | a28677273b8814904d8ea725332ad538dbc90372 (diff) | |
download | gitea-f66377320029e1cd4c4ed0c3e1d550e93ddb54eb.tar.gz gitea-f66377320029e1cd4c4ed0c3e1d550e93ddb54eb.zip |
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.
-rw-r--r-- | models/user/user.go | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/models/user/user.go b/models/user/user.go index 490e7223ce..a96232e386 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -1265,7 +1265,7 @@ func isUserVisibleToViewerCond(viewer *User) builder.Cond { // IsUserVisibleToViewer check if viewer is able to see user profile func IsUserVisibleToViewer(ctx context.Context, u, viewer *User) bool { - if viewer != nil && viewer.IsAdmin { + if viewer != nil && (viewer.IsAdmin || viewer.ID == u.ID) { return true } @@ -1304,7 +1304,7 @@ func IsUserVisibleToViewer(ctx context.Context, u, viewer *User) bool { return false } - if count < 0 { + if count == 0 { // No common organization return false } |