diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-19 00:06:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-19 00:06:37 +0300 |
commit | 4682f5015a5a2d7eedb66b3c90aee931d3789d0b (patch) | |
tree | 6240a8a5cf3584a893c6c3351141446e7856dc12 /app/controllers/registrations_controller.rb | |
parent | 6d59e989185a7d2645792b713d1b5d95d46651fd (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/controllers/registrations_controller.rb')
-rw-r--r-- | app/controllers/registrations_controller.rb | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 3a2975e92d6..4a746fc915d 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -8,13 +8,14 @@ class RegistrationsController < Devise::RegistrationsController layout :choose_layout + skip_before_action :require_role, only: [:welcome, :update_role] prepend_before_action :check_captcha, only: :create before_action :whitelist_query_limiting, only: [:destroy] before_action :ensure_terms_accepted, if: -> { action_name == 'create' && Gitlab::CurrentSettings.current_application_settings.enforce_terms? } def new - if helpers.use_experimental_separate_sign_up_flow? + if experiment_enabled?(:signup_flow) @resource = build_resource else redirect_to new_user_session_path(anchor: 'register-pane') @@ -26,8 +27,13 @@ class RegistrationsController < Devise::RegistrationsController super do |new_user| persist_accepted_terms_if_required(new_user) + set_role_required(new_user) yield new_user if block_given? end + + # Do not show the signed_up notice message when the signup_flow experiment is enabled. + # Instead, show it after succesfully updating the role. + flash[:notice] = nil if experiment_enabled?(:signup_flow) rescue Gitlab::Access::AccessDeniedError redirect_to(new_user_session_path) end @@ -42,6 +48,26 @@ class RegistrationsController < Devise::RegistrationsController end end + def welcome + return redirect_to new_user_registration_path unless current_user + return redirect_to stored_location_or_dashboard_or_almost_there_path(current_user) if current_user.role.present? + + current_user.name = nil + render layout: 'devise_experimental_separate_sign_up_flow' + end + + def update_role + user_params = params.require(:user).permit(:name, :role) + result = ::Users::UpdateService.new(current_user, user_params.merge(user: current_user)).execute + + if result[:status] == :success + set_flash_message! :notice, :signed_up + redirect_to stored_location_or_dashboard_or_almost_there_path(current_user) + else + redirect_to users_sign_up_welcome_path, alert: result[:message] + end + end + protected def persist_accepted_terms_if_required(new_user) @@ -54,6 +80,10 @@ class RegistrationsController < Devise::RegistrationsController end end + def set_role_required(new_user) + new_user.set_role_required! if new_user.persisted? && experiment_enabled?(:signup_flow) + end + def destroy_confirmation_valid? if current_user.confirm_deletion_with_password? current_user.valid_password?(params[:password]) @@ -76,7 +106,10 @@ class RegistrationsController < Devise::RegistrationsController def after_sign_up_path_for(user) Gitlab::AppLogger.info(user_created_message(confirmed: user.confirmed?)) - confirmed_or_unconfirmed_access_allowed(user) ? stored_location_or_dashboard(user) : users_almost_there_path + + return users_sign_up_welcome_path if experiment_enabled?(:signup_flow) + + stored_location_or_dashboard_or_almost_there_path(user) end def after_inactive_sign_up_path_for(resource) @@ -103,6 +136,7 @@ class RegistrationsController < Devise::RegistrationsController ensure_correct_params! return unless Feature.enabled?(:registrations_recaptcha, default_enabled: true) # reCAPTCHA on the UI will still display however + return if experiment_enabled?(:signup_flow) # when the experimental signup flow is enabled for the current user, disable the reCAPTCHA check return unless show_recaptcha_sign_up? return unless Gitlab::Recaptcha.load_configurations! @@ -114,7 +148,13 @@ class RegistrationsController < Devise::RegistrationsController end def sign_up_params - params.require(:user).permit(:username, :email, :email_confirmation, :name, :password) + clean_params = params.require(:user).permit(:username, :email, :email_confirmation, :name, :password) + + if experiment_enabled?(:signup_flow) + clean_params[:name] = clean_params[:username] + end + + clean_params end def resource_name @@ -144,17 +184,21 @@ class RegistrationsController < Devise::RegistrationsController end def confirmed_or_unconfirmed_access_allowed(user) - user.confirmed? || Feature.enabled?(:soft_email_confirmation) + user.confirmed? || Feature.enabled?(:soft_email_confirmation) || experiment_enabled?(:signup_flow) end def stored_location_or_dashboard(user) stored_location_for(user) || dashboard_projects_path end + def stored_location_or_dashboard_or_almost_there_path(user) + confirmed_or_unconfirmed_access_allowed(user) ? stored_location_or_dashboard(user) : users_almost_there_path + end + # Part of an experiment to build a new sign up flow. Will be resolved # with https://gitlab.com/gitlab-org/growth/engineering/issues/64 def choose_layout - if helpers.use_experimental_separate_sign_up_flow? + if experiment_enabled?(:signup_flow) 'devise_experimental_separate_sign_up_flow' else 'devise' |