Commit 8437a24f authored by Michael Kozono's avatar Michael Kozono

Vary share lock setting UI

…based on whether the current user owns the parent group and whether the parent group or current group is share locked.
parent c93e8f24
...@@ -65,6 +65,22 @@ module GroupsHelper ...@@ -65,6 +65,22 @@ module GroupsHelper
{ group_name: group.name } { group_name: group.name }
end end
def share_with_group_lock_disabled
return false unless @group.has_parent?
return false unless @group.parent.share_with_group_lock?
return false unless @group.share_with_group_lock?
return false if @group.has_owner?(current_user)
return true
end
def share_with_group_lock_help_text
return default_help unless @group.has_parent?
return default_help unless @group.parent.share_with_group_lock?
return parent_locked_and_has_been_overridden unless @group.share_with_group_lock?
return parent_locked_but_you_can_override if @group.has_owner?(current_user)
return parent_locked_so_ask_the_owner
end
private private
def group_title_link(group, hidable: false, show_avatar: false) def group_title_link(group, hidable: false, show_avatar: false)
...@@ -80,4 +96,20 @@ module GroupsHelper ...@@ -80,4 +96,20 @@ module GroupsHelper
output.html_safe output.html_safe
end end
end end
def default_help
"This setting will be applied to all subgroups unless overridden by a group owner."
end
def parent_locked_but_you_can_override
"This setting is applied on #{@group.parent.name}. You can override the setting or remove the share lock from the parent group."
end
def parent_locked_so_ask_the_owner
"This setting is applied on #{@group.parent.name}. To share this group with another group, ask the owner to override the setting or remove the share lock from the parent group."
end
def parent_locked_and_has_been_overridden
"This setting is applied on #{@group.parent.name} and has been overridden on this subgroup."
end
end end
...@@ -33,13 +33,13 @@ ...@@ -33,13 +33,13 @@
.col-sm-10 .col-sm-10
.checkbox .checkbox
= f.label :share_with_group_lock do = f.label :share_with_group_lock do
= f.check_box :share_with_group_lock = f.check_box :share_with_group_lock, disabled: share_with_group_lock_disabled
%strong %strong
Prevent sharing a project within Prevent sharing a project within
= @group.name = @group.name
with other groups with other groups
%br/ %br/
%span.descr This setting will be applied to all subgroups unless overridden by a group owner %span.descr= share_with_group_lock_help_text
= render 'group_admin_settings', f: f = render 'group_admin_settings', f: f
......
require 'spec_helper'
describe 'groups/edit.html.haml' do
include Devise::Test::ControllerHelpers
describe 'Share lock option' do
let(:root_owner) { create(:user) }
let(:root_group) { create(:group) }
let(:expected_label) { default_label }
let(:expected_help) { default_help }
before do
root_group.add_owner(root_owner)
end
shared_examples_for 'share lock option' do |checkbox_options|
it 'should have the correct label, help text, and checkbox options' do
assign(:group, test_group)
allow(view).to receive(:can?).and_return(true)
allow(view).to receive(:can_change_group_visibility_level?).and_return(false)
allow(view).to receive(:current_user).and_return(test_user)
render
expect(rendered).to have_content(expected_label)
expect(rendered).to have_css('.descr', text: expected_help)
expect(rendered).to have_field('group_share_with_group_lock', checkbox_options)
end
end
context 'for a root group' do
let(:test_group) { root_group }
let(:test_user) { root_owner }
it_behaves_like 'share lock option', { disabled: false, checked: false }
end
context 'for a subgroup', :nested_groups do
let!(:subgroup) { create(:group, parent: root_group) }
let(:sub_owner) { create(:user) }
let(:test_group) { subgroup }
context 'when the root_group has "Share lock" disabled' do
context 'when the subgroup has "Share lock" disabled' do
context 'as the root_owner' do
let(:test_user) { root_owner }
it_behaves_like 'share lock option', { disabled: false, checked: false }
end
context 'as the sub_owner' do
let(:test_user) { sub_owner }
it_behaves_like 'share lock option', { disabled: false, checked: false }
end
end
context 'when the subgroup has "Share lock" enabled' do
before do
subgroup.update_column(:share_with_group_lock, true)
end
context 'as the root_owner' do
let(:test_user) { root_owner }
it_behaves_like 'share lock option', { disabled: false, checked: true }
end
context 'as the sub_owner' do
let(:test_user) { sub_owner }
it_behaves_like 'share lock option', { disabled: false, checked: true }
end
end
end
context 'when the root_group has "Share lock" enabled' do
before do
root_group.update_column(:share_with_group_lock, true)
end
context 'when the subgroup has "Share lock" disabled (parent overridden)' do
context 'as the root_owner' do
let(:test_user) { root_owner }
let(:expected_help) { parent_locked_and_has_been_overridden }
it_behaves_like 'share lock option', { disabled: false, checked: false }
end
context 'as the sub_owner' do
let(:test_user) { sub_owner }
let(:expected_help) { parent_locked_and_has_been_overridden }
it_behaves_like 'share lock option', { disabled: false, checked: false }
end
end
context 'when the subgroup has "Share lock" enabled (same as parent)' do
before do
subgroup.update_column(:share_with_group_lock, true)
end
context 'as the root_owner' do
let(:test_user) { root_owner }
let(:expected_help) { parent_locked_but_you_can_override }
it_behaves_like 'share lock option', { disabled: false, checked: true }
end
context 'as the sub_owner' do
let(:test_user) { sub_owner }
let(:expected_help) { parent_locked_so_ask_the_owner }
it_behaves_like 'share lock option', { disabled: true, checked: true }
end
end
end
end
def default_label
"Prevent sharing a project within #{test_group.name} with other groups"
end
def default_help
"This setting will be applied to all subgroups unless overridden by a group owner."
end
def parent_locked_but_you_can_override
"This setting is applied on #{test_group.parent.name}. You can override the setting or remove the share lock from the parent group."
end
def parent_locked_so_ask_the_owner
"This setting is applied on #{test_group.parent.name}. To share this group with another group, ask the owner to override the setting or remove the share lock from the parent group."
end
def parent_locked_and_has_been_overridden
"This setting is applied on #{test_group.parent.name} and has been overridden on this subgroup."
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