Commit 23fc1f66 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'dz-nested-group-misc' into 'master'

Miscellaneous improvements to the nested groups feature

See merge request !8308
parents 714f70a3 283e868e
...@@ -42,6 +42,8 @@ class GroupsController < Groups::ApplicationController ...@@ -42,6 +42,8 @@ class GroupsController < Groups::ApplicationController
@notification_setting = current_user.notification_settings_for(group) @notification_setting = current_user.notification_settings_for(group)
end end
@nested_groups = group.children
setup_projects setup_projects
respond_to do |format| respond_to do |format|
......
...@@ -12,6 +12,13 @@ module Groups ...@@ -12,6 +12,13 @@ module Groups
return @group return @group
end end
if @group.parent && !can?(current_user, :admin_group, @group.parent)
@group.parent = nil
@group.errors.add(:parent_id, 'manage access required to create subgroup')
return @group
end
@group.name ||= @group.path.dup @group.name ||= @group.path.dup
@group.save @group.save
@group.add_owner(current_user) @group.add_owner(current_user)
......
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
%li %li
= link_to "#shared", 'data-toggle' => 'tab' do = link_to "#shared", 'data-toggle' => 'tab' do
Shared Projects Shared Projects
- if @nested_groups.present?
%li
= link_to "#groups", 'data-toggle' => 'tab' do
Subgroups
.nav-controls .nav-controls
= form_tag request.path, method: :get, class: 'project-filter-form', id: 'project-filter-form' do |f| = form_tag request.path, method: :get, class: 'project-filter-form', id: 'project-filter-form' do |f|
= search_field_tag :filter_projects, nil, placeholder: 'Filter by name', class: 'projects-list-filter form-control', spellcheck: false = search_field_tag :filter_projects, nil, placeholder: 'Filter by name', class: 'projects-list-filter form-control', spellcheck: false
...@@ -47,3 +51,8 @@ ...@@ -47,3 +51,8 @@
- if @shared_projects.present? - if @shared_projects.present?
.tab-pane#shared .tab-pane#shared
= render "shared_projects", projects: @shared_projects = render "shared_projects", projects: @shared_projects
- if @nested_groups.present?
.tab-pane#groups
%ul.content-list
= render partial: 'shared/groups/group', collection: @nested_groups
---
title: Show nested groups tab on group page
merge_request: 8308
author:
...@@ -107,4 +107,17 @@ feature 'Group', feature: true do ...@@ -107,4 +107,17 @@ feature 'Group', feature: true do
expect(page).to have_css('.group-home-desc a[rel]') expect(page).to have_css('.group-home-desc a[rel]')
end end
end end
describe 'group page with nested groups', js: true do
let!(:group) { create(:group) }
let!(:nested_group) { create(:group, parent: group) }
let!(:path) { group_path(group) }
it 'has nested groups tab with nested groups inside' do
visit path
click_link 'Subgroups'
expect(page).to have_content(nested_group.full_name)
end
end
end end
require 'spec_helper' require 'spec_helper'
describe Groups::CreateService, services: true do describe Groups::CreateService, '#execute', services: true do
let!(:user) { create(:user) } let!(:user) { create(:user) }
let!(:group_params) { { path: "group_path", visibility_level: Gitlab::VisibilityLevel::PUBLIC } } let!(:group_params) { { path: "group_path", visibility_level: Gitlab::VisibilityLevel::PUBLIC } }
describe "execute" do describe 'visibility level restrictions' do
let!(:service) { described_class.new(user, group_params ) } let!(:service) { described_class.new(user, group_params) }
subject { service.execute } subject { service.execute }
context "create groups without restricted visibility level" do context "create groups without restricted visibility level" do
...@@ -14,7 +15,29 @@ describe Groups::CreateService, services: true do ...@@ -14,7 +15,29 @@ describe Groups::CreateService, services: true do
context "cannot create group with restricted visibility level" do context "cannot create group with restricted visibility level" do
before { allow_any_instance_of(ApplicationSetting).to receive(:restricted_visibility_levels).and_return([Gitlab::VisibilityLevel::PUBLIC]) } before { allow_any_instance_of(ApplicationSetting).to receive(:restricted_visibility_levels).and_return([Gitlab::VisibilityLevel::PUBLIC]) }
it { is_expected.not_to be_persisted } it { is_expected.not_to be_persisted }
end end
end end
describe 'creating subgroup' do
let!(:group) { create(:group) }
let!(:service) { described_class.new(user, group_params.merge(parent_id: group.id)) }
subject { service.execute }
context 'as group owner' do
before { group.add_owner(user) }
it { is_expected.to be_persisted }
end
context 'as guest' do
it 'does not save group and returns an error' do
is_expected.not_to be_persisted
expect(subject.errors[:parent_id].first).to eq('manage access required to create subgroup')
expect(subject.parent_id).to be_nil
end
end
end
end end
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