Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent DeleteUser API abuse #10125

Merged
merged 2 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions routers/api/v1/admin/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package admin

import (
"errors"
"fmt"
"net/http"

"code.gitea.io/gitea/models"
Expand Down Expand Up @@ -227,6 +228,11 @@ func DeleteUser(ctx *context.APIContext) {
return
}

if u.IsOrganization() {
ctx.Error(http.StatusUnprocessableEntity, "", fmt.Errorf("%s is an organisation not an user", u.Name))
6543 marked this conversation as resolved.
Show resolved Hide resolved
return
}

if err := models.DeleteUser(u); err != nil {
if models.IsErrUserOwnRepos(err) ||
models.IsErrUserHasOrgs(err) {
Expand Down
2 changes: 1 addition & 1 deletion routers/org/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func SettingsDeleteAvatar(ctx *context.Context) {
ctx.Redirect(ctx.Org.OrgLink + "/settings")
}

// SettingsDelete response for delete repository
// SettingsDelete response for delete organisation
6543 marked this conversation as resolved.
Show resolved Hide resolved
func SettingsDelete(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("org.settings")
ctx.Data["PageIsSettingsDelete"] = true
Expand Down