diff --git a/app/helpers/visibility_level_helper.rb b/app/helpers/visibility_level_helper.rb index cddfc48c6493955811e5257f864676b411441e3b..e248bb657f61b0f09f404b69b8448ab6538b6539 100644 --- a/app/helpers/visibility_level_helper.rb +++ b/app/helpers/visibility_level_helper.rb @@ -84,8 +84,8 @@ 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 + def any_visibility_levels_restricted? + restricted_visibility_levels.any? end private @@ -151,6 +151,17 @@ def group_visibility_level_description(level, group = nil) end end + def group_visibility_level_name(level) + case level + when Gitlab::VisibilityLevel::PRIVATE + s_("VisibilityLevel|Private") + when Gitlab::VisibilityLevel::INTERNAL + s_("VisibilityLevel|Internal") + when Gitlab::VisibilityLevel::PUBLIC + s_('VisibilityLevel|Public') + end + end + def project_visibility_icon_description(level) "#{visibility_level_label(level)} - #{project_visibility_level_description(level)}" end diff --git a/app/views/shared/_visibility_radios.html.haml b/app/views/shared/_visibility_radios.html.haml index b4013cb5b80981bbe928ba48ea20d02dc4b33109..0f67f453664c7efa77f6971627c0ff86dc4b2965 100644 --- a/app/views/shared/_visibility_radios.html.haml +++ b/app/views/shared/_visibility_radios.html.haml @@ -9,9 +9,8 @@ radio_options: { checked: (selected_level == level), data: { track_label: "blank_project", track_action: "activate_form_input", track_property: "#{model_method}_#{level}", track_value: "" } }, label_options: { class: 'js-visibility-level-radio' } - -.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.') +- if any_visibility_levels_restricted? + = render Pajamas::AlertComponent.new(variant: :warning, dismissible: false, alert_options: { class: 'gl-my-5' }) do |c| + - c.with_body do + = n_('The following visibility level has been restricted by the administrator:', 'The following visibility levels have been restricted by the administrator:', restricted_visibility_levels.length) + = restricted_visibility_levels.map { |level| group_visibility_level_name(level) }.join(', ') diff --git a/locale/gitlab.pot b/locale/gitlab.pot index e032315abf9054da7f3574f0adee5dafccb6cc75..899abb52305181ab8f5874b24815db263edd90d7 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -51485,6 +51485,11 @@ msgstr[1] "" msgid "The following personal access tokens have expired:" msgstr "" +msgid "The following visibility level has been restricted by the administrator:" +msgid_plural "The following visibility levels have been restricted by the administrator:" +msgstr[0] "" +msgstr[1] "" + msgid "The fork relationship has been removed." msgstr "" diff --git a/spec/features/groups/settings/general_visibility_levels_spec.rb b/spec/features/groups/settings/general_visibility_levels_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..dd63109876462fc573f0476cd5363e80a7d356b2 --- /dev/null +++ b/spec/features/groups/settings/general_visibility_levels_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'General visibility level', feature_category: :groups_and_projects do + let_it_be(:parent_group) { create(:group, :public) } + let_it_be(:user) { create(:user).tap { |user| parent_group.add_owner(user) } } + + before do + sign_in(user) + end + + context 'with multiple restricted visibility levels' do + before do + stub_application_setting(restricted_visibility_levels: Gitlab::VisibilityLevel.values) + end + + it 'shows warning of restricted visibility levels' do + visit edit_group_path(parent_group) + + expect(page).to have_content( + 'The following visibility levels have been restricted by the administrator: Private, Internal, Public' + ) + end + end + + context 'with restricted visibility level public' do + before do + stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel.string_options['public']]) + end + + it 'shows warning of restricted visibility levels' do + visit edit_group_path(parent_group) + + expect(page).to have_content('The following visibility level has been restricted by the administrator: Public') + end + end + + context 'without restricted visibility levels' do + it 'does not show warning of restricted visibility levels' do + visit edit_group_path(parent_group) + + expect(page).not_to have_content('The following visibility levels have been restricted by the administrator:') + end + end +end diff --git a/spec/helpers/visibility_level_helper_spec.rb b/spec/helpers/visibility_level_helper_spec.rb index 4af7fae400ee328cb474a6570892ae19e8146aee..f29d8be4ec23bfbac440eae7ffc147cb247f1d2d 100644 --- a/spec/helpers/visibility_level_helper_spec.rb +++ b/spec/helpers/visibility_level_helper_spec.rb @@ -301,23 +301,24 @@ end end - describe 'all_visibility_levels_restricted?' do + describe 'any_visibility_levels_restricted?' do using RSpec::Parameterized::TableSyntax let(:user) { create(:user) } - subject { helper.all_visibility_levels_restricted? } + subject { helper.any_visibility_levels_restricted? } where(:restricted_visibility_levels, :expected) do - [Gitlab::VisibilityLevel::PUBLIC] | false - [Gitlab::VisibilityLevel::PUBLIC, Gitlab::VisibilityLevel::INTERNAL] | false - Gitlab::VisibilityLevel.values | true + [Gitlab::VisibilityLevel::PUBLIC] | true + [Gitlab::VisibilityLevel::INTERNAL] | true + [Gitlab::VisibilityLevel::PUBLIC, Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::PRIVATE] | true + [] | false 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 } + stub_application_setting(restricted_visibility_levels: restricted_visibility_levels) end it { is_expected.to eq(expected) }