File tree Expand file tree Collapse file tree 3 files changed +16
-0
lines changed
Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -2529,6 +2529,7 @@ users.allow_import_local = May Import Local Repositories
25292529users.allow_create_organization = May Create Organizations
25302530users.update_profile = Update User Account
25312531users.delete_account = Delete User Account
2532+ users.cannot_delete_self = " You cannot delete yourself"
25322533users.still_own_repo = This user still owns one or more repositories. Delete or transfer these repositories first.
25332534users.still_has_org = This user is a member of an organization. Remove the user from any organizations first.
25342535users.still_own_packages = This user still owns one or more packages. Delete these packages first.
Original file line number Diff line number Diff line change @@ -310,6 +310,12 @@ func DeleteUser(ctx *context.APIContext) {
310310 return
311311 }
312312
313+ // admin should not delete themself
314+ if ctx .ContextUser .ID == ctx .Doer .ID {
315+ ctx .Error (http .StatusUnprocessableEntity , "" , fmt .Errorf ("you cannot delete yourself" ))
316+ return
317+ }
318+
313319 if err := user_service .DeleteUser (ctx .ContextUser ); err != nil {
314320 if models .IsErrUserOwnRepos (err ) ||
315321 models .IsErrUserHasOrgs (err ) ||
Original file line number Diff line number Diff line change @@ -416,6 +416,15 @@ func DeleteUser(ctx *context.Context) {
416416 return
417417 }
418418
419+ // admin should not delete themself
420+ if u .ID == ctx .Doer .ID {
421+ ctx .Flash .Error (ctx .Tr ("admin.users.cannot_delete_self" ))
422+ ctx .JSON (http .StatusOK , map [string ]interface {}{
423+ "redirect" : setting .AppSubURL + "/admin/users/" + url .PathEscape (ctx .Params (":userid" )),
424+ })
425+ return
426+ }
427+
419428 if err = user_service .DeleteUser (u ); err != nil {
420429 switch {
421430 case models .IsErrUserOwnRepos (err ):
You can’t perform that action at this time.
0 commit comments