diff --git a/app/controllers/concerns/onboarding/status.rb b/app/controllers/concerns/onboarding/status.rb index ea4dc5501492b157b65c2e33ac3aba3ed2244a22..055d2aeff6b2904985c87a6a2e87b2fcf240bc76 100644 --- a/app/controllers/concerns/onboarding/status.rb +++ b/app/controllers/concerns/onboarding/status.rb @@ -2,6 +2,10 @@ module Onboarding class Status + def self.registration_path_params(params:, extra_params: {}) # rubocop:disable Lint/UnusedMethodArgument -- overridden in EE + {} + end + def initialize(params, session, user) @params = params @session = session diff --git a/app/controllers/omniauth_callbacks_controller.rb b/app/controllers/omniauth_callbacks_controller.rb index 58f51b222c5b76c6c3ac939805aaf3c097706172..26802eb6833a3d7f8721f686f40c1c370269f9f3 100644 --- a/app/controllers/omniauth_callbacks_controller.rb +++ b/app/controllers/omniauth_callbacks_controller.rb @@ -200,7 +200,7 @@ def build_auth_user(auth_user_class) end end - # Overrided in EE + # Overridden in EE def set_session_active_since(id); end def sign_in_user_flow(auth_user_class) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index e1d8a474e5a492eda1609b4d4748a16a80218253..fdb48376ddecc1608dcbafb9032514167c2b5978 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -28,7 +28,7 @@ class RegistrationsController < Devise::RegistrationsController feature_category :instance_resiliency - helper_method :arkose_labs_enabled?, :registration_path_params, :preregistration_tracking_label + helper_method :arkose_labs_enabled?, :preregistration_tracking_label def new @resource = build_resource @@ -156,11 +156,6 @@ def allow_flash_content?(user) user.blocked_pending_approval? || onboarding_status.single_invite? end - # overridden in EE - def registration_path_params - {} - end - def track_successful_user_creation(user) label = user_invited? ? 'invited' : 'signup' Gitlab::Tracking.event(self.class.name, 'create_user', label: label, user: user) diff --git a/app/helpers/registrations_helper.rb b/app/helpers/registrations_helper.rb index bdae6ad70da10fe0e2039fb26cd9e1cb8bb42de0..25372755f2c1788b397c079acf09e7c6994ef96f 100644 --- a/app/helpers/registrations_helper.rb +++ b/app/helpers/registrations_helper.rb @@ -10,11 +10,6 @@ def signup_username_data_attributes testid: 'new-user-username-field' } end - - # overridden in EE - def register_omniauth_params(_local_assigns) - {} - end end RegistrationsHelper.prepend_mod_with('RegistrationsHelper') diff --git a/app/views/devise/registrations/new.html.haml b/app/views/devise/registrations/new.html.haml index 8583840c35c15731d26082bed240ef338357bb38..c8636bacd5f4d70fe14fc42c8759d2e65c928d99 100644 --- a/app/views/devise/registrations/new.html.haml +++ b/app/views/devise/registrations/new.html.haml @@ -10,7 +10,7 @@ .signup-page .gl-mb-3.gl-p-4 = render 'signup_box_form', - url: registration_path(resource_name, registration_path_params), + url: registration_path(resource_name, ::Onboarding::Status.registration_path_params(params: params)), button_text: _('Continue') - if omniauth_enabled? && button_based_providers_enabled? @@ -20,7 +20,7 @@ .gl-flex.gl-flex-col.gl-gap-3 - enabled_button_based_providers.each do |provider| = render 'devise/shared/omniauth_provider_button', - href: omniauth_authorize_path(:user, provider, register_omniauth_params({})), + href: omniauth_authorize_path(:user, provider, ::Onboarding::Status.registration_path_params(params: params)), provider: provider, classes: 'js-track-omni-auth', data: { provider: provider, track_action: "#{provider}_sso", track_label: preregistration_tracking_label } diff --git a/ee/app/controllers/concerns/ee/onboarding/redirectable.rb b/ee/app/controllers/concerns/ee/onboarding/redirectable.rb index bdca5876999cd54517931bd516ed3a9da558dc53..a3e0d210fa172de57af94ff730b585e33c4e082b 100644 --- a/ee/app/controllers/concerns/ee/onboarding/redirectable.rb +++ b/ee/app/controllers/concerns/ee/onboarding/redirectable.rb @@ -13,6 +13,10 @@ def onboarding_first_step_path users_sign_up_welcome_path(onboarding_params) end + def onboarding_params + ::Onboarding::Status.glm_tracking_params(params) # rubocop:disable Rails/StrongParams -- strong params are used in the method being called + end + override :after_sign_up_path def after_sign_up_path if ::Onboarding.enabled? diff --git a/ee/app/controllers/concerns/ee/onboarding/status.rb b/ee/app/controllers/concerns/ee/onboarding/status.rb index c5c105227c866599080a67ee3c0ba39615cfc4ca..567de398de18921e6c5f68221c150352ef0d7620 100644 --- a/ee/app/controllers/concerns/ee/onboarding/status.rb +++ b/ee/app/controllers/concerns/ee/onboarding/status.rb @@ -10,6 +10,8 @@ module Status ::Onboarding::REGISTRATION_TYPE[:subscription] => ::Onboarding::SubscriptionRegistration }.freeze + GLM_PARAMS = [:glm_source, :glm_content].freeze + attr_reader :registration_type # string delegations @@ -23,6 +25,25 @@ module Status delegate :hide_setup_for_company_field?, :pre_parsed_email_opt_in?, to: :registration_type delegate :read_from_stored_user_location?, :preserve_stored_location?, to: :registration_type + module ClassMethods + extend ::Gitlab::Utils::Override + + def glm_tracking_params(params) + params.permit(*GLM_PARAMS) + end + + override :registration_path_params + def registration_path_params(params:, extra_params: {}) + return super unless ::Onboarding.enabled? + + glm_tracking_params(params).to_h.merge(extra_params) + end + end + + def self.prepended(base) + base.singleton_class.prepend(ClassMethods) + end + def initialize(*) super diff --git a/ee/app/controllers/concerns/gitlab_subscriptions/trials/duo_common.rb b/ee/app/controllers/concerns/gitlab_subscriptions/trials/duo_common.rb index e1ac01cfc1eb5e8d06139cb304029fc194b99cac..862c4befa902b9dde074832900b6a5bb5cd9d182 100644 --- a/ee/app/controllers/concerns/gitlab_subscriptions/trials/duo_common.rb +++ b/ee/app/controllers/concerns/gitlab_subscriptions/trials/duo_common.rb @@ -7,7 +7,6 @@ module DuoCommon include OneTrustCSP include GoogleAnalyticsCSP - include RegistrationsTracking include ::Gitlab::Utils::StrongMemoize include SafeFormatHelper @@ -43,8 +42,9 @@ def general_params def lead_params params.permit( + *::Onboarding::Status::GLM_PARAMS, :company_name, :company_size, :first_name, :last_name, :phone_number, - :country, :state, :website_url, :glm_content, :glm_source + :country, :state, :website_url ).to_h end diff --git a/ee/app/controllers/concerns/registrations_tracking.rb b/ee/app/controllers/concerns/registrations_tracking.rb deleted file mode 100644 index 24e242324498ce3e6d4ac456155a8b30848f17ad..0000000000000000000000000000000000000000 --- a/ee/app/controllers/concerns/registrations_tracking.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -module RegistrationsTracking - extend ActiveSupport::Concern - - included do - helper_method :glm_tracking_params - end - - private - - def glm_tracking_params - params.permit(:glm_source, :glm_content) - end - alias_method :onboarding_params, :glm_tracking_params -end - -RegistrationsTracking.prepend_mod diff --git a/ee/app/controllers/ee/registrations_controller.rb b/ee/app/controllers/ee/registrations_controller.rb index 53784a97402278820f5eebb53bb67d22ff0183a1..4105364b2ac16083f5096e7b245376b4da33d7de 100644 --- a/ee/app/controllers/ee/registrations_controller.rb +++ b/ee/app/controllers/ee/registrations_controller.rb @@ -11,7 +11,6 @@ module RegistrationsController prepended do include Arkose::ContentSecurityPolicy include Arkose::TokenVerifiable - include RegistrationsTracking include GoogleAnalyticsCSP include GoogleSyndicationCSP @@ -171,11 +170,6 @@ def log_audit_event(user) }) end - override :registration_path_params - def registration_path_params - glm_tracking_params.to_h - end - def record_arkose_data(user) return unless arkose_labs_enabled?(user: user) return unless arkose_labs_verify_response diff --git a/ee/app/controllers/gitlab_subscriptions/trials/duo_enterprise_controller.rb b/ee/app/controllers/gitlab_subscriptions/trials/duo_enterprise_controller.rb index 917fbd703e69baf25be37698d3f3acca2e5fec46..2ccaba360b4ad4a72c0372b4dbc54599ff85cb9e 100644 --- a/ee/app/controllers/gitlab_subscriptions/trials/duo_enterprise_controller.rb +++ b/ee/app/controllers/gitlab_subscriptions/trials/duo_enterprise_controller.rb @@ -76,7 +76,7 @@ def track_event(action) end def trial_params - params.permit(:namespace_id, :glm_source, :glm_content).to_h + params.permit(*::Onboarding::Status::GLM_PARAMS, :namespace_id).to_h end def success_flash_message diff --git a/ee/app/controllers/gitlab_subscriptions/trials/duo_pro_controller.rb b/ee/app/controllers/gitlab_subscriptions/trials/duo_pro_controller.rb index cda94c17d0da7e41082ab8b190c51b7e2b3184b2..c2e65b44e9e76b1dd88e2d26d822f7af299665e0 100644 --- a/ee/app/controllers/gitlab_subscriptions/trials/duo_pro_controller.rb +++ b/ee/app/controllers/gitlab_subscriptions/trials/duo_pro_controller.rb @@ -65,7 +65,7 @@ def track_event(action) end def trial_params - params.permit(:namespace_id, :trial_entity, :glm_source, :glm_content).to_h + params.permit(*::Onboarding::Status::GLM_PARAMS, :namespace_id, :trial_entity).to_h end def success_flash_message diff --git a/ee/app/controllers/gitlab_subscriptions/trials_controller.rb b/ee/app/controllers/gitlab_subscriptions/trials_controller.rb index 45387132ee004e12c1c0f881d2c24591ec8fdec3..237db2c3fb7010067224ba1e23363b9ca9432723 100644 --- a/ee/app/controllers/gitlab_subscriptions/trials_controller.rb +++ b/ee/app/controllers/gitlab_subscriptions/trials_controller.rb @@ -5,7 +5,6 @@ module GitlabSubscriptions class TrialsController < ApplicationController include OneTrustCSP include GoogleAnalyticsCSP - include RegistrationsTracking layout 'minimal' @@ -74,18 +73,22 @@ def stored_location_or_provided_path(path) def authenticate_user! return if current_user - redirect_to new_trial_registration_path(glm_tracking_params), alert: I18n.t('devise.failure.unauthenticated') + redirect_to( + new_trial_registration_path(::Onboarding::Status.glm_tracking_params(params)), + alert: I18n.t('devise.failure.unauthenticated') + ) end def lead_params params.permit( + *::Onboarding::Status::GLM_PARAMS, :company_name, :company_size, :first_name, :last_name, :phone_number, - :country, :state, :website_url, :glm_content, :glm_source + :country, :state, :website_url ).to_h end def trial_params - params.permit(:new_group_name, :namespace_id, :trial_entity, :glm_source, :glm_content) + params.permit(*::Onboarding::Status::GLM_PARAMS, :new_group_name, :namespace_id, :trial_entity) .with_defaults(organization_id: Current.organization_id).to_h end diff --git a/ee/app/controllers/registrations/company_controller.rb b/ee/app/controllers/registrations/company_controller.rb index 6aef178373f8dafb99ea2c7e782b34811b1630fd..09e17f980c1a08edd33d76bb1f3e8efd967489a9 100644 --- a/ee/app/controllers/registrations/company_controller.rb +++ b/ee/app/controllers/registrations/company_controller.rb @@ -5,7 +5,6 @@ class CompanyController < ApplicationController include OneTrustCSP include GoogleAnalyticsCSP include GoogleSyndicationCSP - include RegistrationsTracking include ::Onboarding::SetRedirect layout 'minimal' @@ -26,8 +25,9 @@ def create if result.success? track_event('successfully_submitted_form') - response = Onboarding::StatusStepUpdateService - .new(current_user, new_users_sign_up_group_path(glm_tracking_params)).execute + response = Onboarding::StatusStepUpdateService.new( + current_user, new_users_sign_up_group_path(::Onboarding::Status.glm_tracking_params(params)) + ).execute redirect_to response[:step_url] else @@ -40,6 +40,7 @@ def create def permitted_params params.permit( + *::Onboarding::Status::GLM_PARAMS, :company_name, :company_size, :first_name, @@ -52,7 +53,7 @@ def permitted_params :role, :registration_objective, :jobs_to_be_done_other - ).merge(glm_tracking_params) + ) end def track_event(action) diff --git a/ee/app/controllers/registrations/groups_controller.rb b/ee/app/controllers/registrations/groups_controller.rb index 63de4ee7e3e040036cde72236af7ca3cadc09b53..931e65f78acae5634e07bb8a685d290f2c1275d4 100644 --- a/ee/app/controllers/registrations/groups_controller.rb +++ b/ee/app/controllers/registrations/groups_controller.rb @@ -159,11 +159,11 @@ def project_params end def general_params - params.permit(:import_url).merge(glm_params) + params.permit(*::Onboarding::Status::GLM_PARAMS, :import_url) end def glm_params - params.permit(:glm_source, :glm_content) + ::Onboarding::Status.glm_tracking_params(params) # rubocop:disable Rails/StrongParams -- strong params are used in the method being called. end end end diff --git a/ee/app/controllers/registrations/welcome_controller.rb b/ee/app/controllers/registrations/welcome_controller.rb index df93258de00375f346128f1eb3fb4906193d2c90..b74bf4e37c679a53e21e316790395e0030411b73 100644 --- a/ee/app/controllers/registrations/welcome_controller.rb +++ b/ee/app/controllers/registrations/welcome_controller.rb @@ -8,7 +8,6 @@ class WelcomeController < ApplicationController include ::Gitlab::Utils::StrongMemoize include ::Onboarding::Redirectable include ::Onboarding::SetRedirect - include RegistrationsTracking layout 'minimal' @@ -76,7 +75,7 @@ def onboarding_status_params def passed_through_params update_params.slice(:role, :registration_objective) .merge(params.permit(:jobs_to_be_done_other)) - .merge(glm_tracking_params) + .merge(::Onboarding::Status.glm_tracking_params(params)) end def iterable_params diff --git a/ee/app/helpers/ee/registrations_helper.rb b/ee/app/helpers/ee/registrations_helper.rb index d784a60b791cf591c2a0107d2e3ad19a56417798..b047553353c94808f9a6dff84fcb0957218cb63c 100644 --- a/ee/app/helpers/ee/registrations_helper.rb +++ b/ee/app/helpers/ee/registrations_helper.rb @@ -21,11 +21,6 @@ def arkose_labs_data data.compact end - override :register_omniauth_params - def register_omniauth_params(local_assigns) - super.merge(glm_tracking_params.to_h).merge(local_assigns.slice(:trial)) - end - def unconfirmed_email_feature_enabled? ::Gitlab::CurrentSettings.delete_unconfirmed_users? && (::Gitlab::CurrentSettings.email_confirmation_setting_soft? || diff --git a/ee/app/helpers/gitlab_subscriptions/trials_helper.rb b/ee/app/helpers/gitlab_subscriptions/trials_helper.rb index a8af5837ef70a1460d9c29a2e089d60fdc714fac..4a6751c0d24bd2e497c9b14a9eb1ac9090a44363 100644 --- a/ee/app/helpers/gitlab_subscriptions/trials_helper.rb +++ b/ee/app/helpers/gitlab_subscriptions/trials_helper.rb @@ -49,7 +49,7 @@ def should_ask_company_question? def glm_params strong_memoize(:glm_params) do - params.slice(:glm_source, :glm_content).to_unsafe_h + params.slice(*::Onboarding::Status::GLM_PARAMS).to_unsafe_h end end diff --git a/ee/app/services/gitlab_subscriptions/trials/base_create_service.rb b/ee/app/services/gitlab_subscriptions/trials/base_create_service.rb index a24c5e25bc7784be4bd85ea5f2a9ca4a442e0cac..462d158f25d593dbee51b3593f8585cc6aad447d 100644 --- a/ee/app/services/gitlab_subscriptions/trials/base_create_service.rb +++ b/ee/app/services/gitlab_subscriptions/trials/base_create_service.rb @@ -53,7 +53,7 @@ def after_lead_success_hook # trigger new creation for next step... trial_selection_params = { step: TRIAL - }.merge(lead_params.slice(:glm_content, :glm_source)) + }.merge(lead_params.slice(*::Onboarding::Status::GLM_PARAMS)) .merge(trial_params.slice(:namespace_id)) ServiceResponse.error( diff --git a/ee/app/views/registrations/groups/new.html.haml b/ee/app/views/registrations/groups/new.html.haml index 85c3f5eae993f3d331e9bc4b0273762ad3ca2385..391e45e5442419559abf16c020ba83d279c82f02 100644 --- a/ee/app/views/registrations/groups/new.html.haml +++ b/ee/app/views/registrations/groups/new.html.haml @@ -1,7 +1,6 @@ - @html_class = "subscriptions-layout-html" - @hide_flash = true - page_title _('Your GitLab group') -- form_params = { glm_source: params[:glm_source], glm_content: params[:glm_content] } - content_for :page_specific_javascripts do = render "layouts/google_tag_manager_head" = render "layouts/one_trust" @@ -29,7 +28,7 @@ .tab-content.gitlab-tab-content.gl-bg-white.js-group-project-tab-contents #blank-project-pane.tab-pane.js-toggle-container.active{ role: 'tabpanel' } - = gitlab_ui_form_for :project_group, url: users_sign_up_groups_path(form_params), html: { class: 'gl-show-field-errors gl-w-full gl-p-4 js-groups-projects-form' } do |f| + = gitlab_ui_form_for :project_group, url: users_sign_up_groups_path(::Onboarding::Status.glm_tracking_params(params)), html: { class: 'gl-show-field-errors gl-w-full gl-p-4 js-groups-projects-form' } do |f| = form_errors(@group, type: "Group") = form_errors(@project, type: "Project") = render 'layouts/flash' @@ -50,7 +49,7 @@ #import-project-pane.tab-pane.import-project-pane.js-toggle-container{ role: 'tabpanel' } - if import_sources_enabled? - = form_tag users_sign_up_groups_path(form_params), class: 'gl-show-field-errors gl-w-full gl-p-4 js-import-project-form' do + = form_tag users_sign_up_groups_path(::Onboarding::Status.glm_tracking_params(params)), class: 'gl-show-field-errors gl-w-full gl-p-4 js-import-project-form' do = form_errors(@group, type: "Group") = render 'layouts/flash' diff --git a/ee/app/views/registrations/welcome/show.html.haml b/ee/app/views/registrations/welcome/show.html.haml index 8e195992caf3ae8790586f3946af11647158e003..63c649434778085bc2af8611b48d37afd0dec841 100644 --- a/ee/app/views/registrations/welcome/show.html.haml +++ b/ee/app/views/registrations/welcome/show.html.haml @@ -14,7 +14,7 @@ %p.gl-text-center = _('To personalize your GitLab experience, we\'d like to know a bit more about you. We won\'t share this information with anyone.') = gitlab_ui_form_for(current_user, - url: users_sign_up_welcome_path(glm_tracking_params.merge(params.permit(:trial))), + url: users_sign_up_welcome_path(::Onboarding::Status.glm_tracking_params(params)), html: { class: '!gl-w-full gl-p-5 js-users-signup-welcome', 'aria-live' => 'assertive', data: { testid: 'welcome-form' } }) do |f| diff --git a/ee/app/views/trial_registrations/new.html.haml b/ee/app/views/trial_registrations/new.html.haml index 9bfc17f42014376c0621139f71dece90c88d8691..6ff1075207bb44fa2632b4c139ada30fd3211dfc 100644 --- a/ee/app/views/trial_registrations/new.html.haml +++ b/ee/app/views/trial_registrations/new.html.haml @@ -31,7 +31,7 @@ .signup-box.gl-max-w-75 .gl-mb-3.gl-p-6.gl-border-gray-100.gl-border-1.gl-border-solid.gl-rounded-base.gl-bg-white = render 'signup_box_form', - url: trial_registrations_path(glm_tracking_params), + url: trial_registrations_path(::Onboarding::Status.glm_tracking_params(params)), button_text: _('Continue'), button_class: 'black-btn' @@ -44,7 +44,7 @@ .gl-flex.gl-gap-3.gl-justify-center - popular_enabled_button_based_providers.each do |provider| = render 'devise/shared/omniauth_provider_button', - href: omniauth_authorize_path(:user, provider, register_omniauth_params(trial: true)), + href: omniauth_authorize_path(:user, provider, ::Onboarding::Status.registration_path_params(params: params, extra_params: { trial: true })), provider: provider, classes: 'js-track-omni-auth', data: { provider: provider, track_action: "#{provider}_sso", track_label: preregistration_tracking_label } diff --git a/ee/spec/controllers/concerns/ee/onboarding/status_spec.rb b/ee/spec/controllers/concerns/ee/onboarding/status_spec.rb index cfa52f629706f8660c50dd193ccacd3ebce73fc8..fa1689cfb9450a046fee865aeb171935bdbf0f30 100644 --- a/ee/spec/controllers/concerns/ee/onboarding/status_spec.rb +++ b/ee/spec/controllers/concerns/ee/onboarding/status_spec.rb @@ -26,6 +26,52 @@ it { is_expected.to delegate_method(:preserve_stored_location?).to(:registration_type) } end + describe '.glm_tracking_params' do + let(:params) { ActionController::Parameters.new(glm_source: 'source', glm_content: 'content', extra: 'param') } + + subject { described_class.glm_tracking_params(params) } + + it { is_expected.to eq(params.slice(:glm_source, :glm_content).permit!) } + end + + describe '.registration_path_params' do + let(:params) { ActionController::Parameters.new(glm_source: 'source', glm_content: 'content', extra: 'param') } + let(:extra_params) { { another_extra: 'param' } } + let(:onboarding_enabled) { true } + + before do + stub_saas_features(onboarding: onboarding_enabled) + end + + subject { described_class.registration_path_params(params: params) } + + context 'when onboarding is enabled' do + let(:expected_params) { { glm_source: 'source', glm_content: 'content' } } + + it { is_expected.to eq(expected_params.stringify_keys) } + + context 'when extra params are passed' do + let(:combined_params) { expected_params.merge(extra_params).stringify_keys } + + subject { described_class.registration_path_params(params: params, extra_params: extra_params) } + + it { is_expected.to eq(combined_params) } + end + end + + context 'when onboarding is disabled' do + let(:onboarding_enabled) { false } + + it { is_expected.to eq({}) } + + context 'when extra params are passed' do + subject { described_class.registration_path_params(params: params, extra_params: extra_params) } + + it { is_expected.to eq({}) } + end + end + end + describe '#continue_full_onboarding?' do let(:session_in_oauth) do { 'user_return_to' => ::Gitlab::Routing.url_helpers.oauth_authorization_path(some_param: '_param_') } diff --git a/ee/spec/helpers/ee/registrations_helper_spec.rb b/ee/spec/helpers/ee/registrations_helper_spec.rb index a5f42ffb12aee0a6073a7ed674ff8e67a2fba88a..bfa8289ded00a50726023b202ae321b1e1909775 100644 --- a/ee/spec/helpers/ee/registrations_helper_spec.rb +++ b/ee/spec/helpers/ee/registrations_helper_spec.rb @@ -70,28 +70,4 @@ end end end - - describe '#register_omniauth_params' do - let(:result) do - { - glm_source: '_glm_source_', - glm_content: '_glm_content_' - } - end - - before do - allow(helper) - .to receive(:glm_tracking_params).and_return({ glm_source: '_glm_source_', glm_content: '_glm_content_' }) - end - - it 'adds intent to register with glm params' do - expect(helper.register_omniauth_params({})).to eq(result) - end - - context 'when trial param exists' do - it 'adds intent to register with glm params and trial' do - expect(helper.register_omniauth_params({ trial: true })).to eq(result.merge(trial: true)) - end - end - end end diff --git a/ee/spec/views/devise/registrations/new.html.haml_spec.rb b/ee/spec/views/devise/registrations/new.html.haml_spec.rb index 35210da8a5b3954912b7a91df577274f2c569e71..d51d8692730546ad29261e89354043c86680b6cd 100644 --- a/ee/spec/views/devise/registrations/new.html.haml_spec.rb +++ b/ee/spec/views/devise/registrations/new.html.haml_spec.rb @@ -13,9 +13,7 @@ before do allow(view).to receive(:resource).and_return(resource) allow(view).to receive(:resource_name).and_return(:user) - allow(view).to receive(:registration_path_params).and_return({}) - allow(view).to receive(:glm_tracking_params).and_return({}) allow(view).to receive(:arkose_labs_enabled?).and_return(arkose_labs_enabled) allow(view).to receive(:preregistration_tracking_label).and_return('free_registration') allow(::Arkose::Settings).to receive(:arkose_public_api_key).and_return(arkose_labs_api_key) @@ -33,4 +31,37 @@ it { is_expected.not_to have_selector("[data-api-key='#{arkose_labs_api_key}']") } it { is_expected.not_to have_selector("[data-domain='#{arkose_labs_domain}']") } end + + context 'for password form' do + before do + controller.params[:glm_content] = '_glm_content_' + controller.params[:glm_source] = '_glm_source_' + stub_saas_features(onboarding: true) + end + + it { is_expected.to have_css('form[action="/users?glm_content=_glm_content_&glm_source=_glm_source_"]') } + end + + context 'for omniauth provider buttons' do + # add action path for non omniauth too + before do + allow(view).to receive(:providers).and_return([:github, :google_oauth2]) + end + + it { is_expected.to have_css('form[action="/users/auth/github"]') } + it { is_expected.to have_css('form[action="/users/auth/google_oauth2"]') } + + context 'when saas onboarding feature is available' do + let(:action_params) { 'glm_content=_glm_content_&glm_source=_glm_source_' } + + before do + controller.params[:glm_content] = '_glm_content_' + controller.params[:glm_source] = '_glm_source_' + stub_saas_features(onboarding: true) + end + + it { is_expected.to have_css("form[action='/users/auth/github?#{action_params}']") } + it { is_expected.to have_css("form[action='/users/auth/google_oauth2?#{action_params}']") } + end + end end diff --git a/ee/spec/views/registrations/groups/new.html.haml_spec.rb b/ee/spec/views/registrations/groups/new.html.haml_spec.rb index 28848e9090c4de96bcafbc694ca77284920003a8..5622f61cd0156e539b54da64a8ea6d78f01478f2 100644 --- a/ee/spec/views/registrations/groups/new.html.haml_spec.rb +++ b/ee/spec/views/registrations/groups/new.html.haml_spec.rb @@ -48,6 +48,19 @@ end end + context 'for form action path' do + before do + controller.params[:glm_content] = '_glm_content_' + controller.params[:glm_source] = '_glm_source_' + end + + subject { render && rendered } + + it do + is_expected.to have_css('form[action="/users/sign_up/groups?glm_content=_glm_content_&glm_source=_glm_source_"]') + end + end + context 'with expected DOM elements' do it 'contains js-groups-projects-form class' do render diff --git a/ee/spec/views/registrations/welcome/show.html.haml_spec.rb b/ee/spec/views/registrations/welcome/show.html.haml_spec.rb index 357c65e7633895c8dc92f56f862bdeca8ae17d5d..2da388ef5c340afff37500d2389c722693cf189c 100644 --- a/ee/spec/views/registrations/welcome/show.html.haml_spec.rb +++ b/ee/spec/views/registrations/welcome/show.html.haml_spec.rb @@ -21,7 +21,8 @@ before do allow(view).to receive(:onboarding_status).and_return(onboarding_status) allow(view).to receive(:current_user).and_return(build_stubbed(:user)) - allow(view).to receive(:glm_tracking_params).and_return({}) + controller.params[:glm_content] = '_glm_content_' + controller.params[:glm_source] = '_glm_source_' render end @@ -29,6 +30,10 @@ subject { rendered } context 'with basic form items' do + it do + is_expected.to have_css('form[action="/users/sign_up/welcome?glm_content=_glm_content_&glm_source=_glm_source_"]') + end + it 'the text for the :setup_for_company label' do is_expected.to have_selector('label[for="user_setup_for_company"]', text: '_text_') end diff --git a/ee/spec/views/trial_registrations/new.html.haml_spec.rb b/ee/spec/views/trial_registrations/new.html.haml_spec.rb index 471c54f8c8ce91a55f07d32cb534d3b38d9d4831..53c2debf69ad6e6166d6782ba857d426573798f8 100644 --- a/ee/spec/views/trial_registrations/new.html.haml_spec.rb +++ b/ee/spec/views/trial_registrations/new.html.haml_spec.rb @@ -9,7 +9,6 @@ allow(view).to receive(:arkose_labs_enabled?).and_return(false) allow(view).to receive(:resource).and_return(resource) allow(view).to receive(:resource_name).and_return(:user) - allow(view).to receive(:glm_tracking_params).and_return({}) allow(view).to receive(:preregistration_tracking_label).and_return('trial_registration') view.lookup_context.prefixes << 'devise/registrations' end @@ -31,4 +30,32 @@ it { is_expected.to have_content(s_('InProductMarketing|Free 30-day trial GitLab Ultimate')) } it { is_expected.to have_content(s_('InProductMarketing|Accelerate your digital transformation')) } end + + context 'for password form' do + before do + allow(view).to receive(:social_signin_enabled?).and_return(true) + controller.params[:glm_content] = '_glm_content_' + controller.params[:glm_source] = '_glm_source_' + stub_saas_features(onboarding: true) + end + + it do + is_expected.to have_css('form[action="/-/trial_registrations?glm_content=_glm_content_&glm_source=_glm_source_"]') + end + end + + context 'for omniauth provider buttons' do + let(:action_params) { 'glm_content=_glm_content_&glm_source=_glm_source_&trial=true' } + + before do + allow(view).to receive(:social_signin_enabled?).and_return(true) + allow(view).to receive(:popular_enabled_button_based_providers).and_return([:github, :google_oauth2]) + controller.params[:glm_content] = '_glm_content_' + controller.params[:glm_source] = '_glm_source_' + stub_saas_features(onboarding: true) # for trials this view it isn't reachable in the false case + end + + it { is_expected.to have_css("form[action='/users/auth/github?#{action_params}']") } + it { is_expected.to have_css("form[action='/users/auth/google_oauth2?#{action_params}']") } + end end diff --git a/spec/controllers/concerns/onboarding/status_spec.rb b/spec/controllers/concerns/onboarding/status_spec.rb index 6fcbd059947f908209030908f9da7b3eec7efd45..11b4b85afe336c241a2db3d5c624820c5b697782 100644 --- a/spec/controllers/concerns/onboarding/status_spec.rb +++ b/spec/controllers/concerns/onboarding/status_spec.rb @@ -7,6 +7,21 @@ let_it_be(:user) { member.user } let_it_be(:source) { member.group } + describe '.registration_path_params' do + let(:params) { { some: 'thing' } } + let(:extra_params) { { another_extra: 'param' } } + + subject { described_class.registration_path_params(params: params) } + + it { is_expected.to eq({}) } + + context 'when extra params are passed' do + subject { described_class.registration_path_params(params: params, extra_params: extra_params) } + + it { is_expected.to eq({}) } + end + end + describe '#single_invite?' do subject { described_class.new(nil, nil, user).single_invite? } diff --git a/spec/helpers/registrations_helper_spec.rb b/spec/helpers/registrations_helper_spec.rb index 74d46245cc2cd430e68b3c1ff1edbf80e02b06ed..fb7f6d14dd744309f40cc70f90ff3dc41668ae21 100644 --- a/spec/helpers/registrations_helper_spec.rb +++ b/spec/helpers/registrations_helper_spec.rb @@ -8,12 +8,4 @@ expect(helper.signup_username_data_attributes.keys).to include(:min_length, :min_length_message, :max_length, :max_length_message, :testid) end end - - describe '#register_omniauth_params' do - it 'adds intent to register' do - allow(helper).to receive(:glm_tracking_params).and_return({}) - - expect(helper.register_omniauth_params({})).to eq({}) - end - end end diff --git a/spec/views/devise/registrations/new.html.haml_spec.rb b/spec/views/devise/registrations/new.html.haml_spec.rb index 0961da8d1cdc15f89869f3e32edd057b8b604c16..85ebf626e7bac928bb7b5ff14390c9184a5d7518 100644 --- a/spec/views/devise/registrations/new.html.haml_spec.rb +++ b/spec/views/devise/registrations/new.html.haml_spec.rb @@ -11,12 +11,14 @@ before do allow(view).to receive(:resource).and_return(resource) allow(view).to receive(:resource_name).and_return(:user) - allow(view).to receive(:glm_tracking_params).and_return({}) - allow(view).to receive(:registration_path_params).and_return({}) allow(view).to receive(:preregistration_tracking_label).and_return(tracking_label) allow(view).to receive(:arkose_labs_enabled?) end + context 'for password form' do + it { is_expected.to have_css('form[action="/users"]') } + end + context 'for omniauth provider buttons' do let(:provider_label) { :github } let(:tracking_action) { "#{provider_label}_sso" }