mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 12:37:53 +01:00
[BugFix] use default avatar for ghost user (fix 500 error) (#9536)
* remove since it is there for 3years * fix 500 error for ghost avatar * dont insert "-1" in any case to issue.poster_id * fix lint * Test: ghost avatar link * fix test * Revert "remove since it is there for 3years" This reverts commitfd9ad05159
. * Revert "dont insert "-1" in any case to issue.poster_id" This reverts commit05469ab6d8
. Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
parent
ae9d342f54
commit
d59536c222
@ -51,6 +51,7 @@ func TestRedirectsNoLogin(t *testing.T) {
|
|||||||
"/user2/repo1/src/master": "/user2/repo1/src/branch/master",
|
"/user2/repo1/src/master": "/user2/repo1/src/branch/master",
|
||||||
"/user2/repo1/src/master/file.txt": "/user2/repo1/src/branch/master/file.txt",
|
"/user2/repo1/src/master/file.txt": "/user2/repo1/src/branch/master/file.txt",
|
||||||
"/user2/repo1/src/master/directory/file.txt": "/user2/repo1/src/branch/master/directory/file.txt",
|
"/user2/repo1/src/master/directory/file.txt": "/user2/repo1/src/branch/master/directory/file.txt",
|
||||||
|
"/user/avatar/Ghost/-1": "/img/avatar_default.png",
|
||||||
}
|
}
|
||||||
for link, redirectLink := range redirects {
|
for link, redirectLink := range redirects {
|
||||||
req := NewRequest(t, "GET", link)
|
req := NewRequest(t, "GET", link)
|
||||||
|
@ -6,6 +6,7 @@ package user
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
@ -23,7 +24,9 @@ func Avatar(ctx *context.Context) {
|
|||||||
|
|
||||||
log.Debug("Asked avatar for user %v and size %v", userName, size)
|
log.Debug("Asked avatar for user %v and size %v", userName, size)
|
||||||
|
|
||||||
user, err := models.GetUserByName(userName)
|
var user *models.User
|
||||||
|
if strings.ToLower(userName) != "ghost" {
|
||||||
|
user, err = models.GetUserByName(userName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if models.IsErrUserNotExist(err) {
|
if models.IsErrUserNotExist(err) {
|
||||||
ctx.ServerError("Requested avatar for invalid user", err)
|
ctx.ServerError("Requested avatar for invalid user", err)
|
||||||
@ -32,6 +35,9 @@ func Avatar(ctx *context.Context) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
user = models.NewGhostUser()
|
||||||
|
}
|
||||||
|
|
||||||
ctx.Redirect(user.RealSizedAvatarLink(size))
|
ctx.Redirect(user.RealSizedAvatarLink(size))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user