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
2529
2529
users.allow_create_organization = May Create Organizations
2530
2530
users.update_profile = Update User Account
2531
2531
users.delete_account = Delete User Account
2532
+ users.cannot_delete_self = " You cannot delete yourself"
2532
2533
users.still_own_repo = This user still owns one or more repositories. Delete or transfer these repositories first.
2533
2534
users.still_has_org = This user is a member of an organization. Remove the user from any organizations first.
2534
2535
users.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) {
310
310
return
311
311
}
312
312
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
+
313
319
if err := user_service .DeleteUser (ctx .ContextUser ); err != nil {
314
320
if models .IsErrUserOwnRepos (err ) ||
315
321
models .IsErrUserHasOrgs (err ) ||
Original file line number Diff line number Diff line change @@ -416,6 +416,15 @@ func DeleteUser(ctx *context.Context) {
416
416
return
417
417
}
418
418
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
+
419
428
if err = user_service .DeleteUser (u ); err != nil {
420
429
switch {
421
430
case models .IsErrUserOwnRepos (err ):
You can’t perform that action at this time.
0 commit comments