Skip to content

Commit

Permalink
Redirect if user does not exist on admin pages (#20981) (#21059)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
zeripath and KN4CK3R committed Sep 4, 2022
1 parent 0db6add commit ea416d7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion routers/web/admin/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ func NewUserPost(ctx *context.Context) {
func prepareUserInfo(ctx *context.Context) *user_model.User {
u, err := user_model.GetUserByID(ctx.ParamsInt64(":userid"))
if err != nil {
ctx.ServerError("GetUserByID", err)
if user_model.IsErrUserNotExist(err) {
ctx.Redirect(setting.AppSubURL + "/admin/users")
} else {
ctx.ServerError("GetUserByID", err)
}
return nil
}
ctx.Data["User"] = u
Expand Down

0 comments on commit ea416d7

Please sign in to comment.