Redirect if user does not exist on admin pages (#20981) (#21059)

Backport #20981

When on /admin/users/ endpoints if the user is no longer in the DB,
redirect instead of causing a http 500.

Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
This commit is contained in:
zeripath 2022-09-04 17:17:35 +01:00 committed by GitHub
parent 0db6add5c0
commit ea416d7d0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -209,7 +209,11 @@ func NewUserPost(ctx *context.Context) {
func prepareUserInfo(ctx *context.Context) *user_model.User { func prepareUserInfo(ctx *context.Context) *user_model.User {
u, err := user_model.GetUserByID(ctx.ParamsInt64(":userid")) u, err := user_model.GetUserByID(ctx.ParamsInt64(":userid"))
if err != nil { if err != nil {
if user_model.IsErrUserNotExist(err) {
ctx.Redirect(setting.AppSubURL + "/admin/users")
} else {
ctx.ServerError("GetUserByID", err) ctx.ServerError("GetUserByID", err)
}
return nil return nil
} }
ctx.Data["User"] = u ctx.Data["User"] = u