From 88c14326b1a5d9216d5f6905dcbe44e43efdb5b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=99=BA=E8=B6=85?= <1012112796@qq.com> Date: Mon, 6 Apr 2020 22:23:15 +0800 Subject: [PATCH] Users should not be able to prohibit their own login (#10970) * ui: limit managers prohibit themself to login Because I think it's crazy and not reasonale , that if a user can prohibit themself to login. so suggest limit this choice on ui Signed-off-by: a1012112796 <1012112796@qq.com> * skip self Prohibit Login in post event handle * fix comment Co-authored-by: zeripath Co-authored-by: John Olheiser Co-authored-by: Lunny Xiao --- routers/admin/users.go | 8 +++++++- templates/admin/user/edit.tmpl | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/routers/admin/users.go b/routers/admin/users.go index 10ae622c32..a28db2b445 100644 --- a/routers/admin/users.go +++ b/routers/admin/users.go @@ -243,7 +243,13 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) { u.AllowGitHook = form.AllowGitHook u.AllowImportLocal = form.AllowImportLocal u.AllowCreateOrganization = form.AllowCreateOrganization - u.ProhibitLogin = form.ProhibitLogin + + // skip self Prohibit Login + if ctx.User.ID == u.ID { + u.ProhibitLogin = false + } else { + u.ProhibitLogin = form.ProhibitLogin + } if err := models.UpdateUser(u); err != nil { if models.IsErrEmailAlreadyUsed(err) { diff --git a/templates/admin/user/edit.tmpl b/templates/admin/user/edit.tmpl index da75cb5065..feeaacbba2 100644 --- a/templates/admin/user/edit.tmpl +++ b/templates/admin/user/edit.tmpl @@ -74,7 +74,7 @@
- +