summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/user
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2019-10-24 10:18:41 +0900
committerLunny Xiao <xiaolunwen@gmail.com>2019-10-24 09:18:41 +0800
commitee7b153dd96213a36e1073a38c4c4439851ebd85 (patch)
tree00d0510994a7003c99f6ca7590eb6d2501bd8d98 /routers/api/v1/user
parentc84174b7640c17c85c8e3bb86c02cd39b09822e1 (diff)
downloadgitea-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.go2
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