Commit 916bbaf1 authored by Axel García's avatar Axel García Committed by Alex Kalderimis

Update templates for repository size RF CTA

Makes separate CE templates that can be rendered
independently of the actual functionality, using
the new `registration_features_can_be_prompted?`
helper.

Changelog: added
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/77355
EE: true
parent 24c21914
......@@ -15,6 +15,7 @@
= f.label :max_attachment_size, _('Maximum attachment size (MB)'), class: 'label-bold'
= f.number_field :max_attachment_size, class: 'form-control gl-form-input', title: _('Maximum size of individual attachments in comments.'), data: { toggle: 'tooltip', container: 'body' }
= render 'admin/application_settings/repository_size_limit_setting_registration_features_cta', form: f
= render_if_exists 'admin/application_settings/repository_size_limit_setting', form: f
.form-group
......
- return unless registration_features_can_be_prompted?
.form-group
= form.label :disabled_repository_size_limit, class: 'label-bold' do
= _('Size limit per repository (MB)')
= form.number_field :disabled_repository_size_limit, value: '', class: 'form-control gl-form-input', disabled: true
%span.form-text.text-muted
= render 'shared/registration_features_discovery_message'
......@@ -18,6 +18,7 @@
= f.text_area :description, class: 'form-control', rows: 3, maxlength: 250
.form-text.text-muted= _('Optional.')
= render 'shared/repository_size_limit_setting_registration_features_cta', form: f
= render_if_exists 'shared/repository_size_limit_setting', form: f, type: :group
.form-group.gl-mt-3.gl-mb-6
......
......@@ -27,6 +27,7 @@
.row= render_if_exists 'projects/classification_policy_settings', f: f
= render 'shared/repository_size_limit_setting_registration_features_cta', form: f
= render_if_exists 'shared/repository_size_limit_setting', form: f, type: :project
.form-group.gl-mt-3.gl-mb-3
......
- feature_title = local_assigns.fetch(:feature_title, s_('RegistrationFeatures|use this feature'))
- registration_features_docs_path = help_page_path('development/service_ping/index.md', anchor: 'registration-features-program')
- service_ping_settings_path = metrics_and_profiling_admin_application_settings_path(anchor: 'js-usage-settings')
- registration_features_link_start = '<a href="%{url}" target="_blank">'.html_safe % { url: registration_features_docs_path }
%div
%span= sprintf(s_('RegistrationFeatures|Want to %{feature_title} for free?'), { feature_title: feature_title })
- if Gitlab.ee?
= link_to s_('RegistrationFeatures|Enable Service Ping and register for this feature.'), service_ping_settings_path
= sprintf(s_('RegistrationFeatures|Read more about the %{linkStart}%{label}%{linkEnd}.') , { linkStart: "<a href=\"#{registration_features_docs_path}\" target=\"_blank\">", label: s_('RegistrationFeatures|Registration Features Program'), linkEnd: "</a>" }).html_safe
= render_if_exists 'shared/registration_features_discovery_settings_link'
= html_escape(s_('RegistrationFeatures|Read more about the %{link_start}Registration Features Program%{link_end}.')) % { link_start: registration_features_link_start, link_end: '</a>'.html_safe }
- return unless registration_features_can_be_prompted?
.row
.form-group.col-md-9
= form.label :disabled_repository_size_limit, class: 'label-bold' do
= _('Repository size limit (MB)')
= form.number_field :disabled_repository_size_limit, value: '', class: 'form-control', disabled: true
%span.form-text.text-muted
= render 'shared/registration_features_discovery_message'
- return unless repo_size_limit_feature_available?
- form = local_assigns.fetch(:form)
.form-group
= form.label :repository_size_limit, class: 'label-bold' do
= _('Size limit per repository (MB)')
- if repo_size_limit_feature_available?
= form.number_field :repository_size_limit, value: form.object.repository_size_limit.try(:to_mb), class: 'form-control gl-form-input', min: 0, title: _('Maximum size limit for each repository.'), data: { toggle: 'tooltip', container: 'body' }
%span.form-text.text-muted#repository_size_limit_help_block
= _('Includes LFS objects. It can be overridden per group, or per project. 0 for unlimited.')
= link_to _('Learn more.'), help_page_path('user/admin_area/settings/account_and_limit_settings'), target: '_blank', rel: 'noopener noreferrer'
- else
= form.number_field :disabled_repository_size_limit, value: '', class: 'form-control gl-form-input', disabled: true
%span.form-text.text-muted
= render 'shared/registration_features_discovery_message'
= form.number_field :repository_size_limit, value: form.object.repository_size_limit.try(:to_mb), class: 'form-control gl-form-input', min: 0, title: _('Maximum size limit for each repository.'), data: { toggle: 'tooltip', container: 'body' }
%span.form-text.text-muted#repository_size_limit_help_block
= _('Includes LFS objects. It can be overridden per group, or per project. 0 for unlimited.')
= link_to _('Learn more.'), help_page_path('user/admin_area/settings/account_and_limit_settings'), target: '_blank', rel: 'noopener noreferrer'
- return unless current_user.admin?
- service_ping_settings_path = metrics_and_profiling_admin_application_settings_path(anchor: 'js-usage-settings')
= link_to s_('RegistrationFeatures|Enable Service Ping and register for this feature.'), service_ping_settings_path
- return unless current_user.admin?
- return unless current_user.admin? && repo_size_limit_feature_available?
- form = local_assigns.fetch(:form)
- is_project = local_assigns.fetch(:type) == :project
......@@ -6,12 +6,7 @@
.row
.form-group.col-md-9
= form.label :repository_size_limit, class: 'label-bold' do
Repository size limit (MB)
- if repo_size_limit_feature_available?
= form.number_field :repository_size_limit, value: form.object.repository_size_limit.try(:to_mb), class: 'form-control', min: 0, data: { qa_selector: 'repository_size_limit_field' }
%span.form-text.text-muted#repository_size_limit_help_block
= is_project ? size_limit_message(@project) : size_limit_message_for_group(@group)
- else
= form.number_field :disabled_repository_size_limit, value: '', class: 'form-control', disabled: true
%span.form-text.text-muted
= render 'shared/registration_features_discovery_message'
= _('Repository size limit (MB)')
= form.number_field :repository_size_limit, value: form.object.repository_size_limit.try(:to_mb), class: 'form-control', min: 0, data: { qa_selector: 'repository_size_limit_field' }
%span.form-text.text-muted#repository_size_limit_help_block
= is_project ? size_limit_message(@project) : size_limit_message_for_group(@group)
# frozen_string_literal: true
RSpec.shared_examples 'renders registration features settings link' do
let_it_be(:admin) { create(:admin) }
let_it_be(:user) { create(:user) }
context 'as regular user' do
before do
allow(view).to receive(:current_user) { user }
end
it 'does not render settings link', :aggregate_failures do
expect(rendered).not_to have_link(s_('RegistrationFeatures|Enable Service Ping and register for this feature.'))
end
end
context 'as admin' do
before do
allow(view).to receive(:current_user) { admin }
end
it 'renders settings link', :aggregate_failures do
render
expect(rendered).to have_link(s_('RegistrationFeatures|Enable Service Ping and register for this feature.'))
end
end
end
......@@ -40,22 +40,14 @@ RSpec.describe 'admin/application_settings/general.html.haml' do
end
describe 'prompt user about registration features' do
let(:message) { s_("RegistrationFeatures|Want to %{feature_title} for free?") % { feature_title: s_('RegistrationFeatures|use this feature') } }
context 'with no license and service ping disabled' do
before do
allow(License).to receive(:current).and_return(nil)
stub_application_setting(usage_ping_enabled: false)
render
end
it 'renders registration features CTA' do
expect(rendered).to have_content message
expect(rendered).to have_link s_('RegistrationFeatures|Registration Features Program')
expect(rendered).to have_link s_('RegistrationFeatures|Enable Service Ping and register for this feature.')
expect(rendered).to have_field 'application_setting_disabled_repository_size_limit', disabled: true
end
it_behaves_like 'renders registration features prompt', :application_setting_disabled_repository_size_limit
it_behaves_like 'renders registration features settings link'
end
context 'with a valid license and service ping disabled' do
......@@ -63,13 +55,9 @@ RSpec.describe 'admin/application_settings/general.html.haml' do
license = build(:license)
allow(License).to receive(:current).and_return(license)
stub_application_setting(usage_ping_enabled: false)
render
end
it 'does not render registration features CTA' do
expect(rendered).not_to have_content message
end
it_behaves_like 'does not render registration features prompt', :application_setting_disabled_repository_size_limit
end
end
end
......@@ -89,14 +89,8 @@ RSpec.describe 'groups/edit.html.haml' do
allow(License).to receive(:current).and_return(nil)
end
it 'renders a placeholder input with registration features message' do
render
expect(rendered).to have_field(:group_disabled_ip_restriction_ranges, disabled: true)
expect(rendered).to have_content(s_("RegistrationFeatures|Want to %{feature_title} for free?") % { feature_title: s_('RegistrationFeatures|use this feature') })
expect(rendered).to have_link(s_('RegistrationFeatures|Enable Service Ping and register for this feature.'))
expect(rendered).to have_link(s_('RegistrationFeatures|Registration Features Program'))
end
it_behaves_like 'renders registration features prompt', :group_disabled_ip_restriction_ranges
it_behaves_like 'renders registration features settings link'
end
context 'with a valid license' do
......
......@@ -42,22 +42,14 @@ RSpec.describe 'projects/edit' do
end
describe 'prompt user about registration features' do
let(:message) { s_("RegistrationFeatures|Want to %{feature_title} for free?") % { feature_title: s_('RegistrationFeatures|use this feature') } }
context 'with no license and service ping disabled' do
before do
allow(License).to receive(:current).and_return(nil)
stub_application_setting(usage_ping_enabled: false)
render
end
it 'renders registration features CTA' do
expect(rendered).to have_content(message)
expect(rendered).to have_link(s_('RegistrationFeatures|Registration Features Program'))
expect(rendered).to have_link(s_('RegistrationFeatures|Enable Service Ping and register for this feature.'))
expect(rendered).to have_field('project_disabled_repository_size_limit', disabled: true)
end
it_behaves_like 'renders registration features prompt', :project_disabled_repository_size_limit
it_behaves_like 'renders registration features settings link'
end
context 'with a valid license and service ping disabled' do
......@@ -65,13 +57,9 @@ RSpec.describe 'projects/edit' do
license = build(:license)
allow(License).to receive(:current).and_return(license)
stub_application_setting(usage_ping_enabled: false)
render
end
it 'does not render registration features CTA' do
expect(rendered).not_to have_content(message)
end
it_behaves_like 'does not render registration features prompt', :project_disabled_repository_size_limit
end
end
end
......@@ -29442,7 +29442,7 @@ msgstr ""
msgid "RegistrationFeatures|Enable Service Ping and register for this feature."
msgstr ""
msgid "RegistrationFeatures|Read more about the %{linkStart}%{label}%{linkEnd}."
msgid "RegistrationFeatures|Read more about the %{link_start}Registration Features Program%{link_end}."
msgstr ""
msgid "RegistrationFeatures|Registration Features Program"
......@@ -30208,6 +30208,9 @@ msgstr ""
msgid "Repository size is above the limit."
msgstr ""
msgid "Repository size limit (MB)"
msgstr ""
msgid "Repository storage"
msgstr ""
......
# frozen_string_literal: true
RSpec.shared_examples 'renders registration features prompt' do |disabled_field|
it 'renders a placeholder input with registration features message', :aggregate_failures do
render
if disabled_field
expect(rendered).to have_field(disabled_field, disabled: true)
end
expect(rendered).to have_content(s_("RegistrationFeatures|Want to %{feature_title} for free?") % { feature_title: s_('RegistrationFeatures|use this feature') })
expect(rendered).to have_link(s_('RegistrationFeatures|Registration Features Program'))
end
end
RSpec.shared_examples 'does not render registration features prompt' do |disabled_field|
it 'does not render a placeholder input with registration features message' do
it 'does not render a placeholder input with registration features message', :aggregate_failures do
render
if disabled_field
......@@ -9,7 +22,6 @@ RSpec.shared_examples 'does not render registration features prompt' do |disable
end
expect(rendered).not_to have_content(s_("RegistrationFeatures|Want to %{feature_title} for free?") % { feature_title: s_('RegistrationFeatures|use this feature') })
expect(rendered).not_to have_link(s_('RegistrationFeatures|Enable Service Ping and register for this feature.'))
expect(rendered).not_to have_link(s_('RegistrationFeatures|Registration Features Program'))
end
end
......@@ -33,4 +33,31 @@ RSpec.describe 'admin/application_settings/general.html.haml' do
end
end
end
describe 'prompt user about registration features' do
before do
assign(:application_setting, app_settings)
allow(view).to receive(:current_user).and_return(user)
end
context 'when service ping is enabled' do
before do
stub_application_setting(usage_ping_enabled: true)
end
it_behaves_like 'does not render registration features prompt', :application_setting_disabled_repository_size_limit
end
context 'with no license and service ping disabled' do
before do
stub_application_setting(usage_ping_enabled: false)
if Gitlab.ee?
allow(License).to receive(:current).and_return(nil)
end
end
it_behaves_like 'renders registration features prompt', :application_setting_disabled_repository_size_limit
end
end
end
......@@ -139,4 +139,26 @@ RSpec.describe 'projects/edit' do
end
end
end
describe 'prompt user about registration features' do
context 'when service ping is enabled' do
before do
stub_application_setting(usage_ping_enabled: true)
end
it_behaves_like 'does not render registration features prompt', :project_disabled_repository_size_limit
end
context 'with no license and service ping disabled' do
before do
stub_application_setting(usage_ping_enabled: false)
if Gitlab.ee?
allow(License).to receive(:current).and_return(nil)
end
end
it_behaves_like 'renders registration features prompt', :project_disabled_repository_size_limit
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