Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
99fd82cc
Commit
99fd82cc
authored
Oct 05, 2021
by
Alper Akgun
Committed by
Peter Leitzen
Oct 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create hand raise controller endpoint
parent
c7c495a0
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
2 deletions
+131
-2
ee/app/controllers/trials_controller.rb
ee/app/controllers/trials_controller.rb
+34
-2
ee/config/feature_flags/development/in_app_hand_raise_pql.yml
...onfig/feature_flags/development/in_app_hand_raise_pql.yml
+7
-0
ee/config/routes/trial.rb
ee/config/routes/trial.rb
+1
-0
ee/spec/controllers/trials_controller_spec.rb
ee/spec/controllers/trials_controller_spec.rb
+89
-0
No files found.
ee/app/controllers/trials_controller.rb
View file @
99fd82cc
...
@@ -8,9 +8,10 @@ class TrialsController < ApplicationController
...
@@ -8,9 +8,10 @@ class TrialsController < ApplicationController
layout
'minimal'
layout
'minimal'
before_action
:check_if_gl_com_or_dev
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_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
]
before_action
:authenticate_namespace_owner!
,
only:
[
:extend_reactivate
]
feature_category
:purchase
feature_category
:purchase
...
@@ -42,6 +43,18 @@ class TrialsController < ApplicationController
...
@@ -42,6 +43,18 @@ class TrialsController < ApplicationController
end
end
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
def
apply
apply_trial_and_redirect
apply_trial_and_redirect
end
end
...
@@ -73,6 +86,10 @@ class TrialsController < ApplicationController
...
@@ -73,6 +86,10 @@ class TrialsController < ApplicationController
redirect_to
new_trial_registration_path
,
alert:
I18n
.
t
(
'devise.failure.unauthenticated'
)
redirect_to
new_trial_registration_path
,
alert:
I18n
.
t
(
'devise.failure.unauthenticated'
)
end
end
def
authenticate_user_404!
render_404
unless
current_user
end
def
authenticate_namespace_owner!
def
authenticate_namespace_owner!
user_is_namespace_owner
=
if
@namespace
.
is_a?
(
Group
)
user_is_namespace_owner
=
if
@namespace
.
is_a?
(
Group
)
@namespace
.
owners
.
include?
(
current_user
)
@namespace
.
owners
.
include?
(
current_user
)
...
@@ -83,6 +100,21 @@ class TrialsController < ApplicationController
...
@@ -83,6 +100,21 @@ class TrialsController < ApplicationController
render_403
unless
user_is_namespace_owner
render_403
unless
user_is_namespace_owner
end
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
def
company_params
params
.
permit
(
:company_name
,
:company_size
,
:first_name
,
:last_name
,
:phone_number
,
:number_of_users
,
:country
)
params
.
permit
(
:company_name
,
:company_size
,
:first_name
,
:last_name
,
:phone_number
,
:number_of_users
,
:country
)
.
merge
(
extra_params
)
.
merge
(
extra_params
)
...
...
ee/config/feature_flags/development/in_app_hand_raise_pql.yml
0 → 100644
View file @
99fd82cc
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
ee/config/routes/trial.rb
View file @
99fd82cc
...
@@ -6,5 +6,6 @@ resources :trials, only: [:new] do
...
@@ -6,5 +6,6 @@ resources :trials, only: [:new] do
get
:select
get
:select
post
:apply
post
:apply
put
:extend_reactivate
put
:extend_reactivate
post
:create_hand_raise_lead
end
end
end
end
ee/spec/controllers/trials_controller_spec.rb
View file @
99fd82cc
...
@@ -201,6 +201,95 @@ RSpec.describe TrialsController do
...
@@ -201,6 +201,95 @@ RSpec.describe TrialsController do
end
end
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
describe
'#select'
do
subject
(
:get_select
)
do
subject
(
:get_select
)
do
get
:select
get
:select
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment