From 06f8772924502e5cdf357ec1af269dc119be02de Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 7 Dec 2016 19:15:26 +0200 Subject: [PATCH 01/12] Allow creating namespaces with same path Signed-off-by: Dmitriy Zaporozhets --- app/models/namespace.rb | 5 ++- ...9_remove_uniq_path_index_from_namespace.rb | 36 +++++++++++++++++++ ...61206153751_add_path_index_to_namespace.rb | 20 +++++++++++ db/schema.rb | 4 +-- spec/models/namespace_spec.rb | 6 +--- 5 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20161206153749_remove_uniq_path_index_from_namespace.rb create mode 100644 db/migrate/20161206153751_add_path_index_to_namespace.rb diff --git a/app/models/namespace.rb b/app/models/namespace.rb index ff161e4c53f7..7ded50e6ace5 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -19,14 +19,13 @@ class Namespace < ActiveRecord::Base length: { within: 0..255 }, namespace_name: true, presence: true, - uniqueness: true + uniqueness: { scope: :parent_id } validates :description, length: { within: 0..255 } validates :path, length: { within: 1..255 }, namespace: true, - presence: true, - uniqueness: { case_sensitive: false } + presence: true delegate :name, to: :owner, allow_nil: true, prefix: true diff --git a/db/migrate/20161206153749_remove_uniq_path_index_from_namespace.rb b/db/migrate/20161206153749_remove_uniq_path_index_from_namespace.rb new file mode 100644 index 000000000000..2977917f2d10 --- /dev/null +++ b/db/migrate/20161206153749_remove_uniq_path_index_from_namespace.rb @@ -0,0 +1,36 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class RemoveUniqPathIndexFromNamespace < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + DOWNTIME = false + + def up + constraint_name = 'namespaces_path_key' + + transaction do + if index_exists?(:namespaces, :path) + remove_index(:namespaces, :path) + end + + # In some bizarre cases PostgreSQL might have a separate unique constraint + # that we'll need to drop. + if constraint_exists?(constraint_name) && Gitlab::Database.postgresql? + execute("ALTER TABLE namespaces DROP CONSTRAINT IF EXISTS #{constraint_name};") + end + end + end + + def down + unless index_exists?(:namespaces, :path) + add_concurrent_index(:namespaces, :path, unique: true) + end + end + + def constraint_exists?(name) + indexes(:namespaces).map(&:name).include?(name) + end +end diff --git a/db/migrate/20161206153751_add_path_index_to_namespace.rb b/db/migrate/20161206153751_add_path_index_to_namespace.rb new file mode 100644 index 000000000000..b0bac7d121e3 --- /dev/null +++ b/db/migrate/20161206153751_add_path_index_to_namespace.rb @@ -0,0 +1,20 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddPathIndexToNamespace < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + DOWNTIME = false + + def up + add_concurrent_index :namespaces, :path + end + + def down + if index_exists?(:namespaces, :path) + remove_index :namespaces, :path + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 9c46f573719a..434fcc1df3fa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161202152035) do +ActiveRecord::Schema.define(version: 20161206153751) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -748,7 +748,7 @@ add_index "namespaces", ["name"], name: "index_namespaces_on_name_trigram", using: :gin, opclasses: {"name"=>"gin_trgm_ops"} add_index "namespaces", ["owner_id"], name: "index_namespaces_on_owner_id", using: :btree add_index "namespaces", ["parent_id", "id"], name: "index_namespaces_on_parent_id_and_id", unique: true, using: :btree - add_index "namespaces", ["path"], name: "index_namespaces_on_path", unique: true, using: :btree + add_index "namespaces", ["path"], name: "index_namespaces_on_path", using: :btree add_index "namespaces", ["path"], name: "index_namespaces_on_path_trigram", using: :gin, opclasses: {"path"=>"gin_trgm_ops"} add_index "namespaces", ["type"], name: "index_namespaces_on_type", using: :btree diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 67f6a0bd4fe8..19c9691dbbac 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -5,14 +5,10 @@ it { is_expected.to have_many :projects } it { is_expected.to validate_presence_of :name } - it { is_expected.to validate_uniqueness_of(:name) } + it { is_expected.to validate_uniqueness_of(:name).scoped_to(:parent_id) } it { is_expected.to validate_presence_of :path } - it { is_expected.to validate_uniqueness_of(:path) } it { is_expected.to validate_presence_of :owner } - describe "Mass assignment" do - end - describe "Respond to" do it { is_expected.to respond_to(:human_name) } it { is_expected.to respond_to(:to_param) } -- GitLab From a268e5c29f6f248dfa775acba38263e99589f9f0 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 7 Dec 2016 19:16:02 +0200 Subject: [PATCH 02/12] Validate presence of route by Routable concern Signed-off-by: Dmitriy Zaporozhets --- app/models/concerns/routable.rb | 1 + spec/models/concerns/routable_spec.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/app/models/concerns/routable.rb b/app/models/concerns/routable.rb index d36bb9da2968..8d3774844735 100644 --- a/app/models/concerns/routable.rb +++ b/app/models/concerns/routable.rb @@ -7,6 +7,7 @@ module Routable has_one :route, as: :source, autosave: true, dependent: :destroy validates_associated :route + validates :route, presence: true before_validation :update_route_path, if: :full_path_changed? end diff --git a/spec/models/concerns/routable_spec.rb b/spec/models/concerns/routable_spec.rb index 0acefc0c1d5f..d6e93b4bf7bb 100644 --- a/spec/models/concerns/routable_spec.rb +++ b/spec/models/concerns/routable_spec.rb @@ -3,6 +3,10 @@ describe Group, 'Routable' do let!(:group) { create(:group) } + describe 'Validations' do + it { is_expected.to validate_presence_of(:route) } + end + describe 'Associations' do it { is_expected.to have_one(:route).dependent(:destroy) } end -- GitLab From 6e1a5b665241812b3e5fd8ec28c2834364d7dd19 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 7 Dec 2016 19:16:17 +0200 Subject: [PATCH 03/12] Create nested group factory Signed-off-by: Dmitriy Zaporozhets --- spec/factories/groups.rb | 4 ++++ spec/models/group_spec.rb | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/spec/factories/groups.rb b/spec/factories/groups.rb index ebd3595ea641..ece6beb9fa96 100644 --- a/spec/factories/groups.rb +++ b/spec/factories/groups.rb @@ -19,5 +19,9 @@ trait :access_requestable do request_access_enabled true end + + trait :nested do + parent factory: :group + end end end diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 1613a586a2c4..850b1a3cf1ec 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -271,4 +271,11 @@ def setup_group_members(group) expect(group.web_url).to include("groups/#{group.name}") end end + + describe 'nested group' do + subject { create(:group, :nested) } + + it { is_expected.to be_valid } + it { expect(subject.parent).to be_kind_of(Group) } + end end -- GitLab From 325acb322bb32b86d948236d67fdbee972c5adef Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 7 Dec 2016 19:46:44 +0200 Subject: [PATCH 04/12] Change namespace name uniq index to parent_id scope Signed-off-by: Dmitriy Zaporozhets --- ...3_remove_uniq_name_index_from_namespace.rb | 36 +++++++++++++++++++ ...61206153754_add_name_index_to_namespace.rb | 20 +++++++++++ db/schema.rb | 4 +-- 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20161206153753_remove_uniq_name_index_from_namespace.rb create mode 100644 db/migrate/20161206153754_add_name_index_to_namespace.rb diff --git a/db/migrate/20161206153753_remove_uniq_name_index_from_namespace.rb b/db/migrate/20161206153753_remove_uniq_name_index_from_namespace.rb new file mode 100644 index 000000000000..cc9d4974baaf --- /dev/null +++ b/db/migrate/20161206153753_remove_uniq_name_index_from_namespace.rb @@ -0,0 +1,36 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class RemoveUniqNameIndexFromNamespace < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + DOWNTIME = false + + def up + constraint_name = 'namespaces_name_key' + + transaction do + if index_exists?(:namespaces, :name) + remove_index(:namespaces, :name) + end + + # In some bizarre cases PostgreSQL might have a separate unique constraint + # that we'll need to drop. + if constraint_exists?(constraint_name) && Gitlab::Database.postgresql? + execute("ALTER TABLE namespaces DROP CONSTRAINT IF EXISTS #{constraint_name};") + end + end + end + + def down + unless index_exists?(:namespaces, :name) + add_concurrent_index(:namespaces, :name, unique: true) + end + end + + def constraint_exists?(name) + indexes(:namespaces).map(&:name).include?(name) + end +end diff --git a/db/migrate/20161206153754_add_name_index_to_namespace.rb b/db/migrate/20161206153754_add_name_index_to_namespace.rb new file mode 100644 index 000000000000..aaa35ed6f0ae --- /dev/null +++ b/db/migrate/20161206153754_add_name_index_to_namespace.rb @@ -0,0 +1,20 @@ +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class AddNameIndexToNamespace < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + DOWNTIME = false + + def up + add_concurrent_index(:namespaces, [:name, :parent_id], unique: true) + end + + def down + if index_exists?(:namespaces, :name) + remove_index :namespaces, [:name, :parent_id] + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 434fcc1df3fa..08b1590e4845 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161206153751) do +ActiveRecord::Schema.define(version: 20161206153754) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -744,7 +744,7 @@ add_index "namespaces", ["created_at"], name: "index_namespaces_on_created_at", using: :btree add_index "namespaces", ["deleted_at"], name: "index_namespaces_on_deleted_at", using: :btree - add_index "namespaces", ["name"], name: "index_namespaces_on_name", unique: true, using: :btree + add_index "namespaces", ["name", "parent_id"], name: "index_namespaces_on_name_and_parent_id", unique: true, using: :btree add_index "namespaces", ["name"], name: "index_namespaces_on_name_trigram", using: :gin, opclasses: {"name"=>"gin_trgm_ops"} add_index "namespaces", ["owner_id"], name: "index_namespaces_on_owner_id", using: :btree add_index "namespaces", ["parent_id", "id"], name: "index_namespaces_on_parent_id_and_id", unique: true, using: :btree -- GitLab From 8799c96c7bf6158b91127559c58473adb3ff6554 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 7 Dec 2016 20:38:46 +0200 Subject: [PATCH 05/12] Add parents method to the Namespace model Signed-off-by: Dmitriy Zaporozhets --- app/models/namespace.rb | 14 ++++++++++++++ spec/models/namespace_spec.rb | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 7ded50e6ace5..aab6ad873f35 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -161,6 +161,20 @@ def full_path end end + def parents + @parents ||= + begin + parents = [] + + if parent + parents << parent + parents += parent.parents + end + + parents + end + end + private def repository_storage_paths diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 19c9691dbbac..8a42ebe31a02 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -121,4 +121,12 @@ it { expect(group.full_path).to eq(group.path) } it { expect(nested_group.full_path).to eq("#{group.path}/#{nested_group.path}") } end + + describe '#parents' do + let(:group) { create(:group) } + let(:nested_group) { create(:group, parent: group) } + let(:deep_nested_group) { create(:group, parent: nested_group) } + + it { expect(deep_nested_group.parents).to eq([nested_group, group]) } + end end -- GitLab From 0b0a2edb516d599985e9aa9603b0f95ef0aef86d Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Wed, 7 Dec 2016 21:13:13 +0200 Subject: [PATCH 06/12] Add members_with_parents and users_with_parents methods to the Group Signed-off-by: Dmitriy Zaporozhets --- app/models/group.rb | 8 ++++++++ spec/models/group_spec.rb | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/models/group.rb b/app/models/group.rb index 4248e1162d85..f6e21816bf8a 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -191,4 +191,12 @@ def system_hook_service def refresh_members_authorized_projects UserProjectAccessChangedService.new(users.pluck(:id)).execute end + + def members_with_parents + GroupMember.where(source_id: parents.map(&:id).push(id)) + end + + def users_with_parents + User.where(id: members_with_parents.pluck(:user_id)) + end end diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 850b1a3cf1ec..60d644ded5f5 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -278,4 +278,15 @@ def setup_group_members(group) it { is_expected.to be_valid } it { expect(subject.parent).to be_kind_of(Group) } end + + describe '#members_with_parents' do + let!(:group) { create(:group, :nested) } + let!(:master) { group.parent.add_user(create(:user), GroupMember::MASTER) } + let!(:developer) { group.add_user(create(:user), GroupMember::DEVELOPER) } + + it 'returns parents members' do + expect(group.members_with_parents).to include(developer) + expect(group.members_with_parents).to include(master) + end + end end -- GitLab From 751ccd3c199287d43adf0ec93806f47f9fb3ea65 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 8 Dec 2016 17:02:00 +0200 Subject: [PATCH 07/12] Fix group specs Signed-off-by: Dmitriy Zaporozhets --- spec/models/group_spec.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 60d644ded5f5..52a49e8b013c 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -50,9 +50,8 @@ describe 'validations' do it { is_expected.to validate_presence_of :name } - it { is_expected.to validate_uniqueness_of(:name) } + it { is_expected.to validate_uniqueness_of(:name).scoped_to(:parent_id) } it { is_expected.to validate_presence_of :path } - it { is_expected.to validate_uniqueness_of(:path) } it { is_expected.not_to validate_presence_of :owner } end -- GitLab From 4731f9e42d4ab6dd225de6e7bca76d71a31c6db9 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 8 Dec 2016 18:28:49 +0200 Subject: [PATCH 08/12] Show full path in header UI for nested groups/projects Signed-off-by: Dmitriy Zaporozhets --- app/helpers/groups_helper.rb | 11 +++++++++-- app/helpers/projects_helper.rb | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb index f6d4ea4659a5..77dc9e7d538d 100644 --- a/app/helpers/groups_helper.rb +++ b/app/helpers/groups_helper.rb @@ -12,11 +12,18 @@ def group_icon(group) end def group_title(group, name = nil, url = nil) - full_title = link_to(simple_sanitize(group.name), group_path(group)) + full_title = '' + + group.parents.each do |parent| + full_title += link_to(simple_sanitize(parent.name), group_path(parent)) + full_title += ' / '.html_safe + end + + full_title += link_to(simple_sanitize(group.name), group_path(group)) full_title += ' · '.html_safe + link_to(simple_sanitize(name), url) if name content_tag :span do - full_title + full_title.html_safe end end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 9cda3b787613..d2177f683a1a 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -52,7 +52,7 @@ def link_to_member(project, author, opts = {}, &block) def project_title(project) namespace_link = if project.group - link_to(simple_sanitize(project.group.name), group_path(project.group)) + group_title(project.group) else owner = project.namespace.owner link_to(simple_sanitize(owner.name), user_path(owner)) @@ -390,7 +390,7 @@ def project_status_css_class(status) "success" end end - + def readme_cache_key sha = @project.commit.try(:sha) || 'nil' [@project.path_with_namespace, sha, "readme"].join('-') -- GitLab From 5fb5d26eda215a1ba79929b27a5be1407d0d901b Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 8 Dec 2016 18:30:11 +0200 Subject: [PATCH 09/12] Show full path for nested groups at dashboard groups list Signed-off-by: Dmitriy Zaporozhets --- app/models/namespace.rb | 8 ++++++++ app/views/shared/groups/_group.html.haml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/namespace.rb b/app/models/namespace.rb index aab6ad873f35..5de329675af7 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -161,6 +161,14 @@ def full_path end end + def full_name + if parent + parent.full_name + ' / ' + name + else + name + end + end + def parents @parents ||= begin diff --git a/app/views/shared/groups/_group.html.haml b/app/views/shared/groups/_group.html.haml index 19221e3391fc..8164f61797c0 100644 --- a/app/views/shared/groups/_group.html.haml +++ b/app/views/shared/groups/_group.html.haml @@ -28,7 +28,7 @@ = image_tag group_icon(group), class: "avatar s40 hidden-xs" .title = link_to group, class: 'group-name' do - = group.name + = group.full_name - if group_member as -- GitLab From 11cc4e88943dc86d9dbec0cfbdca2c511ed47802 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 8 Dec 2016 20:59:41 +0200 Subject: [PATCH 10/12] Fix admin group routing Signed-off-by: Dmitriy Zaporozhets --- app/views/admin/groups/_group.html.haml | 2 +- app/views/admin/groups/show.html.haml | 4 ++-- config/routes/admin.rb | 14 ++++++++++++-- spec/features/admin/admin_groups_spec.rb | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/views/admin/groups/_group.html.haml b/app/views/admin/groups/_group.html.haml index 664bb417c6a7..4efeec0ea4e0 100644 --- a/app/views/admin/groups/_group.html.haml +++ b/app/views/admin/groups/_group.html.haml @@ -2,7 +2,7 @@ %li.group-row{ class: css_class } .controls - = link_to 'Edit', edit_admin_group_path(group), id: "edit_#{dom_id(group)}", class: 'btn' + = link_to 'Edit', admin_group_edit_path(group), id: "edit_#{dom_id(group)}", class: 'btn' = link_to 'Delete', [:admin, group], data: { confirm: "Are you sure you want to remove #{group.name}?" }, method: :delete, class: 'btn btn-remove' .stats %span diff --git a/app/views/admin/groups/show.html.haml b/app/views/admin/groups/show.html.haml index 40871e32913b..71a605f33b1e 100644 --- a/app/views/admin/groups/show.html.haml +++ b/app/views/admin/groups/show.html.haml @@ -2,7 +2,7 @@ %h3.page-title Group: #{@group.name} - = link_to edit_admin_group_path(@group), class: "btn pull-right" do + = link_to admin_group_edit_path(@group), class: "btn pull-right" do %i.fa.fa-pencil-square-o Edit %hr @@ -88,7 +88,7 @@ Read more about project permissions %strong= link_to "here", help_page_path("user/permissions"), class: "vlink" - = form_tag members_update_admin_group_path(@group), id: "new_project_member", class: "bulk_import", method: :put do + = form_tag admin_group_members_update_path(@group), id: "new_project_member", class: "bulk_import", method: :put do %div = users_select_tag(:user_ids, multiple: true, email_user: true, scope: :all) %div.prepend-top-10 diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 5ae985da5610..51726a027ba3 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -28,9 +28,19 @@ resources :applications - resources :groups, constraints: { id: /[^\/]+/ } do - member do + resources :groups, only: [:index, :new, :create] + + scope(path: 'groups/*id', + controller: :groups, + constraints: { id: Gitlab::Regex.namespace_route_regex }) do + + scope(as: :group) do put :members_update + get :edit, action: :edit + get '/', action: :show + patch '/', action: :update + put '/', action: :update + delete '/', action: :destroy end end diff --git a/spec/features/admin/admin_groups_spec.rb b/spec/features/admin/admin_groups_spec.rb index f6d625fa7f6d..0aa01fc499a0 100644 --- a/spec/features/admin/admin_groups_spec.rb +++ b/spec/features/admin/admin_groups_spec.rb @@ -21,7 +21,7 @@ scenario 'shows the visibility level radio populated with the group visibility_level value' do group = create(:group, :private) - visit edit_admin_group_path(group) + visit admin_group_edit_path(group) expect_selected_visibility(group.visibility_level) end -- GitLab From 424a67dfe30f1f5daffb30db65045b08fb3d492d Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 8 Dec 2016 21:11:20 +0200 Subject: [PATCH 11/12] Use full group name for admin group index and show pages Signed-off-by: Dmitriy Zaporozhets --- app/views/admin/groups/_group.html.haml | 2 +- app/views/admin/groups/show.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/admin/groups/_group.html.haml b/app/views/admin/groups/_group.html.haml index 4efeec0ea4e0..cf28f92853e1 100644 --- a/app/views/admin/groups/_group.html.haml +++ b/app/views/admin/groups/_group.html.haml @@ -20,7 +20,7 @@ = image_tag group_icon(group), class: "avatar s40 hidden-xs" .title = link_to [:admin, group], class: 'group-name' do - = group.name + = group.full_name - if group.description.present? .description diff --git a/app/views/admin/groups/show.html.haml b/app/views/admin/groups/show.html.haml index 71a605f33b1e..7b0175af2140 100644 --- a/app/views/admin/groups/show.html.haml +++ b/app/views/admin/groups/show.html.haml @@ -1,6 +1,6 @@ - page_title @group.name, "Groups" %h3.page-title - Group: #{@group.name} + Group: #{@group.full_name} = link_to admin_group_edit_path(@group), class: "btn pull-right" do %i.fa.fa-pencil-square-o -- GitLab From 4517dde733be9eb33e31f6f23ad5e099de26d849 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 8 Dec 2016 21:30:44 +0200 Subject: [PATCH 12/12] Add nested groups support to admin project routing Signed-off-by: Dmitriy Zaporozhets --- app/views/admin/dashboard/_head.html.haml | 2 +- app/views/admin/dashboard/index.html.haml | 2 +- app/views/admin/projects/index.html.haml | 12 ++++++------ config/routes/admin.rb | 9 ++++----- spec/features/admin/admin_projects_spec.rb | 6 +++--- spec/features/security/admin_access_spec.rb | 2 +- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/app/views/admin/dashboard/_head.html.haml b/app/views/admin/dashboard/_head.html.haml index ec40391a3e3a..b5f96363230b 100644 --- a/app/views/admin/dashboard/_head.html.haml +++ b/app/views/admin/dashboard/_head.html.haml @@ -8,7 +8,7 @@ %span Overview = nav_link(controller: [:admin, :projects]) do - = link_to admin_namespaces_projects_path, title: 'Projects' do + = link_to admin_projects_path, title: 'Projects' do %span Projects = nav_link(controller: :users) do diff --git a/app/views/admin/dashboard/index.html.haml b/app/views/admin/dashboard/index.html.haml index e51f4ac1d934..5238623e936e 100644 --- a/app/views/admin/dashboard/index.html.haml +++ b/app/views/admin/dashboard/index.html.haml @@ -116,7 +116,7 @@ .light-well.well-centered %h4 Projects .data - = link_to admin_namespaces_projects_path do + = link_to admin_projects_path do %h1= number_with_delimiter(Project.cached_count) %hr = link_to('New Project', new_project_path, class: "btn btn-new") diff --git a/app/views/admin/projects/index.html.haml b/app/views/admin/projects/index.html.haml index b37b8d4fee78..8bc7dc7dd51e 100644 --- a/app/views/admin/projects/index.html.haml +++ b/app/views/admin/projects/index.html.haml @@ -7,7 +7,7 @@ %div{ class: container_class } .top-area .prepend-top-default - = form_tag admin_namespaces_projects_path, method: :get do |f| + = form_tag admin_projects_path, method: :get do |f| .search-holder .search-field-holder = search_field_tag :name, params[:name], class: "form-control search-text-input js-search-input", id: "dashboard_search", autofocus: true, spellcheck: false, placeholder: 'Search by name' @@ -41,19 +41,19 @@ = button_tag "Search", class: "btn btn-primary btn-search" %ul.nav-links - - opts = params[:visibility_level].present? ? {} : { page: admin_namespaces_projects_path } + - opts = params[:visibility_level].present? ? {} : { page: admin_projects_path } = nav_link(opts) do - = link_to admin_namespaces_projects_path do + = link_to admin_projects_path do All = nav_link(html_options: { class: params[:visibility_level] == Gitlab::VisibilityLevel::PRIVATE.to_s ? 'active' : '' }) do - = link_to admin_namespaces_projects_path(visibility_level: Gitlab::VisibilityLevel::PRIVATE) do + = link_to admin_projects_path(visibility_level: Gitlab::VisibilityLevel::PRIVATE) do Private = nav_link(html_options: { class: params[:visibility_level] == Gitlab::VisibilityLevel::INTERNAL.to_s ? 'active' : '' }) do - = link_to admin_namespaces_projects_path(visibility_level: Gitlab::VisibilityLevel::INTERNAL) do + = link_to admin_projects_path(visibility_level: Gitlab::VisibilityLevel::INTERNAL) do Internal = nav_link(html_options: { class: params[:visibility_level] == Gitlab::VisibilityLevel::PUBLIC.to_s ? 'active' : '' }) do - = link_to admin_namespaces_projects_path(visibility_level: Gitlab::VisibilityLevel::PUBLIC) do + = link_to admin_projects_path(visibility_level: Gitlab::VisibilityLevel::PUBLIC) do Public .nav-controls diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 51726a027ba3..0dd2c8f7aef7 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -60,14 +60,13 @@ resource :system_info, controller: 'system_info', only: [:show] resources :requests_profiles, only: [:index, :show], param: :name, constraints: { name: /.+\.html/ } - resources :namespaces, path: '/projects', constraints: { id: /[a-zA-Z.0-9_\-]+/ }, only: [] do - root to: 'projects#index', as: :projects + resources :projects, only: [:index] + scope(path: 'projects/*namespace_id', as: :namespace) do resources(:projects, path: '/', - constraints: { id: /[a-zA-Z.0-9_\-]+/ }, - only: [:index, :show]) do - root to: 'projects#show' + constraints: { id: Gitlab::Regex.project_route_regex }, + only: [:show]) do member do put :transfer diff --git a/spec/features/admin/admin_projects_spec.rb b/spec/features/admin/admin_projects_spec.rb index 30ded9202a49..a36bfd574cbe 100644 --- a/spec/features/admin/admin_projects_spec.rb +++ b/spec/features/admin/admin_projects_spec.rb @@ -8,11 +8,11 @@ describe "GET /admin/projects" do before do - visit admin_namespaces_projects_path + visit admin_projects_path end it "is ok" do - expect(current_path).to eq(admin_namespaces_projects_path) + expect(current_path).to eq(admin_projects_path) end it "has projects list" do @@ -22,7 +22,7 @@ describe "GET /admin/projects/:id" do before do - visit admin_namespaces_projects_path + visit admin_projects_path click_link "#{@project.name}" end diff --git a/spec/features/security/admin_access_spec.rb b/spec/features/security/admin_access_spec.rb index fe8cd7b76023..e180ca53eb51 100644 --- a/spec/features/security/admin_access_spec.rb +++ b/spec/features/security/admin_access_spec.rb @@ -4,7 +4,7 @@ include AccessMatchers describe "GET /admin/projects" do - subject { admin_namespaces_projects_path } + subject { admin_projects_path } it { is_expected.to be_allowed_for :admin } it { is_expected.to be_denied_for :user } -- GitLab