Commit 283e868e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor nested group related code

* Simplify code around group parent access check
* Rename 'Nested groups' to 'Subgroups' tab at group#show page
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 10de4e3b
...@@ -12,18 +12,12 @@ module Groups ...@@ -12,18 +12,12 @@ module Groups
return @group return @group
end end
parent_id = params[:parent_id] if @group.parent && !can?(current_user, :admin_group, @group.parent)
@group.parent = nil
if parent_id
parent = Group.find(parent_id)
unless can?(current_user, :admin_group, parent)
@group.parent_id = nil
@group.errors.add(:parent_id, 'manage access required to create subgroup') @group.errors.add(:parent_id, 'manage access required to create subgroup')
return @group return @group
end end
end
@group.name ||= @group.path.dup @group.name ||= @group.path.dup
@group.save @group.save
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
- if @nested_groups.present? - if @nested_groups.present?
%li %li
= link_to "#groups", 'data-toggle' => 'tab' do = link_to "#groups", 'data-toggle' => 'tab' do
Nested Groups 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
...@@ -55,5 +55,4 @@ ...@@ -55,5 +55,4 @@
- if @nested_groups.present? - if @nested_groups.present?
.tab-pane#groups .tab-pane#groups
%ul.content-list %ul.content-list
- @nested_groups.each do |group| = render partial: 'shared/groups/group', collection: @nested_groups
= render 'shared/groups/group', group: group
...@@ -115,7 +115,7 @@ feature 'Group', feature: true do ...@@ -115,7 +115,7 @@ feature 'Group', feature: true do
it 'has nested groups tab with nested groups inside' do it 'has nested groups tab with nested groups inside' do
visit path visit path
click_link 'Nested Groups' click_link 'Subgroups'
expect(page).to have_content(nested_group.full_name) expect(page).to have_content(nested_group.full_name)
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