Skip to content

Commit

Permalink
Redirect if user does not exist on admin pages (go-gitea#20981)
Browse files Browse the repository at this point in the history
Backport go-gitea#20981

When on /admin/users/ endpoints if the user is no longer in the DB,
redirect instead of causing a http 500.
  • Loading branch information
KN4CK3R authored and zeripath committed Sep 4, 2022
1 parent 0ecbb71 commit baa1cdb
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 baa1cdb

Please sign in to comment.