diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-05-03 15:49:37 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-05-17 21:53:16 +0300 |
commit | 34974258bc3f745c86512319231bad47232fe007 (patch) | |
tree | a6b9b7d7a80282f77471302f0970daced62e0455 | |
parent | ac382b5682dc2d5eea750313c59fb2581af13326 (diff) |
Hide nested group UI/API support for MySQL
This hides/disables some UI elements and API parameters related to
nested groups when MySQL is used, since nested groups are not supported
for MySQL.
-rw-r--r-- | app/controllers/groups_controller.rb | 2 | ||||
-rw-r--r-- | app/models/namespace.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | app/views/groups/_show_nav.html.haml | 7 | ||||
-rw-r--r-- | lib/api/entities.rb | 5 | ||||
-rw-r--r-- | lib/api/groups.rb | 6 | ||||
-rw-r--r-- | lib/api/v3/entities.rb | 5 | ||||
-rw-r--r-- | lib/api/v3/groups.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/group_hierarchy.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/project_authorizations/with_nested_groups.rb | 3 | ||||
-rw-r--r-- | spec/controllers/groups_controller_spec.rb | 2 | ||||
-rw-r--r-- | spec/spec_helper.rb | 2 |
12 files changed, 33 insertions, 17 deletions
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 1515173d0ac..26a4b884c3a 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -64,6 +64,8 @@ class GroupsController < Groups::ApplicationController end def subgroups + return not_found unless Group.supports_nested_groups? + @nested_groups = GroupsFinder.new(current_user, parent: group).execute @nested_groups = @nested_groups.search(params[:filter_groups]) if params[:filter_groups].present? end diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 985395a6fe2..5ceb3d0aee6 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -178,7 +178,7 @@ class Namespace < ActiveRecord::Base # Returns all the ancestors of the current namespaces. def ancestors - return self.class.none if !Group.supports_nested_groups? || !parent_id + return self.class.none unless parent_id Gitlab::GroupHierarchy. new(self.class.where(id: parent_id)). @@ -187,8 +187,6 @@ class Namespace < ActiveRecord::Base # Returns all the descendants of the current namespace. def descendants - return self.class.none unless Group.supports_nested_groups? - Gitlab::GroupHierarchy. new(self.class.where(parent_id: id)). base_and_descendants diff --git a/app/models/user.rb b/app/models/user.rb index 2cf995f8c31..149a80b6083 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -509,8 +509,6 @@ class User < ActiveRecord::Base # Returns a relation of groups the user has access to, including their parent # and child groups (recursively). def all_expanded_groups - return groups unless Group.supports_nested_groups? - Gitlab::GroupHierarchy.new(groups).all_groups end diff --git a/app/views/groups/_show_nav.html.haml b/app/views/groups/_show_nav.html.haml index b2097e88741..35b75bc0923 100644 --- a/app/views/groups/_show_nav.html.haml +++ b/app/views/groups/_show_nav.html.haml @@ -2,6 +2,7 @@ = nav_link(page: group_path(@group)) do = link_to group_path(@group) do Projects - = nav_link(page: subgroups_group_path(@group)) do - = link_to subgroups_group_path(@group) do - Subgroups + - if Group.supports_nested_groups? + = nav_link(page: subgroups_group_path(@group)) do + = link_to subgroups_group_path(@group) do + Subgroups diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 3fc2b453eb6..e3692a58119 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -152,7 +152,10 @@ module API expose :web_url expose :request_access_enabled expose :full_name, :full_path - expose :parent_id + + if ::Group.supports_nested_groups? + expose :parent_id + end expose :statistics, if: :statistics do with_options format_with: -> (value) { value.to_i } do diff --git a/lib/api/groups.rb b/lib/api/groups.rb index 3da7d735da8..ee85b777aff 100644 --- a/lib/api/groups.rb +++ b/lib/api/groups.rb @@ -70,7 +70,11 @@ module API params do requires :name, type: String, desc: 'The name of the group' requires :path, type: String, desc: 'The path of the group' - optional :parent_id, type: Integer, desc: 'The parent group id for creating nested group' + + if ::Group.supports_nested_groups? + optional :parent_id, type: Integer, desc: 'The parent group id for creating nested group' + end + use :optional_params end post do diff --git a/lib/api/v3/entities.rb b/lib/api/v3/entities.rb index 56a9b019f1b..101f566f1dd 100644 --- a/lib/api/v3/entities.rb +++ b/lib/api/v3/entities.rb @@ -137,7 +137,10 @@ module API expose :web_url expose :request_access_enabled expose :full_name, :full_path - expose :parent_id + + if ::Group.supports_nested_groups? + expose :parent_id + end expose :statistics, if: :statistics do with_options format_with: -> (value) { value.to_i } do diff --git a/lib/api/v3/groups.rb b/lib/api/v3/groups.rb index 6187445fc8d..2c52d21fa1c 100644 --- a/lib/api/v3/groups.rb +++ b/lib/api/v3/groups.rb @@ -74,7 +74,11 @@ module API params do requires :name, type: String, desc: 'The name of the group' requires :path, type: String, desc: 'The path of the group' - optional :parent_id, type: Integer, desc: 'The parent group id for creating nested group' + + if ::Group.supports_nested_groups? + optional :parent_id, type: Integer, desc: 'The parent group id for creating nested group' + end + use :optional_params end post do diff --git a/lib/gitlab/group_hierarchy.rb b/lib/gitlab/group_hierarchy.rb index 50e057892a6..e9d5d52cabb 100644 --- a/lib/gitlab/group_hierarchy.rb +++ b/lib/gitlab/group_hierarchy.rb @@ -15,12 +15,16 @@ module Gitlab # Returns a relation that includes the base set of groups and all their # ancestors (recursively). def base_and_ancestors + return model.none unless Group.supports_nested_groups? + base_and_ancestors_cte.apply_to(model.all) end # Returns a relation that includes the base set of groups and all their # descendants (recursively). def base_and_descendants + return model.none unless Group.supports_nested_groups? + base_and_descendants_cte.apply_to(model.all) end @@ -45,6 +49,8 @@ module Gitlab # Using this approach allows us to further add criteria to the relation with # Rails thinking it's selecting data the usual way. def all_groups + return base unless Group.supports_nested_groups? + ancestors = base_and_ancestors_cte descendants = base_and_descendants_cte diff --git a/lib/gitlab/project_authorizations/with_nested_groups.rb b/lib/gitlab/project_authorizations/with_nested_groups.rb index 79c082c08fd..bb0df1e3dad 100644 --- a/lib/gitlab/project_authorizations/with_nested_groups.rb +++ b/lib/gitlab/project_authorizations/with_nested_groups.rb @@ -19,9 +19,6 @@ module Gitlab projects = Project.arel_table links = ProjectGroupLink.arel_table - # These queries don't directly use the user object so they don't depend - # on the state of said object, ensuring the produced queries are always - # the same. relations = [ # The project a user has direct access to. user.projects.select_for_project_authorization, diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index 15dae3231ca..a5477a48cf2 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -26,7 +26,7 @@ describe GroupsController do end end - describe 'GET #subgroups' do + describe 'GET #subgroups', :nested_groups do let!(:public_subgroup) { create(:group, :public, parent: group) } let!(:private_subgroup) { create(:group, :private, parent: group) } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8db141247c2..c126641c4b9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -95,7 +95,7 @@ RSpec.configure do |config| end config.around(:each, :nested_groups) do |example| - example.run if Gitlab::GroupHierarchy.supports_nested_groups? + example.run if Group.supports_nested_groups? end config.around(:each, :postgresql) do |example| |