diff options
author | Monty Taylor <mordred@inaugust.com> | 2019-10-24 17:25:30 +0900 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-10-24 16:25:30 +0800 |
commit | 66ceee08dcbad366761c10e8dee8f3d8624092bd (patch) | |
tree | f4b72ecb109f309e1b1a31e3d143ab7f00e0f886 | |
parent | ffff835b7338a25be96df8747a336f07afc49db2 (diff) | |
download | gitea-66ceee08dcbad366761c10e8dee8f3d8624092bd.tar.gz gitea-66ceee08dcbad366761c10e8dee8f3d8624092bd.zip |
Fix 500 when getting user as unauthenticated user (#8662)
When doing GET /api/v1/users/{user} as an unauthenticated user,
gitea throws a 500 because it's trying to dereference elements
from the context user. It wants to do this to see whether to
show the primary email and will do that if the logged in user
is admin or the user in question. However, if ctx.User is nil,
go gets really unhappy.
-rw-r--r-- | routers/api/v1/user/user.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go index fc3b7a8160..649c38e462 100644 --- a/routers/api/v1/user/user.go +++ b/routers/api/v1/user/user.go @@ -104,7 +104,7 @@ func GetInfo(ctx *context.APIContext) { return } - ctx.JSON(200, convert.ToUser(u, ctx.IsSigned, ctx.User.ID == u.ID || ctx.User.IsAdmin)) + ctx.JSON(200, convert.ToUser(u, ctx.IsSigned, ctx.User != nil && (ctx.User.ID == u.ID || ctx.User.IsAdmin))) } // GetAuthenticatedUser get current user's information |