aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2019-10-25 21:09:15 +0900
committerzeripath <art27@cantab.net>2019-10-25 13:09:15 +0100
commit9bde52ffc1bdfc6fcc3d2995776d60d8b42ce316 (patch)
treedea6815f13c6ea43e61aebbc25534789599b9cef /routers/api
parentfa03af8456b49ccca9ee2242d908e8fa6363f6c7 (diff)
downloadgitea-9bde52ffc1bdfc6fcc3d2995776d60d8b42ce316.tar.gz
gitea-9bde52ffc1bdfc6fcc3d2995776d60d8b42ce316.zip
Fix 500 when getting user as unauthenticated user (#8653) (#8663)
Backport #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 there is a panic
Diffstat (limited to 'routers/api')
-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