Commit 80780018 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Update `children` route to handle projects and groups

parent 648c082a
...@@ -61,7 +61,11 @@ class GroupsController < Groups::ApplicationController ...@@ -61,7 +61,11 @@ class GroupsController < Groups::ApplicationController
end end
def children def children
parent = Group.find_by(parent_id: params[:parent_id]) || @group parent = if params[:parent_id].present?
Group.find(params[:parent_id])
else
@group
end
if parent.nil? || !can?(current_user, :read_group, parent) if parent.nil? || !can?(current_user, :read_group, parent)
render_404 render_404
end end
...@@ -70,7 +74,7 @@ class GroupsController < Groups::ApplicationController ...@@ -70,7 +74,7 @@ class GroupsController < Groups::ApplicationController
respond_to do |format| respond_to do |format|
format.json do format.json do
render json: GroupChildrenSerializer render json: GroupChildSerializer
.new(current_user: current_user) .new(current_user: current_user)
.with_pagination(request, response) .with_pagination(request, response)
.represent(@children) .represent(@children)
......
...@@ -41,6 +41,9 @@ scope(path: 'groups/*id', ...@@ -41,6 +41,9 @@ scope(path: 'groups/*id',
get :merge_requests, as: :merge_requests_group get :merge_requests, as: :merge_requests_group
get :projects, as: :projects_group get :projects, as: :projects_group
get :activity, as: :activity_group get :activity, as: :activity_group
scope(path: '-') do
get :children, as: :group_children
end
get '/', action: :show, as: :group_canonical get '/', action: :show, as: :group_canonical
end end
......
...@@ -129,7 +129,6 @@ module Gitlab ...@@ -129,7 +129,6 @@ module Gitlab
notification_setting notification_setting
pipeline_quota pipeline_quota
projects projects
subgroups
].freeze ].freeze
ILLEGAL_PROJECT_PATH_WORDS = PROJECT_WILDCARD_ROUTES ILLEGAL_PROJECT_PATH_WORDS = PROJECT_WILDCARD_ROUTES
......
...@@ -150,39 +150,79 @@ describe GroupsController do ...@@ -150,39 +150,79 @@ describe GroupsController do
end end
end end
describe 'GET #subgroups', :nested_groups do describe 'GET #children' do
let!(:public_subgroup) { create(:group, :public, parent: group) } context 'for projects' do
let!(:private_subgroup) { create(:group, :private, parent: group) } let!(:public_project) { create(:project, :public, namespace: group) }
let!(:private_project) { create(:project, :private, namespace: group) }
context 'as a user' do context 'as a user' do
before do before do
sign_in(user) sign_in(user)
pending('spec the children path instead') end
it 'shows all children' do
get :children, id: group.to_param, format: :json
expect(assigns(:children)).to contain_exactly(public_project, private_project)
end
context 'being member of private subgroup' do
it 'shows public and private children the user is member of' do
group_member.destroy!
private_project.add_guest(user)
get :children, id: group.to_param, format: :json
expect(assigns(:children)).to contain_exactly(public_project, private_project)
end
end
end end
it 'shows all subgroups' do context 'as a guest' do
get :subgroups, id: group.to_param it 'shows the public children' do
get :children, id: group.to_param, format: :json
expect(assigns(:nested_groups)).to contain_exactly(public_subgroup, private_subgroup) expect(assigns(:children)).to contain_exactly(public_project)
end
end end
end
context 'being member of private subgroup' do context 'for subgroups', :nested_groups do
it 'shows public and private subgroups the user is member of' do let!(:public_subgroup) { create(:group, :public, parent: group) }
group_member.destroy! let!(:private_subgroup) { create(:group, :private, parent: group) }
private_subgroup.add_guest(user) let!(:public_project) { create(:project, :public, namespace: group) }
let!(:private_project) { create(:project, :private, namespace: group) }
get :subgroups, id: group.to_param context 'as a user' do
before do
sign_in(user)
end
expect(assigns(:nested_groups)).to contain_exactly(public_subgroup, private_subgroup) it 'shows all children' do
get :children, id: group.to_param, format: :json
expect(assigns(:children)).to contain_exactly(public_subgroup, private_subgroup, public_project, private_project)
end
context 'being member of private subgroup' do
it 'shows public and private children the user is member of' do
group_member.destroy!
private_subgroup.add_guest(user)
private_project.add_guest(user)
get :children, id: group.to_param, format: :json
expect(assigns(:children)).to contain_exactly(public_subgroup, private_subgroup, public_project, private_project)
end
end end
end end
end
context 'as a guest' do context 'as a guest' do
it 'shows the public subgroups' do it 'shows the public children' do
get :subgroups, id: group.to_param get :children, id: group.to_param, format: :json
expect(assigns(:nested_groups)).to contain_exactly(public_subgroup) expect(assigns(:children)).to contain_exactly(public_subgroup, public_project)
end
end end
end end
end end
......
...@@ -213,7 +213,7 @@ describe Gitlab::PathRegex do ...@@ -213,7 +213,7 @@ describe Gitlab::PathRegex do
it 'accepts group routes' do it 'accepts group routes' do
expect(subject).to match('activity/') expect(subject).to match('activity/')
expect(subject).to match('group_members/') expect(subject).to match('group_members/')
expect(subject).to match('subgroups/') expect(subject).to match('labels/')
end end
it 'is not case sensitive' do it 'is not case sensitive' do
...@@ -246,7 +246,7 @@ describe Gitlab::PathRegex do ...@@ -246,7 +246,7 @@ describe Gitlab::PathRegex do
it 'accepts group routes' do it 'accepts group routes' do
expect(subject).to match('activity/') expect(subject).to match('activity/')
expect(subject).to match('group_members/') expect(subject).to match('group_members/')
expect(subject).to match('subgroups/') expect(subject).to match('labels/')
end end
end end
...@@ -268,7 +268,7 @@ describe Gitlab::PathRegex do ...@@ -268,7 +268,7 @@ describe Gitlab::PathRegex do
it 'accepts group routes' do it 'accepts group routes' do
expect(subject).to match('activity/more/') expect(subject).to match('activity/more/')
expect(subject).to match('group_members/more/') expect(subject).to match('group_members/more/')
expect(subject).to match('subgroups/more/') expect(subject).to match('labels/more/')
end end
end end
end end
...@@ -292,7 +292,7 @@ describe Gitlab::PathRegex do ...@@ -292,7 +292,7 @@ describe Gitlab::PathRegex do
it 'rejects group routes' do it 'rejects group routes' do
expect(subject).not_to match('root/activity/') expect(subject).not_to match('root/activity/')
expect(subject).not_to match('root/group_members/') expect(subject).not_to match('root/group_members/')
expect(subject).not_to match('root/subgroups/') expect(subject).not_to match('root/labels/')
end end
end end
...@@ -314,7 +314,7 @@ describe Gitlab::PathRegex do ...@@ -314,7 +314,7 @@ describe Gitlab::PathRegex do
it 'rejects group routes' do it 'rejects group routes' do
expect(subject).not_to match('root/activity/more/') expect(subject).not_to match('root/activity/more/')
expect(subject).not_to match('root/group_members/more/') expect(subject).not_to match('root/group_members/more/')
expect(subject).not_to match('root/subgroups/more/') expect(subject).not_to match('root/labels/more/')
end end
end end
end end
...@@ -349,7 +349,7 @@ describe Gitlab::PathRegex do ...@@ -349,7 +349,7 @@ describe Gitlab::PathRegex do
it 'accepts group routes' do it 'accepts group routes' do
expect(subject).to match('activity/') expect(subject).to match('activity/')
expect(subject).to match('group_members/') expect(subject).to match('group_members/')
expect(subject).to match('subgroups/') expect(subject).to match('labels/')
end end
it 'is not case sensitive' do it 'is not case sensitive' do
...@@ -382,7 +382,7 @@ describe Gitlab::PathRegex do ...@@ -382,7 +382,7 @@ describe Gitlab::PathRegex do
it 'accepts group routes' do it 'accepts group routes' do
expect(subject).to match('root/activity/') expect(subject).to match('root/activity/')
expect(subject).to match('root/group_members/') expect(subject).to match('root/group_members/')
expect(subject).to match('root/subgroups/') expect(subject).to match('root/labels/')
end end
it 'is not case sensitive' do it 'is not case sensitive' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment