aboutsummaryrefslogtreecommitdiffstats
path: root/services/org
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-05-21 23:13:47 +0800
committerGitHub <noreply@github.com>2023-05-21 23:13:47 +0800
commitc59a057297c782f44a81a3e630b5094a58099edb (patch)
tree58c3020b0da9755fa769619bb3ad80e656f25cd9 /services/org
parent64f6a5d113da0d5d187752c9398d6e8d22d24b79 (diff)
downloadgitea-c59a057297c782f44a81a3e630b5094a58099edb.tar.gz
gitea-c59a057297c782f44a81a3e630b5094a58099edb.zip
Refactor rename user and rename organization (#24052)
This PR is a refactor at the beginning. And now it did 4 things. - [x] Move renaming organizaiton and user logics into services layer and merged as one function - [x] Support rename a user capitalization only. For example, rename the user from `Lunny` to `lunny`. We just need to change one table `user` and others should not be touched. - [x] Before this PR, some renaming were missed like `agit` - [x] Fix bug the API reutrned from `http.StatusNoContent` to `http.StatusOK`
Diffstat (limited to 'services/org')
-rw-r--r--services/org/org.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/services/org/org.go b/services/org/org.go
index e45fb305de..a62e5b6fc8 100644
--- a/services/org/org.go
+++ b/services/org/org.go
@@ -4,20 +4,22 @@
package org
import (
+ "context"
"fmt"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
- "code.gitea.io/gitea/models/organization"
+ org_model "code.gitea.io/gitea/models/organization"
packages_model "code.gitea.io/gitea/models/packages"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/util"
+ user_service "code.gitea.io/gitea/services/user"
)
// DeleteOrganization completely and permanently deletes everything of organization.
-func DeleteOrganization(org *organization.Organization) error {
+func DeleteOrganization(org *org_model.Organization) error {
ctx, commiter, err := db.TxContext(db.DefaultContext)
if err != nil {
return err
@@ -39,7 +41,7 @@ func DeleteOrganization(org *organization.Organization) error {
return models.ErrUserOwnPackages{UID: org.ID}
}
- if err := organization.DeleteOrganization(ctx, org); err != nil {
+ if err := org_model.DeleteOrganization(ctx, org); err != nil {
return fmt.Errorf("DeleteOrganization: %w", err)
}
@@ -53,15 +55,20 @@ func DeleteOrganization(org *organization.Organization) error {
path := user_model.UserPath(org.Name)
if err := util.RemoveAll(path); err != nil {
- return fmt.Errorf("Failed to RemoveAll %s: %w", path, err)
+ return fmt.Errorf("failed to RemoveAll %s: %w", path, err)
}
if len(org.Avatar) > 0 {
avatarPath := org.CustomAvatarRelativePath()
if err := storage.Avatars.Delete(avatarPath); err != nil {
- return fmt.Errorf("Failed to remove %s: %w", avatarPath, err)
+ return fmt.Errorf("failed to remove %s: %w", avatarPath, err)
}
}
return nil
}
+
+// RenameOrganization renames an organization.
+func RenameOrganization(ctx context.Context, org *org_model.Organization, newName string) error {
+ return user_service.RenameUser(ctx, org.AsUser(), newName)
+}