Commit 99fd82cc authored by Alper Akgun's avatar Alper Akgun Committed by Peter Leitzen

Create hand raise controller endpoint

parent c7c495a0
......@@ -8,9 +8,10 @@ class TrialsController < ApplicationController
layout 'minimal'
before_action :check_if_gl_com_or_dev
before_action :authenticate_user!
before_action :authenticate_user!, except: [:create_hand_raise_lead]
before_action :authenticate_user_404!, only: [:create_hand_raise_lead]
before_action :find_or_create_namespace, only: :apply
before_action :find_namespace, only: [:extend_reactivate]
before_action :find_namespace, only: [:extend_reactivate, :create_hand_raise_lead]
before_action :authenticate_namespace_owner!, only: [:extend_reactivate]
feature_category :purchase
......@@ -42,6 +43,18 @@ class TrialsController < ApplicationController
end
end
def create_hand_raise_lead
return render_404 unless Feature.enabled?(:in_app_hand_raise_pql, @namespace)
result = GitlabSubscriptions::CreateHandRaiseLeadService.new.execute(hand_raise_lead_params)
if result.success?
head 200
else
render_403
end
end
def apply
apply_trial_and_redirect
end
......@@ -73,6 +86,10 @@ class TrialsController < ApplicationController
redirect_to new_trial_registration_path, alert: I18n.t('devise.failure.unauthenticated')
end
def authenticate_user_404!
render_404 unless current_user
end
def authenticate_namespace_owner!
user_is_namespace_owner = if @namespace.is_a?(Group)
@namespace.owners.include?(current_user)
......@@ -83,6 +100,21 @@ class TrialsController < ApplicationController
render_403 unless user_is_namespace_owner
end
def hand_raise_lead_params
params.permit(:first_name, :last_name, :company_name, :company_size, :phone_number, :country,
:state, :namespace_id, :comment)
.merge(hand_raise_lead_extra_params)
end
def hand_raise_lead_extra_params
{
work_email: current_user.email,
uid: current_user.id,
provider: 'gitlab',
setup_for_company: current_user.setup_for_company
}
end
def company_params
params.permit(:company_name, :company_size, :first_name, :last_name, :phone_number, :number_of_users, :country)
.merge(extra_params)
......
name: in_app_hand_raise_pql
introduced_by_url:
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/334211
milestone: '14.4'
type: development
group: group::conversion
default_enabled: false
......@@ -6,5 +6,6 @@ resources :trials, only: [:new] do
get :select
post :apply
put :extend_reactivate
post :create_hand_raise_lead
end
end
......@@ -201,6 +201,95 @@ RSpec.describe TrialsController do
end
end
describe '#create_hand_raise_lead' do
let_it_be(:namespace) { create(:group) }
let_it_be(:namespace_id) { namespace.id.to_s }
let(:create_hand_raise_lead_result) { true }
let(:hand_raise_lead_extra_params) do
{
work_email: user.email,
uid: user.id,
provider: 'gitlab',
setup_for_company: user.setup_for_company
}
end
let(:post_params) do
{
namespace_id: namespace_id,
first_name: 'James',
last_name: 'Bond',
company_name: 'ACME',
company_size: '1-99',
phone_number: '+1-192-10-10',
country: 'US',
state: 'CA',
comment: 'I want to talk to sales.'
}
end
subject do
post :create_hand_raise_lead, params: post_params
response
end
before_all do
namespace.add_developer(user)
end
before do
stub_feature_flags(in_app_hand_raise_pql: true)
allow_next_instance_of(GitlabSubscriptions::CreateHandRaiseLeadService) do |service|
allow(service).to receive(:execute).and_return(create_hand_raise_lead_result ? ServiceResponse.success : ServiceResponse.error(message: 'failed'))
end
end
it_behaves_like 'a dot-com only feature'
context 'when not authenticated' do
let(:logged_in) { false }
it { is_expected.to have_gitlab_http_status(:not_found) }
end
context 'when in_app_hand_raise_pql feature flag is disabled' do
before do
stub_feature_flags(in_app_hand_raise_pql: false)
end
it { is_expected.to have_gitlab_http_status(:not_found) }
end
context 'when cannot find the namespace' do
let(:namespace_id) { non_existing_record_id.to_s }
it 'returns 404' do
is_expected.to have_gitlab_http_status(:not_found)
end
end
context 'when CreateHandRaiseLeadService fails' do
let(:create_hand_raise_lead_result) { false }
it 'returns 403' do
is_expected.to have_gitlab_http_status(:forbidden)
end
end
it 'calls the CreateHandRaiseLeadService with correct parameters' do
expect_next_instance_of(GitlabSubscriptions::CreateHandRaiseLeadService) do |service|
expected_params = ActionController::Parameters.new(post_params)
.permit!
.merge(hand_raise_lead_extra_params)
expect(service).to receive(:execute).with(expected_params).and_return(ServiceResponse.success)
end
post :create_hand_raise_lead, params: post_params
end
end
describe '#select' do
subject(:get_select) do
get :select
......
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