diff options
author | Mayra Cabrera <mcabrera@gitlab.com> | 2018-02-06 00:10:58 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-02-06 00:10:58 +0000 |
commit | 68a419c8792798cfb09730c4ea52ac16e31c3fc9 (patch) | |
tree | 973e75c7941119c19f91107f96a674938daf18dd /app/models/namespace.rb | |
parent | 976413ad0f01c1c1f49227c2f5265bda4dc2e548 (diff) | |
download | gitlab-ce-68a419c8792798cfb09730c4ea52ac16e31c3fc9.tar.gz |
31885 - Ability to transfer a single group to another group
Diffstat (limited to 'app/models/namespace.rb')
-rw-r--r-- | app/models/namespace.rb | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 7b82d076975..06655298950 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -40,7 +40,6 @@ class Namespace < ActiveRecord::Base namespace_path: true validate :nesting_level_allowed - validate :allowed_path_by_redirects delegate :name, to: :owner, allow_nil: true, prefix: true @@ -52,7 +51,7 @@ class Namespace < ActiveRecord::Base # Legacy Storage specific hooks - after_update :move_dir, if: :path_changed? + after_update :move_dir, if: :path_or_parent_changed? before_destroy(prepend: true) { prepare_for_destroy } after_destroy :rm_dir @@ -222,9 +221,12 @@ class Namespace < ActiveRecord::Base end def full_path_was - return path_was unless has_parent? - - "#{parent.full_path}/#{path_was}" + if parent_id_was.nil? + path_was + else + previous_parent = Group.find_by(id: parent_id_was) + previous_parent.full_path + '/' + path_was + end end # Exports belonging to projects with legacy storage are placed in a common @@ -241,6 +243,10 @@ class Namespace < ActiveRecord::Base private + def path_or_parent_changed? + path_changed? || parent_changed? + end + def refresh_access_of_projects_invited_groups Group .joins(project_group_links: :project) @@ -271,16 +277,6 @@ class Namespace < ActiveRecord::Base .update_all(share_with_group_lock: true) end - def allowed_path_by_redirects - return if path.nil? - - errors.add(:path, "#{path} has been taken before. Please use another one") if namespace_previously_created_with_same_path? - end - - def namespace_previously_created_with_same_path? - RedirectRoute.permanent.exists?(path: path) - end - def write_projects_repository_config all_projects.find_each do |project| project.expires_full_path_cache # we need to clear cache to validate renames correctly |