From 0f3c3a1c57beb8269f97e408f19e76ba77aac99c Mon Sep 17 00:00:00 2001 From: Ahmad Sherif Date: Mon, 21 Nov 2016 15:33:58 +0200 Subject: Update user's authorized projects if project is allowed to share with group --- app/models/namespace.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/models/namespace.rb') diff --git a/app/models/namespace.rb b/app/models/namespace.rb index b67049f0f55..99da26a89fb 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -27,6 +27,7 @@ class Namespace < ActiveRecord::Base delegate :name, to: :owner, allow_nil: true, prefix: true after_update :move_dir, if: :path_changed? + after_commit :refresh_access_of_projects_invited_groups, on: :update, if: -> { previous_changes.key?('share_with_group_lock') } # Save the storage paths before the projects are destroyed to use them on after destroy before_destroy(prepend: true) { @old_repository_storage_paths = repository_storage_paths } @@ -175,4 +176,11 @@ class Namespace < ActiveRecord::Base end end end + + def refresh_access_of_projects_invited_groups + Group. + joins(project_group_links: :project). + where(projects: { namespace_id: id }). + find_each(&:refresh_members_authorized_projects) + end end -- cgit v1.2.1 From 4123a0ff75369e28a4722b087ef4243f5e521d52 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 24 Nov 2016 13:36:15 +0800 Subject: Log mv_namespace parameters --- app/models/namespace.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/models/namespace.rb') diff --git a/app/models/namespace.rb b/app/models/namespace.rb index b67049f0f55..dfd1633707e 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -103,6 +103,8 @@ class Namespace < ActiveRecord::Base gitlab_shell.add_namespace(repository_storage_path, path_was) unless gitlab_shell.mv_namespace(repository_storage_path, path_was, path) + Rails.logger.error "Exception moving path #{repository_storage_path} from #{path_was} to #{path}" + # if we cannot move namespace directory we should rollback # db changes in order to prevent out of sync between db and fs raise Exception.new('namespace directory cannot be moved') -- cgit v1.2.1 From 4e249d5baea99a52915025fc2827d01ab2d77c18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Fri, 2 Dec 2016 13:54:57 +0100 Subject: Use :maximum instead of :within for length validators with a 0..N range MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- app/models/namespace.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'app/models/namespace.rb') diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 891dffac648..7a545f752b6 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -12,17 +12,17 @@ class Namespace < ActiveRecord::Base validates :owner, presence: true, unless: ->(n) { n.type == "Group" } validates :name, - length: { within: 0..255 }, - namespace_name: true, presence: true, - uniqueness: true + uniqueness: true, + length: { maximum: 255 }, + namespace_name: true - validates :description, length: { within: 0..255 } + validates :description, length: { maximum: 255 } validates :path, - length: { within: 1..255 }, - namespace: true, presence: true, - uniqueness: { case_sensitive: false } + uniqueness: { case_sensitive: false }, + length: { maximum: 255 }, + namespace: true delegate :name, to: :owner, allow_nil: true, prefix: true -- cgit v1.2.1 From 83232be0e14cc8b35bf74532203a6e4371c15e70 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 31 Oct 2016 13:00:53 +0200 Subject: Add nested groups support on data level * add parent_id field to namespaces table to store relation with nested groups * create routes table to keep information about full path of every group and project * project/group lookup by full path from routes table Signed-off-by: Dmitriy Zaporozhets --- app/models/namespace.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'app/models/namespace.rb') diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 891dffac648..ff161e4c53f 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -4,12 +4,16 @@ class Namespace < ActiveRecord::Base include CacheMarkdownField include Sortable include Gitlab::ShellAdapter + include Routable cache_markdown_field :description, pipeline: :description has_many :projects, dependent: :destroy belongs_to :owner, class_name: "User" + belongs_to :parent, class_name: "Namespace" + has_many :children, class_name: "Namespace", foreign_key: :parent_id + validates :owner, presence: true, unless: ->(n) { n.type == "Group" } validates :name, length: { within: 0..255 }, @@ -86,7 +90,7 @@ class Namespace < ActiveRecord::Base end def to_param - path + full_path end def human_name @@ -150,6 +154,14 @@ class Namespace < ActiveRecord::Base Gitlab.config.lfs.enabled end + def full_path + if parent + parent.full_path + '/' + path + else + path + end + end + private def repository_storage_paths @@ -185,4 +197,8 @@ class Namespace < ActiveRecord::Base where(projects: { namespace_id: id }). find_each(&:refresh_members_authorized_projects) end + + def full_path_changed? + path_changed? || parent_id_changed? + end end -- cgit v1.2.1 From 161d7c02d4ff49d6d91b982faee61b5de00d2631 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 7 Dec 2016 19:15:26 +0200 Subject: Modify namespace name and path validation Currently namespace name and path have uniq validaiton which does not allow us to use same group name/path inside different groups. This commit changes validation in next way: * Allow same namespace name with different parent_id * Allow same namespace path. Uniq validation should be handled by routes table Signed-off-by: Dmitriy Zaporozhets --- app/models/namespace.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'app/models/namespace.rb') diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 37374044551..f0479d94986 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -17,14 +17,13 @@ class Namespace < ActiveRecord::Base validates :owner, presence: true, unless: ->(n) { n.type == "Group" } validates :name, presence: true, - uniqueness: true, + uniqueness: { scope: :parent_id }, length: { maximum: 255 }, namespace_name: true validates :description, length: { maximum: 255 } validates :path, presence: true, - uniqueness: { case_sensitive: false }, length: { maximum: 255 }, namespace: true -- cgit v1.2.1 From 8128ce3054749401acfee2c91d38e0e731253624 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 8 Dec 2016 18:30:11 +0200 Subject: Show full path for nested groups at dashboard groups list Signed-off-by: Dmitriy Zaporozhets --- app/models/namespace.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/models/namespace.rb') diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 37374044551..464be910f5a 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -162,6 +162,14 @@ class Namespace < ActiveRecord::Base end end + def full_name + if parent + parent.full_name + ' / ' + name + else + name + end + end + private def repository_storage_paths -- cgit v1.2.1 From d806230f9f95a2d08253f6c534ba69d1b9a498ea Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 13 Dec 2016 16:59:49 +0200 Subject: Add parents method to Namespace Signed-off-by: Dmitriy Zaporozhets --- app/models/namespace.rb | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'app/models/namespace.rb') diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 464be910f5a..b3cefc01b99 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -163,11 +163,26 @@ class Namespace < ActiveRecord::Base end def full_name - if parent - parent.full_name + ' / ' + name - else - name - end + @full_name ||= + if parent + parent.full_name + ' / ' + name + else + name + end + end + + def parents + @parents ||= + begin + parents = [] + + if parent + parents << parent + parents += parent.parents + end + + parents + end end private -- cgit v1.2.1 From 82f9957d466810314b8f3af672bcdd706905007a Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 13 Dec 2016 20:49:25 +0200 Subject: Refactor Namespace#parents method Signed-off-by: Dmitriy Zaporozhets --- app/models/namespace.rb | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'app/models/namespace.rb') diff --git a/app/models/namespace.rb b/app/models/namespace.rb index b3cefc01b99..3830379be3e 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -172,17 +172,7 @@ class Namespace < ActiveRecord::Base end def parents - @parents ||= - begin - parents = [] - - if parent - parents << parent - parents += parent.parents - end - - parents - end + @parents ||= parent ? parent.parents + [parent] : [] end private -- cgit v1.2.1