aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2021-11-18 18:42:27 +0100
committerGitHub <noreply@github.com>2021-11-19 01:42:27 +0800
commitf34151bdb22c8160b0a6eafef20725ebae1768da (patch)
tree2abcc5845e4a9cf3769deb27ba5a3ecccd2ad8c9 /routers
parent55be5fe3399d18b7d2477519707aecf5f99f1de5 (diff)
downloadgitea-f34151bdb22c8160b0a6eafef20725ebae1768da.tar.gz
gitea-f34151bdb22c8160b0a6eafef20725ebae1768da.zip
Move user/org deletion to services (#17673)
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/admin/user.go3
-rw-r--r--routers/api/v1/org/org.go3
-rw-r--r--routers/web/admin/users.go3
-rw-r--r--routers/web/org/setting.go8
-rw-r--r--routers/web/user/setting/account.go3
5 files changed, 12 insertions, 8 deletions
diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go
index 1e4a2851c2..95060e7a1c 100644
--- a/routers/api/v1/admin/user.go
+++ b/routers/api/v1/admin/user.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/routers/api/v1/user"
"code.gitea.io/gitea/routers/api/v1/utils"
"code.gitea.io/gitea/services/mailer"
+ user_service "code.gitea.io/gitea/services/user"
)
func parseLoginSource(ctx *context.APIContext, u *models.User, sourceID int64, loginName string) {
@@ -289,7 +290,7 @@ func DeleteUser(ctx *context.APIContext) {
return
}
- if err := models.DeleteUser(u); err != nil {
+ if err := user_service.DeleteUser(u); err != nil {
if models.IsErrUserOwnRepos(err) ||
models.IsErrUserHasOrgs(err) {
ctx.Error(http.StatusUnprocessableEntity, "", err)
diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go
index d3aa92f46d..e82e8552e0 100644
--- a/routers/api/v1/org/org.go
+++ b/routers/api/v1/org/org.go
@@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/user"
"code.gitea.io/gitea/routers/api/v1/utils"
+ "code.gitea.io/gitea/services/org"
)
func listUserOrgs(ctx *context.APIContext, u *models.User) {
@@ -364,7 +365,7 @@ func Delete(ctx *context.APIContext) {
// "204":
// "$ref": "#/responses/empty"
- if err := models.DeleteOrganization(ctx.Org.Organization); err != nil {
+ if err := org.DeleteOrganization(ctx.Org.Organization); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteOrganization", err)
return
}
diff --git a/routers/web/admin/users.go b/routers/web/admin/users.go
index 93e59893e9..b23e4cf39b 100644
--- a/routers/web/admin/users.go
+++ b/routers/web/admin/users.go
@@ -26,6 +26,7 @@ import (
router_user_setting "code.gitea.io/gitea/routers/web/user/setting"
"code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/mailer"
+ "code.gitea.io/gitea/services/user"
)
const (
@@ -377,7 +378,7 @@ func DeleteUser(ctx *context.Context) {
return
}
- if err = models.DeleteUser(u); err != nil {
+ if err = user.DeleteUser(u); err != nil {
switch {
case models.IsErrUserOwnRepos(err):
ctx.Flash.Error(ctx.Tr("admin.users.still_own_repo"))
diff --git a/routers/web/org/setting.go b/routers/web/org/setting.go
index 53c31a1c60..f27cb40838 100644
--- a/routers/web/org/setting.go
+++ b/routers/web/org/setting.go
@@ -20,6 +20,7 @@ import (
"code.gitea.io/gitea/modules/web"
userSetting "code.gitea.io/gitea/routers/web/user/setting"
"code.gitea.io/gitea/services/forms"
+ "code.gitea.io/gitea/services/org"
)
const (
@@ -156,15 +157,14 @@ func SettingsDelete(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("org.settings")
ctx.Data["PageIsSettingsDelete"] = true
- org := ctx.Org.Organization
if ctx.Req.Method == "POST" {
- if org.Name != ctx.FormString("org_name") {
+ if ctx.Org.Organization.Name != ctx.FormString("org_name") {
ctx.Data["Err_OrgName"] = true
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_org_name"), tplSettingsDelete, nil)
return
}
- if err := models.DeleteOrganization(org); err != nil {
+ if err := org.DeleteOrganization(ctx.Org.Organization); err != nil {
if models.IsErrUserOwnRepos(err) {
ctx.Flash.Error(ctx.Tr("form.org_still_own_repo"))
ctx.Redirect(ctx.Org.OrgLink + "/settings/delete")
@@ -172,7 +172,7 @@ func SettingsDelete(ctx *context.Context) {
ctx.ServerError("DeleteOrganization", err)
}
} else {
- log.Trace("Organization deleted: %s", org.Name)
+ log.Trace("Organization deleted: %s", ctx.Org.Organization.Name)
ctx.Redirect(setting.AppSubURL + "/")
}
return
diff --git a/routers/web/user/setting/account.go b/routers/web/user/setting/account.go
index 5ef1c3bdc8..3362d3806d 100644
--- a/routers/web/user/setting/account.go
+++ b/routers/web/user/setting/account.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/services/auth"
"code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/mailer"
+ "code.gitea.io/gitea/services/user"
)
const (
@@ -241,7 +242,7 @@ func DeleteAccount(ctx *context.Context) {
return
}
- if err := models.DeleteUser(ctx.User); err != nil {
+ if err := user.DeleteUser(ctx.User); err != nil {
switch {
case models.IsErrUserOwnRepos(err):
ctx.Flash.Error(ctx.Tr("form.still_own_repo"))