From ea416d7d0edb1a291e8f2019449abce3d05c9b50 Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 4 Sep 2022 17:17:35 +0100 Subject: [PATCH] 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 --- routers/web/admin/users.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/routers/web/admin/users.go b/routers/web/admin/users.go index c37ecfd71ea90..39b212bbc316b 100644 --- a/routers/web/admin/users.go +++ b/routers/web/admin/users.go @@ -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