summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-03 14:57:12 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-06-03 14:57:12 +0200
commit1edff53444ea493ee010a83220cf13ccb381b411 (patch)
tree51f2f728dee26bd6107c520bb092ddfac84409d1
parent61cfd1d2733a717934a723d36f60e7bcd09fad05 (diff)
downloadgitlab-ce-fix-group-remove.tar.gz
Remove projects before group/user. Remove namespace directory asyncfix-group-remove
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/models/namespace.rb11
-rw-r--r--app/services/delete_user_service.rb5
-rw-r--r--app/services/destroy_group_service.rb5
3 files changed, 19 insertions, 2 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index 211dfa76b81..8918e4a682e 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -72,7 +72,7 @@ class Namespace < ActiveRecord::Base
path.gsub!(/[^a-zA-Z0-9_\-\.]/, "")
# Users with the great usernames of "." or ".." would end up with a blank username.
- # Work around that by setting their username to "blank", followed by a counter.
+ # Work around that by setting their username to "blank", followed by a counter.
path = "blank" if path.blank?
counter = 0
@@ -99,7 +99,14 @@ class Namespace < ActiveRecord::Base
end
def rm_dir
- gitlab_shell.rm_namespace(path)
+ # Move namespace directory into trash.
+ # We will remove it later async
+ new_path = "#{path}+#{id}+deleted"
+ gitlab_shell.mv_namespace(path, new_path)
+
+ # Remove namespace directroy async with delay so
+ # GitLab has time to remove all projects first
+ GitlabShellWorker.perform_in(5.minutes, :rm_namespace, new_path)
end
def move_dir
diff --git a/app/services/delete_user_service.rb b/app/services/delete_user_service.rb
index d259b4efca6..ca350eb2a8d 100644
--- a/app/services/delete_user_service.rb
+++ b/app/services/delete_user_service.rb
@@ -4,6 +4,11 @@ class DeleteUserService
user.errors[:base] << 'You must transfer ownership or delete groups before you can remove user'
user
else
+ # TODO: Skip remove repository so Namespace#rm_dir works
+ user.personal_projects.each do |project|
+ ::Projects::DestroyService.new(project, current_user, {}).execute
+ end
+
user.destroy
end
end
diff --git a/app/services/destroy_group_service.rb b/app/services/destroy_group_service.rb
index 9637a1480a8..c1add7b92e8 100644
--- a/app/services/destroy_group_service.rb
+++ b/app/services/destroy_group_service.rb
@@ -6,6 +6,11 @@ class DestroyGroupService
end
def execute
+ # TODO: Skip remove repository so Namespace#rm_dir works
+ @group.projects.each do |project|
+ ::Projects::DestroyService.new(project, current_user, {}).execute
+ end
+
@group.destroy
end
end