diff options
Diffstat (limited to 'routers/web')
-rw-r--r-- | routers/web/admin/users.go | 11 | ||||
-rw-r--r-- | routers/web/user/setting/account.go | 10 |
2 files changed, 20 insertions, 1 deletions
diff --git a/routers/web/admin/users.go b/routers/web/admin/users.go index f77af3175f..9c95347580 100644 --- a/routers/web/admin/users.go +++ b/routers/web/admin/users.go @@ -429,6 +429,12 @@ func EditUserPost(ctx *context.Context) { } + // Check whether user is the last admin + if !form.Admin && user_model.IsLastAdminUser(ctx, u) { + ctx.RenderWithErr(ctx.Tr("auth.last_admin"), tplUserEdit, &form) + return + } + u.LoginName = form.LoginName u.FullName = form.FullName emailChanged := !strings.EqualFold(u.Email, form.Email) @@ -496,7 +502,10 @@ func DeleteUser(ctx *context.Context) { ctx.Redirect(setting.AppSubURL + "/admin/users/" + url.PathEscape(ctx.Params(":userid"))) case models.IsErrUserOwnPackages(err): ctx.Flash.Error(ctx.Tr("admin.users.still_own_packages")) - ctx.Redirect(setting.AppSubURL + "/admin/users/" + ctx.Params(":userid")) + ctx.Redirect(setting.AppSubURL + "/admin/users/" + url.PathEscape(ctx.Params(":userid"))) + case models.IsErrDeleteLastAdminUser(err): + ctx.Flash.Error(ctx.Tr("auth.last_admin")) + ctx.Redirect(setting.AppSubURL + "/admin/users/" + url.PathEscape(ctx.Params(":userid"))) default: ctx.ServerError("DeleteUser", err) } diff --git a/routers/web/user/setting/account.go b/routers/web/user/setting/account.go index 5c14f3ad4b..266f86fc94 100644 --- a/routers/web/user/setting/account.go +++ b/routers/web/user/setting/account.go @@ -246,6 +246,13 @@ func DeleteAccount(ctx *context.Context) { return } + // admin should not delete themself + if ctx.Doer.IsAdmin { + ctx.Flash.Error(ctx.Tr("form.admin_cannot_delete_self")) + ctx.Redirect(setting.AppSubURL + "/user/settings/account") + return + } + if err := user.DeleteUser(ctx, ctx.Doer, false); err != nil { switch { case models.IsErrUserOwnRepos(err): @@ -257,6 +264,9 @@ func DeleteAccount(ctx *context.Context) { case models.IsErrUserOwnPackages(err): ctx.Flash.Error(ctx.Tr("form.still_own_packages")) ctx.Redirect(setting.AppSubURL + "/user/settings/account") + case models.IsErrDeleteLastAdminUser(err): + ctx.Flash.Error(ctx.Tr("auth.last_admin")) + ctx.Redirect(setting.AppSubURL + "/user/settings/account") default: ctx.ServerError("DeleteUser", err) } |