]> source.dussan.org Git - gitea.git/commitdiff
Fix 500 when getting user as unauthenticated user (#8662)
authorMonty Taylor <mordred@inaugust.com>
Thu, 24 Oct 2019 08:25:30 +0000 (17:25 +0900)
committerLunny Xiao <xiaolunwen@gmail.com>
Thu, 24 Oct 2019 08:25:30 +0000 (16:25 +0800)
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.

routers/api/v1/user/user.go

index fc3b7a816036cb3778523f7fab0470ace6c076ac..649c38e4623fc52efa660b79749a1a512126ef40 100644 (file)
@@ -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