From 51c4b20c48f29fe34fd1306f7a115f645eb9fb71 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 5 Jan 2017 14:43:50 +0200 Subject: Refactor Namespace code related to nested groups Signed-off-by: Dmitriy Zaporozhets --- app/models/namespace.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'app/models/namespace.rb') diff --git a/app/models/namespace.rb b/app/models/namespace.rb index d41833de66f..d3a4ddbb3bf 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -183,8 +183,26 @@ class Namespace < ActiveRecord::Base end end - def parents - @parents ||= parent ? parent.parents + [parent] : [] + # Scopes the model on ancestors of the record + def ancestors + if parent_id + path = route.path + paths = [] + + until path.blank? + path = path.rpartition('/').first + paths << path + end + + self.class.joins(:route).where('routes.path IN (?)', paths).order_id_asc + else + self.class.none + end + end + + # Scopes the model on direct and indirect children of the record + def descendants + self.class.joins(:route).where('routes.path LIKE ?', "#{route.path}/%").order_id_asc end private -- cgit v1.2.1 From b7f4553e3e4681d5a4a53af35650bcbb1c83b390 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 20 Jan 2017 12:25:53 +0100 Subject: Backport changes introduced by https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1083 --- app/models/namespace.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/models/namespace.rb') diff --git a/app/models/namespace.rb b/app/models/namespace.rb index d41833de66f..778b9c127ad 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -4,6 +4,7 @@ class Namespace < ActiveRecord::Base include CacheMarkdownField include Sortable include Gitlab::ShellAdapter + include Gitlab::CurrentSettings include Routable cache_markdown_field :description, pipeline: :description @@ -174,6 +175,10 @@ class Namespace < ActiveRecord::Base end end + def shared_runners_enabled? + projects.with_shared_runners.any? + end + def full_name @full_name ||= if parent -- cgit v1.2.1 From d7755ede246988e3186a46b2c9fbd1b70660b529 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 4 Jan 2017 19:13:29 +0000 Subject: Merge branch 'fix/rename-group-export-vuln' into 'security' Fix export files not removed when a user takes over a namespace See merge request !2051 --- app/models/namespace.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'app/models/namespace.rb') diff --git a/app/models/namespace.rb b/app/models/namespace.rb index d41833de66f..dd33975731f 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -130,6 +130,8 @@ class Namespace < ActiveRecord::Base Gitlab::UploadsTransfer.new.rename_namespace(path_was, path) + remove_exports! + # If repositories moved successfully we need to # send update instructions to users. # However we cannot allow rollback since we moved namespace dir @@ -214,6 +216,8 @@ class Namespace < ActiveRecord::Base GitlabShellWorker.perform_in(5.minutes, :rm_namespace, repository_storage_path, new_path) end end + + remove_exports! end def refresh_access_of_projects_invited_groups @@ -226,4 +230,20 @@ class Namespace < ActiveRecord::Base def full_path_changed? path_changed? || parent_id_changed? end + + def remove_exports! + Gitlab::Popen.popen(%W(find #{export_path} -not -path #{export_path} -delete)) + end + + def export_path + File.join(Gitlab::ImportExport.storage_path, full_path_was) + end + + def full_path_was + if parent + parent.full_path + '/' + path_was + else + path_was + end + end end -- cgit v1.2.1 From 52c5f9c97f20529b608f5b47a7c361383ccadb54 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 5 Jan 2017 19:20:12 +0200 Subject: Add User#nested_groups and User#nested_projects methods Signed-off-by: Dmitriy Zaporozhets --- app/models/namespace.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models/namespace.rb') diff --git a/app/models/namespace.rb b/app/models/namespace.rb index d3a4ddbb3bf..eb970dddd91 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -194,7 +194,7 @@ class Namespace < ActiveRecord::Base paths << path end - self.class.joins(:route).where('routes.path IN (?)', paths).order_id_asc + self.class.joins(:route).where('routes.path IN (?)', paths).reorder('routes.path ASC') else self.class.none end @@ -202,7 +202,7 @@ class Namespace < ActiveRecord::Base # Scopes the model on direct and indirect children of the record def descendants - self.class.joins(:route).where('routes.path LIKE ?', "#{route.path}/%").order_id_asc + self.class.joins(:route).where('routes.path LIKE ?', "#{route.path}/%").reorder('routes.path ASC') end private -- cgit v1.2.1