diff options
Diffstat (limited to 'app/controllers/invites_controller.rb')
-rw-r--r-- | app/controllers/invites_controller.rb | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb index 0eb08d2d0ad..0a9a9e03e94 100644 --- a/app/controllers/invites_controller.rb +++ b/app/controllers/invites_controller.rb @@ -3,10 +3,10 @@ class InvitesController < ApplicationController include Gitlab::Utils::StrongMemoize + prepend_before_action :authenticate_user!, :track_invite_join_click, only: :show before_action :member before_action :ensure_member_exists before_action :invite_details - before_action :set_invite_type, only: :show skip_before_action :authenticate_user!, only: :decline helper_method :member?, :current_user_matches_invite? @@ -16,18 +16,12 @@ class InvitesController < ApplicationController feature_category :authentication_and_authorization def show - experiment('members/invite_email', actor: member).track(:opened) if initial_invite_email? - accept if skip_invitation_prompt? end def accept if member.accept_invite!(current_user) - experiment('members/invite_email', actor: member).track(:accepted) if initial_invite_email? - session.delete(:invite_type) - - redirect_to invite_details[:path], notice: _("You have been granted %{member_human_access} access to %{title} %{name}.") % - { member_human_access: member.human_access, title: invite_details[:title], name: invite_details[:name] } + redirect_to invite_details[:path], notice: helpers.invite_accepted_notice(member) else redirect_back_or_default(options: { alert: _("The invitation could not be accepted.") }) end @@ -53,14 +47,6 @@ class InvitesController < ApplicationController private - def set_invite_type - session[:invite_type] = params[:invite_type] if params[:invite_type].in?([Members::InviteEmailExperiment::INVITE_TYPE]) - end - - def initial_invite_email? - session[:invite_type] == Members::InviteEmailExperiment::INVITE_TYPE - end - def skip_invitation_prompt? !member? && current_user_matches_invite? end @@ -85,21 +71,48 @@ class InvitesController < ApplicationController def ensure_member_exists return if member - render_404 + redirect_back_or_default(options: { alert: _("The invitation can not be found with the provided invite token.") }) + end + + def track_invite_join_click + experiment('members/invite_email', actor: member).track(:join_clicked) if member && Members::InviteEmailExperiment.initial_invite_email?(params[:invite_type]) end def authenticate_user! return if current_user - store_location_for :user, request.fullpath + store_location_for(:user, invite_landing_url) if member if user_sign_up? - redirect_to new_user_registration_path(invite_email: member.invite_email), notice: _("To accept this invitation, create an account or sign in.") + set_session_invite_params + + experiment(:invite_signup_page_interaction, actor: member) do |experiment_instance| + set_originating_member_id if experiment_instance.enabled? + + experiment_instance.use do + redirect_to new_user_registration_path(invite_email: member.invite_email), notice: _("To accept this invitation, create an account or sign in.") + end + experiment_instance.try do + redirect_to new_users_sign_up_invite_path(invite_email: member.invite_email) + end + + experiment_instance.track(:view) + end else redirect_to new_user_session_path(sign_in_redirect_params), notice: sign_in_notice end end + def set_session_invite_params + session[:invite_email] = member.invite_email + + set_originating_member_id if Members::InviteEmailExperiment.initial_invite_email?(params[:invite_type]) + end + + def set_originating_member_id + session[:originating_member_id] = member.id + end + def sign_in_redirect_params member ? { invite_email: member.invite_email } : {} end @@ -116,6 +129,10 @@ class InvitesController < ApplicationController end end + def invite_landing_url + root_url + invite_details[:path] + end + def invite_details @invite_details ||= case member.source when Project @@ -123,14 +140,14 @@ class InvitesController < ApplicationController name: member.source.full_name, url: project_url(member.source), title: _("project"), - path: project_path(member.source) + path: member.source.activity_path } when Group { name: member.source.name, url: group_url(member.source), title: _("group"), - path: group_path(member.source) + path: member.source.activity_path } end end |