Skip to content

Commit ea50f60

Browse files
authored
Prevent DeleteUser API abuse (#10125)
* fix & co * word suggestions from @jolheiser
1 parent 29151b9 commit ea50f60

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

routers/api/v1/admin/user.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package admin
77

88
import (
99
"errors"
10+
"fmt"
1011
"net/http"
1112

1213
"code.gitea.io/gitea/models"
@@ -227,6 +228,11 @@ func DeleteUser(ctx *context.APIContext) {
227228
return
228229
}
229230

231+
if u.IsOrganization() {
232+
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("%s is an organization not a user", u.Name))
233+
return
234+
}
235+
230236
if err := models.DeleteUser(u); err != nil {
231237
if models.IsErrUserOwnRepos(err) ||
232238
models.IsErrUserHasOrgs(err) {

routers/org/setting.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func SettingsDeleteAvatar(ctx *context.Context) {
115115
ctx.Redirect(ctx.Org.OrgLink + "/settings")
116116
}
117117

118-
// SettingsDelete response for delete repository
118+
// SettingsDelete response for deleting an organization
119119
func SettingsDelete(ctx *context.Context) {
120120
ctx.Data["Title"] = ctx.Tr("org.settings")
121121
ctx.Data["PageIsSettingsDelete"] = true

0 commit comments

Comments
 (0)