Read about our upcoming Code of Conduct on this issue

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

Update `children` route to handle projects and groups

parent 6fb854fb7a33
......@@ -61,7 +61,11 @@ def show
end
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)
render_404
end
......@@ -70,7 +74,7 @@ def children
respond_to do |format|
format.json do
render json: GroupChildrenSerializer
render json: GroupChildSerializer
.new(current_user: current_user)
.with_pagination(request, response)
.represent(@children)
......
......@@ -41,6 +41,9 @@
get :merge_requests, as: :merge_requests_group
get :projects, as: :projects_group
get :activity, as: :activity_group
scope(path: '-') do
get :children, as: :group_children
end
get '/', action: :show, as: :group_canonical
end
......
......@@ -129,7 +129,6 @@ module PathRegex
notification_setting
pipeline_quota
projects
subgroups
].freeze
ILLEGAL_PROJECT_PATH_WORDS = PROJECT_WILDCARD_ROUTES
......
......@@ -150,39 +150,79 @@
end
end
describe 'GET #subgroups', :nested_groups do
let!(:public_subgroup) { create(:group, :public, parent: group) }
let!(:private_subgroup) { create(:group, :private, parent: group) }
describe 'GET #children' do
context 'for projects' do
let!(:public_project) { create(:project, :public, namespace: group) }
let!(:private_project) { create(:project, :private, namespace: group) }
context 'as a user' do
before do
sign_in(user)
pending('spec the children path instead')
context 'as a user' do
before do
sign_in(user)
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
it 'shows all subgroups' do
get :subgroups, id: group.to_param
context 'as a guest' do
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
context 'being member of private subgroup' do
it 'shows public and private subgroups the user is member of' do
group_member.destroy!
private_subgroup.add_guest(user)
context 'for subgroups', :nested_groups do
let!(:public_subgroup) { create(:group, :public, parent: group) }
let!(:private_subgroup) { create(:group, :private, parent: group) }
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
context 'as a guest' do
it 'shows the public subgroups' do
get :subgroups, id: group.to_param
context 'as a guest' do
it 'shows the public children' do
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
......
......@@ -213,7 +213,7 @@ def failure_message(constant_name, migration_helper, missing_words: [], addition
it 'accepts group routes' do
expect(subject).to match('activity/')
expect(subject).to match('group_members/')
expect(subject).to match('subgroups/')
expect(subject).to match('labels/')
end
it 'is not case sensitive' do
......@@ -246,7 +246,7 @@ def failure_message(constant_name, migration_helper, missing_words: [], addition
it 'accepts group routes' do
expect(subject).to match('activity/')
expect(subject).to match('group_members/')
expect(subject).to match('subgroups/')
expect(subject).to match('labels/')
end
end
......@@ -268,7 +268,7 @@ def failure_message(constant_name, migration_helper, missing_words: [], addition
it 'accepts group routes' do
expect(subject).to match('activity/more/')
expect(subject).to match('group_members/more/')
expect(subject).to match('subgroups/more/')
expect(subject).to match('labels/more/')
end
end
end
......@@ -292,7 +292,7 @@ def failure_message(constant_name, migration_helper, missing_words: [], addition
it 'rejects group routes' do
expect(subject).not_to match('root/activity/')
expect(subject).not_to match('root/group_members/')
expect(subject).not_to match('root/subgroups/')
expect(subject).not_to match('root/labels/')
end
end
......@@ -314,7 +314,7 @@ def failure_message(constant_name, migration_helper, missing_words: [], addition
it 'rejects group routes' do
expect(subject).not_to match('root/activity/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
......@@ -349,7 +349,7 @@ def failure_message(constant_name, migration_helper, missing_words: [], addition
it 'accepts group routes' do
expect(subject).to match('activity/')
expect(subject).to match('group_members/')
expect(subject).to match('subgroups/')
expect(subject).to match('labels/')
end
it 'is not case sensitive' do
......@@ -382,7 +382,7 @@ def failure_message(constant_name, migration_helper, missing_words: [], addition
it 'accepts group routes' do
expect(subject).to match('root/activity/')
expect(subject).to match('root/group_members/')
expect(subject).to match('root/subgroups/')
expect(subject).to match('root/labels/')
end
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