Commit 1332e9a8 authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch 'registration-features-frontend' into 'master'

UsagePing EE features frontend

See merge request gitlab-org/gitlab!64186
parents 7909fd7d 295bd623
import initSetHelperText from '~/pages/admin/application_settings/metrics_and_profiling/usage_statistics';
import PayloadPreviewer from '~/pages/admin/application_settings/payload_previewer';
export default () => {
......@@ -5,3 +6,5 @@ export default () => {
new PayloadPreviewer(trigger).init();
});
};
initSetHelperText();
import { __ } from '~/locale';
export const HELPER_TEXT_USAGE_PING_DISABLED = __(
'To enable Registration Features, make sure "Enable service ping" is checked.',
);
export const HELPER_TEXT_USAGE_PING_ENABLED = __(
'You can enable Registration Features because Service Ping is enabled. To continue using Registration Features in future, you will also need to register with GitLab via a new cloud licensing service.',
);
function setHelperText(usagePingCheckbox) {
const helperTextId = document.getElementById('usage_ping_features_helper_text');
const usagePingFeaturesLabel = document.getElementById('usage_ping_features_label');
const usagePingFeaturesCheckbox = document.getElementById(
'application_setting_usage_ping_features_enabled',
);
helperTextId.textContent = usagePingCheckbox.checked
? HELPER_TEXT_USAGE_PING_ENABLED
: HELPER_TEXT_USAGE_PING_DISABLED;
usagePingFeaturesLabel.classList.toggle('gl-cursor-not-allowed', !usagePingCheckbox.checked);
usagePingFeaturesCheckbox.disabled = !usagePingCheckbox.checked;
if (!usagePingCheckbox.checked) {
usagePingFeaturesCheckbox.disabled = true;
usagePingFeaturesCheckbox.checked = false;
}
}
export default function initSetHelperText() {
const usagePingCheckbox = document.getElementById('application_setting_usage_ping_enabled');
setHelperText(usagePingCheckbox);
usagePingCheckbox.addEventListener('change', () => {
setHelperText(usagePingCheckbox);
});
}
......@@ -331,6 +331,7 @@ module ApplicationSettingsHelper
:unique_ips_limit_per_user,
:unique_ips_limit_time_window,
:usage_ping_enabled,
:usage_ping_features_enabled,
:user_default_external,
:user_show_add_ssh_key_message,
:user_default_internal_regex,
......
......@@ -377,6 +377,10 @@ module ApplicationSettingImplementation
Settings.gitlab.usage_ping_enabled
end
def usage_ping_features_enabled?
usage_ping_enabled? && usage_ping_features_enabled
end
def usage_ping_enabled
usage_ping_can_be_configured? && super
end
......
......@@ -35,5 +35,26 @@
- deactivating_service_ping_path = help_page_path('development/usage_ping/index.md', anchor: 'disable-usage-ping')
- deactivating_service_ping_link_start = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: deactivating_service_ping_path }
= s_('For more information, see the documentation on %{deactivating_service_ping_link_start}deactivating service ping%{deactivating_service_ping_link_end}.').html_safe % { deactivating_service_ping_link_start: deactivating_service_ping_link_start, deactivating_service_ping_link_end: '</a>'.html_safe }
.form-group
- usage_ping_enabled = @application_setting.usage_ping_enabled?
.form-check
= f.check_box :usage_ping_features_enabled?, disabled: !usage_ping_enabled, class: 'form-check-input'
= f.label :usage_ping_features_enabled?, class: 'form-check-label gl-cursor-not-allowed', id: 'usage_ping_features_label' do
= _('Enable Registration Features')
= link_to sprite_icon('question-o'), help_page_path('development/usage_ping/index.md', anchor: 'registration-features-program')
.form-text.text-muted
- if usage_ping_enabled
%p.gl-mb-3.text-muted{ id: 'usage_ping_features_helper_text' }= _('You can enable Registration Features because Service Ping is enabled. To continue using Registration Features in future, you will also need to register with GitLab via a new cloud licensing service.')
- else
%p.gl-mb-3.text-muted{ id: 'usage_ping_features_helper_text' }= _('To enable Registration Features, make sure "Enable service ping" is checked.')
%p.gl-mb-3.text-muted= _('Registration Features include:')
.form-text
- email_from_gitlab_path = help_page_path('tools/email.md')
- link_end = '</a>'.html_safe
- email_from_gitlab_link = '<a href="%{url}" target="_blank" rel="noopener noreferrer">'.html_safe % { url: email_from_gitlab_path }
%ul
%li
= _('Email from GitLab - email users right from the Admin Area. %{link_start}Learn more%{link_end}.').html_safe % { link_start: email_from_gitlab_link, link_end: link_end }
= f.submit _('Save changes'), class: "gl-button btn btn-confirm"
# frozen_string_literal: true
class AddUsagePingFeaturesEnabledToApplicationSettings < ActiveRecord::Migration[6.1]
def up
add_column :application_settings, :usage_ping_features_enabled, :boolean, default: false, null: false
end
def down
remove_column :application_settings, :usage_ping_features_enabled
end
end
1a0df6210d9ee0e0229f3cdf3e95acaaa47ebf4ca31ac0fd9f57255115355f99
\ No newline at end of file
......@@ -9525,6 +9525,7 @@ CREATE TABLE application_settings (
encrypted_mailgun_signing_key bytea,
encrypted_mailgun_signing_key_iv bytea,
mailgun_events_enabled boolean DEFAULT false NOT NULL,
usage_ping_features_enabled boolean DEFAULT false NOT NULL,
CONSTRAINT app_settings_container_reg_cleanup_tags_max_list_size_positive CHECK ((container_registry_cleanup_tags_service_max_list_size >= 0)),
CONSTRAINT app_settings_ext_pipeline_validation_service_url_text_limit CHECK ((char_length(external_pipeline_validation_service_url) <= 255)),
CONSTRAINT app_settings_registry_exp_policies_worker_capacity_positive CHECK ((container_registry_expiration_policies_worker_capacity >= 0)),
......@@ -282,7 +282,7 @@ class License < ApplicationRecord
end
def features_with_usage_ping
return FEATURES_WITH_USAGE_PING if Gitlab::CurrentSettings.usage_ping_enabled?
return FEATURES_WITH_USAGE_PING if Gitlab::CurrentSettings.usage_ping_features_enabled?
[]
end
......
......@@ -31,7 +31,7 @@ RSpec.describe Admin::EmailsController, :clean_gitlab_redis_shared_state do
context 'when `send_emails_from_admin_area` feature is disabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(false)
stub_application_setting(usage_ping_enabled: false)
end
it 'returns 404' do
......@@ -44,10 +44,20 @@ RSpec.describe Admin::EmailsController, :clean_gitlab_redis_shared_state do
context 'when usage ping is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(true)
stub_application_setting(usage_ping_enabled: true)
end
it 'responds with 200' do
it 'responds 404 when feature is not activated' do
stub_application_setting(usage_ping_features_enabled: false)
subject
expect(response).to have_gitlab_http_status(:not_found)
end
it 'responds with 200 when feature is activated' do
stub_application_setting(usage_ping_features_enabled: true)
subject
expect(response).to have_gitlab_http_status(:ok)
......@@ -136,7 +146,7 @@ RSpec.describe Admin::EmailsController, :clean_gitlab_redis_shared_state do
context 'when `send_emails_from_admin_area` feature is disabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(false)
stub_application_setting(usage_ping_enabled: false)
end
it 'does not trigger the service to send emails' do
......@@ -155,23 +165,47 @@ RSpec.describe Admin::EmailsController, :clean_gitlab_redis_shared_state do
context 'when usage ping is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(true)
stub_application_setting(usage_ping_enabled: true)
end
it 'triggers the service to send emails' do
expect_next_instance_of(Admin::EmailService, recipients, email_subject, body) do |email_service|
expect(email_service).to receive(:execute)
context 'when feature is activated' do
before do
stub_application_setting(usage_ping_features_enabled: true)
end
subject
it 'triggers the service to send emails' do
expect_next_instance_of(Admin::EmailService, recipients, email_subject, body) do |email_service|
expect(email_service).to receive(:execute)
end
subject
end
it 'redirects to `admin_email_path` with success notice' do
subject
expect(response).to have_gitlab_http_status(:found)
expect(response).to redirect_to(admin_email_path)
expect(flash[:notice]).to eq('Email sent')
end
end
it 'redirects to `admin_email_path` with success notice' do
subject
context 'when feature is deactivated' do
before do
stub_application_setting(usage_ping_features_enabled: false)
end
expect(response).to have_gitlab_http_status(:found)
expect(response).to redirect_to(admin_email_path)
expect(flash[:notice]).to eq('Email sent')
it 'does not trigger the service to send emails' do
expect(Admin::EmailService).not_to receive(:new)
subject
end
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
end
......
......@@ -14,7 +14,7 @@ RSpec.describe 'Admin::Emails', :clean_gitlab_redis_shared_state do
context 'when `send_emails_from_admin_area` feature is not licensed' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(false)
stub_application_setting(usage_ping_enabled: false)
end
it 'returns 404' do
......@@ -27,13 +27,31 @@ RSpec.describe 'Admin::Emails', :clean_gitlab_redis_shared_state do
context 'when usage ping is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(true)
stub_application_setting(usage_ping_enabled: true)
end
it 'returns 200' do
visit admin_email_path
context 'when feature is activated' do
before do
stub_application_setting(usage_ping_features_enabled: true)
end
it 'returns 200' do
visit admin_email_path
expect(page.status_code).to eq(200)
end
end
context 'when feature is deactivated' do
before do
stub_application_setting(usage_ping_features_enabled: false)
end
expect(page.status_code).to eq(200)
it 'returns 404' do
visit admin_email_path
expect(page.status_code).to eq(404)
end
end
end
......
......@@ -28,7 +28,7 @@ RSpec.describe "Admin::Users", :js do
context 'when `send_emails_from_admin_area` feature is disabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(false)
stub_application_setting(usage_ping_enabled: false)
end
it "does not show the 'Send email to users' link" do
......@@ -41,13 +41,31 @@ RSpec.describe "Admin::Users", :js do
context 'when usage ping is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(true)
stub_application_setting(usage_ping_enabled: true)
end
it "shows the 'Send email to users' link" do
visit admin_users_path
context 'when feature is activated' do
before do
stub_application_setting(usage_ping_features_enabled: true)
end
expect(page).to have_link(href: admin_email_path)
it "shows the 'Send email to users' link" do
visit admin_users_path
expect(page).to have_link(href: admin_email_path)
end
end
context 'when feature is disabled' do
before do
stub_application_setting(usage_ping_features_enabled: false)
end
it "does not show the 'Send email to users' link" do
visit admin_users_path
expect(page).not_to have_link(href: admin_email_path)
end
end
end
end
......
......@@ -22,7 +22,7 @@ RSpec.describe Admin::EmailsHelper, :clean_gitlab_redis_shared_state do
context 'when `send_emails_from_admin_area` feature is disabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(false)
stub_application_setting(usage_ping_enabled: false)
end
it { is_expected.to be_falsey }
......@@ -31,11 +31,27 @@ RSpec.describe Admin::EmailsHelper, :clean_gitlab_redis_shared_state do
context 'when usage ping is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(true)
stub_application_setting(usage_ping_enabled: true)
end
it 'returns true' do
expect(subject).to eq(true)
context 'when feature is activated' do
before do
stub_application_setting(usage_ping_features_enabled: true)
end
it 'returns true' do
expect(subject).to eq(true)
end
end
context 'when feature is deactivated' do
before do
stub_application_setting(usage_ping_features_enabled: false)
end
it 'returns false' do
expect(subject).to eq(false)
end
end
end
end
......
......@@ -11809,6 +11809,9 @@ msgstr ""
msgid "Email display name"
msgstr ""
msgid "Email from GitLab - email users right from the Admin Area. %{link_start}Learn more%{link_end}."
msgstr ""
msgid "Email not verified. Please verify your email in Salesforce."
msgstr ""
......@@ -11950,6 +11953,9 @@ msgstr ""
msgid "Enable Pseudonymizer data collection"
msgstr ""
msgid "Enable Registration Features"
msgstr ""
msgid "Enable Repository Checks"
msgstr ""
......@@ -26845,6 +26851,9 @@ msgstr ""
msgid "Register with two-factor app"
msgstr ""
msgid "Registration Features include:"
msgstr ""
msgid "Registration|Checkout"
msgstr ""
......@@ -33913,6 +33922,9 @@ msgstr ""
msgid "To define internal users, first enable new users set to external"
msgstr ""
msgid "To enable Registration Features, make sure \"Enable service ping\" is checked."
msgstr ""
msgid "To ensure no loss of personal content, this account should only be used for matters related to %{group_name}."
msgstr ""
......@@ -37086,6 +37098,9 @@ msgstr ""
msgid "You can easily contribute to them by requesting to join these groups."
msgstr ""
msgid "You can enable Registration Features because Service Ping is enabled. To continue using Registration Features in future, you will also need to register with GitLab via a new cloud licensing service."
msgstr ""
msgid "You can enable project access token creation in %{link_start}group settings%{link_end}."
msgstr ""
......
......@@ -34,4 +34,12 @@ RSpec.describe Admin::ApplicationSettingsController, '(JavaScript fixtures)', ty
expect(response).to be_successful
end
it 'application_settings/usage.html' do
stub_application_setting(usage_ping_enabled: false)
get :metrics_and_profiling
expect(response).to be_successful
end
end
import initSetHelperText, {
HELPER_TEXT_USAGE_PING_DISABLED,
HELPER_TEXT_USAGE_PING_ENABLED,
} from '~/pages/admin/application_settings/metrics_and_profiling/usage_statistics';
describe('UsageStatistics', () => {
const FIXTURE = 'application_settings/usage.html';
let usagePingCheckBox;
let usagePingFeaturesCheckBox;
let usagePingFeaturesLabel;
let usagePingFeaturesHelperText;
beforeEach(() => {
loadFixtures(FIXTURE);
initSetHelperText();
usagePingCheckBox = document.getElementById('application_setting_usage_ping_enabled');
usagePingFeaturesCheckBox = document.getElementById(
'application_setting_usage_ping_features_enabled',
);
usagePingFeaturesLabel = document.getElementById('usage_ping_features_label');
usagePingFeaturesHelperText = document.getElementById('usage_ping_features_helper_text');
});
const expectEnabledUsagePingFeaturesCheckBox = () => {
expect(usagePingFeaturesCheckBox.classList.contains('gl-cursor-not-allowed')).toBe(false);
expect(usagePingFeaturesHelperText.textContent).toEqual(HELPER_TEXT_USAGE_PING_ENABLED);
};
const expectDisabledUsagePingFeaturesCheckBox = () => {
expect(usagePingFeaturesLabel.classList.contains('gl-cursor-not-allowed')).toBe(true);
expect(usagePingFeaturesHelperText.textContent).toEqual(HELPER_TEXT_USAGE_PING_DISABLED);
};
describe('Registration Features checkbox', () => {
it('is disabled when Usage Ping checkbox is unchecked', () => {
expect(usagePingCheckBox.checked).toBe(false);
expectDisabledUsagePingFeaturesCheckBox();
});
it('is enabled when Usage Ping checkbox is checked', () => {
usagePingCheckBox.click();
expect(usagePingCheckBox.checked).toBe(true);
expectEnabledUsagePingFeaturesCheckBox();
});
it('is switched to disabled when Usage Ping checkbox is unchecked ', () => {
usagePingCheckBox.click();
usagePingFeaturesCheckBox.click();
expectEnabledUsagePingFeaturesCheckBox();
usagePingCheckBox.click();
expect(usagePingCheckBox.checked).toBe(false);
expect(usagePingFeaturesCheckBox.checked).toBe(false);
expectDisabledUsagePingFeaturesCheckBox();
});
});
});
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