Commit 9b40fc74 authored by Luke Bennett's avatar Luke Bennett Committed by Douglas Barbosa Alexandre

Hide restricted and disallowed visibility radios

Show a message if many levels are restricted and a
different message if all levels are restricted.
parent 96277bb9
...@@ -65,20 +65,6 @@ module VisibilityLevelHelper ...@@ -65,20 +65,6 @@ module VisibilityLevelHelper
end end
end end
def restricted_visibility_level_description(level)
level_name = Gitlab::VisibilityLevel.level_name(level)
_("%{level_name} visibility has been restricted by the administrator.") % { level_name: level_name.capitalize }
end
def disallowed_visibility_level_description(level, form_model)
case form_model
when Project
disallowed_project_visibility_level_description(level, form_model)
when Group
disallowed_group_visibility_level_description(level, form_model)
end
end
# Note: these messages closely mirror the form validation strings found in the project # Note: these messages closely mirror the form validation strings found in the project
# model and any changes or additons to these may also need to be made there. # model and any changes or additons to these may also need to be made there.
def disallowed_project_visibility_level_description(level, project) def disallowed_project_visibility_level_description(level, project)
...@@ -181,6 +167,14 @@ module VisibilityLevelHelper ...@@ -181,6 +167,14 @@ module VisibilityLevelHelper
[requested_level, max_allowed_visibility_level(form_model)].min [requested_level, max_allowed_visibility_level(form_model)].min
end end
def multiple_visibility_levels_restricted?
restricted_visibility_levels.many? # rubocop: disable CodeReuse/ActiveRecord
end
def all_visibility_levels_restricted?
Gitlab::VisibilityLevel.values == restricted_visibility_levels
end
private private
def max_allowed_visibility_level(form_model) def max_allowed_visibility_level(form_model)
......
- Gitlab::VisibilityLevel.values.each do |level| - Gitlab::VisibilityLevel.values.each do |level|
- disallowed = disallowed_visibility_level?(form_model, level) - disallowed = disallowed_visibility_level?(form_model, level)
- restricted = restricted_visibility_levels.include?(level) - restricted = restricted_visibility_levels.include?(level)
- disabled = disallowed || restricted - next if disallowed || restricted
.form-check{ class: [('disabled' if disabled), ('restricted' if restricted)] }
= form.radio_button model_method, level, checked: (selected_level == level), disabled: disabled, class: 'form-check-input', data: { track_label: "blank_project", track_event: "activate_form_input", track_property: "#{model_method}", track_value: "#{level}" } .form-check
= form.radio_button model_method, level, checked: (selected_level == level), class: 'form-check-input', data: { track_label: "blank_project", track_event: "activate_form_input", track_property: "#{model_method}", track_value: "#{level}" }
= form.label "#{model_method}_#{level}", class: 'form-check-label' do = form.label "#{model_method}_#{level}", class: 'form-check-label' do
= visibility_level_icon(level) = visibility_level_icon(level)
.option-title .option-title
= visibility_level_label(level) = visibility_level_label(level)
.option-description .option-description
= visibility_level_description(level, form_model) = visibility_level_description(level, form_model)
.option-disabled-reason
- if restricted .text-muted
= restricted_visibility_level_description(level) - if all_visibility_levels_restricted?
- elsif disallowed = _('Visibility settings have been disabled by the administrator.')
= disallowed_visibility_level_description(level, form_model) - elsif multiple_visibility_levels_restricted?
= _('Other visibility settings have been disabled by the administrator.')
---
title: Hide restricted and disallowed visibility radios
merge_request: 30590
author:
type: fixed
...@@ -171,9 +171,6 @@ msgstr "" ...@@ -171,9 +171,6 @@ msgstr ""
msgid "%{level_name} is not allowed since the fork source project has lower visibility." msgid "%{level_name} is not allowed since the fork source project has lower visibility."
msgstr "" msgstr ""
msgid "%{level_name} visibility has been restricted by the administrator."
msgstr ""
msgid "%{link_start}Read more%{link_end} about role permissions" msgid "%{link_start}Read more%{link_end} about role permissions"
msgstr "" msgstr ""
...@@ -7228,6 +7225,9 @@ msgstr "" ...@@ -7228,6 +7225,9 @@ msgstr ""
msgid "Other Labels" msgid "Other Labels"
msgstr "" msgstr ""
msgid "Other visibility settings have been disabled by the administrator."
msgstr ""
msgid "Outbound requests" msgid "Outbound requests"
msgstr "" msgstr ""
...@@ -11974,6 +11974,9 @@ msgstr "" ...@@ -11974,6 +11974,9 @@ msgstr ""
msgid "Visibility level:" msgid "Visibility level:"
msgstr "" msgstr ""
msgid "Visibility settings have been disabled by the administrator."
msgstr ""
msgid "Visibility, project features, permissions" msgid "Visibility, project features, permissions"
msgstr "" msgstr ""
......
This diff is collapsed.
...@@ -137,32 +137,6 @@ describe VisibilityLevelHelper do ...@@ -137,32 +137,6 @@ describe VisibilityLevelHelper do
end end
end end
describe "disallowed_visibility_level_description" do
let(:group) { create(:group, :internal) }
let!(:subgroup) { create(:group, :internal, parent: group) }
let!(:project) { create(:project, :internal, group: group) }
describe "project" do
it "provides correct description for disabled levels" do
expect(disallowed_visibility_level?(project, Gitlab::VisibilityLevel::PUBLIC)).to be_truthy
expect(strip_tags disallowed_visibility_level_description(Gitlab::VisibilityLevel::PUBLIC, project))
.to include "the visibility of #{project.group.name} is internal"
end
end
describe "group" do
it "provides correct description for disabled levels" do
expect(disallowed_visibility_level?(group, Gitlab::VisibilityLevel::PRIVATE)).to be_truthy
expect(disallowed_visibility_level_description(Gitlab::VisibilityLevel::PRIVATE, group))
.to include "it contains projects with higher visibility", "it contains sub-groups with higher visibility"
expect(disallowed_visibility_level?(subgroup, Gitlab::VisibilityLevel::PUBLIC)).to be_truthy
expect(strip_tags disallowed_visibility_level_description(Gitlab::VisibilityLevel::PUBLIC, subgroup))
.to include "the visibility of #{group.name} is internal"
end
end
end
describe "selected_visibility_level" do describe "selected_visibility_level" do
let(:group) { create(:group, :public) } let(:group) { create(:group, :public) }
let!(:project) { create(:project, :internal, group: group) } let!(:project) { create(:project, :internal, group: group) }
...@@ -207,4 +181,50 @@ describe VisibilityLevelHelper do ...@@ -207,4 +181,50 @@ describe VisibilityLevelHelper do
end end
end end
end end
describe 'multiple_visibility_levels_restricted?' do
using RSpec::Parameterized::TableSyntax
let(:user) { create(:user) }
subject { helper.multiple_visibility_levels_restricted? }
where(:restricted_visibility_levels, :expected) do
[Gitlab::VisibilityLevel::PUBLIC] | false
[Gitlab::VisibilityLevel::PUBLIC, Gitlab::VisibilityLevel::INTERNAL] | true
[Gitlab::VisibilityLevel::PUBLIC, Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::PRIVATE] | true
end
with_them do
before do
allow(helper).to receive(:current_user) { user }
allow(Gitlab::CurrentSettings.current_application_settings).to receive(:restricted_visibility_levels) { restricted_visibility_levels }
end
it { is_expected.to eq(expected) }
end
end
describe 'all_visibility_levels_restricted?' do
using RSpec::Parameterized::TableSyntax
let(:user) { create(:user) }
subject { helper.all_visibility_levels_restricted? }
where(:restricted_visibility_levels, :expected) do
[Gitlab::VisibilityLevel::PUBLIC] | false
[Gitlab::VisibilityLevel::PUBLIC, Gitlab::VisibilityLevel::INTERNAL] | false
Gitlab::VisibilityLevel.values | true
end
with_them do
before do
allow(helper).to receive(:current_user) { user }
allow(Gitlab::CurrentSettings.current_application_settings).to receive(:restricted_visibility_levels) { restricted_visibility_levels }
end
it { is_expected.to eq(expected) }
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