Commit affc5a31 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'hide-restricted-visibility-radio' into 'master'

Hide restricted and disallowed visibility radios

See merge request gitlab-org/gitlab-ee!14478
parents f3e32a23 710b28ed
......@@ -65,20 +65,6 @@ module VisibilityLevelHelper
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
# model and any changes or additons to these may also need to be made there.
def disallowed_project_visibility_level_description(level, project)
......@@ -181,6 +167,14 @@ module VisibilityLevelHelper
[requested_level, max_allowed_visibility_level(form_model)].min
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
def max_allowed_visibility_level(form_model)
......
- Gitlab::VisibilityLevel.values.each do |level|
- disallowed = disallowed_visibility_level?(form_model, level)
- restricted = restricted_visibility_levels.include?(level)
- disabled = 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}" }
- next if disallowed || restricted
.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
= visibility_level_icon(level)
.option-title
= visibility_level_label(level)
.option-description
= visibility_level_description(level, form_model)
.option-disabled-reason
- if restricted
= restricted_visibility_level_description(level)
- elsif disallowed
= disallowed_visibility_level_description(level, form_model)
.text-muted
- if all_visibility_levels_restricted?
= _('Visibility settings have been disabled by the administrator.')
- 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
......@@ -230,9 +230,6 @@ msgstr ""
msgid "%{level_name} is not allowed since the fork source project has lower visibility."
msgstr ""
msgid "%{level_name} visibility has been restricted by the administrator."
msgstr ""
msgid "%{link_start}Read more%{link_end} about role permissions"
msgstr ""
......@@ -9633,6 +9630,9 @@ msgstr ""
msgid "Other merge requests block this MR"
msgstr ""
msgid "Other visibility settings have been disabled by the administrator."
msgstr ""
msgid "Outbound requests"
msgstr ""
......@@ -15673,6 +15673,9 @@ msgstr ""
msgid "Visibility level:"
msgstr ""
msgid "Visibility settings have been disabled by the administrator."
msgstr ""
msgid "Visibility, project features, permissions"
msgstr ""
......
This diff is collapsed.
......@@ -137,32 +137,6 @@ describe VisibilityLevelHelper do
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
let(:group) { create(:group, :public) }
let!(:project) { create(:project, :internal, group: group) }
......@@ -207,4 +181,50 @@ describe VisibilityLevelHelper do
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
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