diff options
author | Monty Taylor <mordred@inaugust.com> | 2019-10-24 10:18:41 +0900 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2019-10-24 09:18:41 +0800 |
commit | ee7b153dd96213a36e1073a38c4c4439851ebd85 (patch) | |
tree | 00d0510994a7003c99f6ca7590eb6d2501bd8d98 /routers/api/v1/user | |
parent | c84174b7640c17c85c8e3bb86c02cd39b09822e1 (diff) | |
download | gitea-ee7b153dd96213a36e1073a38c4c4439851ebd85.tar.gz gitea-ee7b153dd96213a36e1073a38c4c4439851ebd85.zip |
Fix 500 when getting user as unauthenticated user (#8653)
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.
Diffstat (limited to 'routers/api/v1/user')
-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 bb1302077b..0639494c0e 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 |