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
a3911576
Commit
a3911576
authored
Feb 19, 2021
by
Doug Stull
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor registration area for easier extension
- enable extension in subsequent MR
parent
77239704
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
261 additions
and
193 deletions
+261
-193
ee/app/controllers/registrations/groups_controller.rb
ee/app/controllers/registrations/groups_controller.rb
+58
-31
ee/app/controllers/registrations/projects_controller.rb
ee/app/controllers/registrations/projects_controller.rb
+11
-5
ee/spec/controllers/registrations/groups_controller_spec.rb
ee/spec/controllers/registrations/groups_controller_spec.rb
+178
-135
ee/spec/support/shared_examples/controllers/concerns/group_invite_members_shared_examples.rb
...trollers/concerns/group_invite_members_shared_examples.rb
+14
-22
No files found.
ee/app/controllers/registrations/groups_controller.rb
View file @
a3911576
...
...
@@ -19,14 +19,43 @@ module Registrations
def
create
@group
=
Groups
::
CreateService
.
new
(
current_user
,
group_params
).
execute
render_new
&&
return
unless
@group
.
persisted?
if
@group
.
persisted?
create_successful_flow
else
render
action: :new
end
end
protected
def
show_confirm_warning?
false
end
trial
=
params
[
:trial
]
==
'true'
url_params
=
{
namespace_id:
@group
.
id
,
trial:
trial
}
private
def
check_signup_onboarding_enabled
access_denied!
unless
helpers
.
signup_onboarding_enabled?
end
def
create_successful_flow
if
helpers
.
in_trial_onboarding_flow?
render_new
&&
return
unless
apply_trial
apply_trial_for_trial_onboarding_flow
else
registration_onboarding_flow
end
end
def
authorize_create_group!
access_denied!
unless
can?
(
current_user
,
:create_group
)
end
def
group_params
params
.
require
(
:group
).
permit
(
:name
,
:path
,
:visibility_level
)
end
def
apply_trial_for_trial_onboarding_flow
if
apply_trial
record_experiment_user
(
:remove_known_trial_form_fields
,
namespace_id:
@group
.
id
)
record_experiment_user
(
:trimmed_skip_trial_copy
,
namespace_id:
@group
.
id
)
record_experiment_user
(
:trial_registration_with_social_signin
,
namespace_id:
@group
.
id
)
...
...
@@ -36,46 +65,44 @@ module Registrations
record_experiment_conversion_event
(
:trial_registration_with_social_signin
)
record_experiment_conversion_event
(
:trial_onboarding_issues
)
url_params
[
:trial_onboarding_flow
]
=
true
redirect_to
new_users_sign_up_project_path
(
namespace_id:
@group
.
id
,
trial:
helpers
.
in_trial_during_signup_flow?
,
trial_onboarding_flow:
true
)
else
record_experiment_user
(
:trial_during_signup
,
trial_chosen:
trial
,
namespace_id:
@group
.
id
)
if
experiment_enabled?
(
:trial_during_signup
)
if
trial
render_new
&&
return
unless
create_lead
&&
apply_trial
record_experiment_conversion_event
(
:trial_during_signup
)
end
else
invite_members
(
@group
)
end
render
action: :new
end
redirect_to
new_users_sign_up_project_path
(
url_params
)
end
protected
def
registration_onboarding_flow
record_experiment_user
(
:trial_during_signup
,
trial_chosen:
helpers
.
in_trial_during_signup_flow?
,
namespace_id:
@group
.
id
)
def
show_confirm_warning?
false
if
experiment_enabled?
(
:trial_during_signup
)
trial_during_signup_flow
else
invite_on_create
end
end
private
def
invite_on_create
invite_members
(
@group
)
def
check_signup_onboarding_enabled
access_denied!
unless
helpers
.
signup_onboarding_enabled?
redirect_to
new_users_sign_up_project_path
(
namespace_id:
@group
.
id
,
trial:
helpers
.
in_trial_during_signup_flow?
)
end
def
authorize_create_group!
access_denied!
unless
can?
(
current_user
,
:create_group
)
def
trial_during_signup_flow
if
helpers
.
in_trial_during_signup_flow?
create_lead_and_apply_trial_flow
else
redirect_to
new_users_sign_up_project_path
(
namespace_id:
@group
.
id
,
trial:
helpers
.
in_trial_during_signup_flow?
)
end
end
def
group_params
params
.
require
(
:group
).
permit
(
:name
,
:path
,
:visibility_level
)
end
def
create_lead_and_apply_trial_flow
if
create_lead
&&
apply_trial
record_experiment_conversion_event
(
:trial_during_signup
)
def
render_new
render
action: :new
redirect_to
new_users_sign_up_project_path
(
namespace_id:
@group
.
id
,
trial:
helpers
.
in_trial_during_signup_flow?
)
else
render
action: :new
end
end
def
create_lead
...
...
ee/app/controllers/registrations/projects_controller.rb
View file @
a3911576
...
...
@@ -5,7 +5,10 @@ module Registrations
layout
'checkout'
before_action
:check_signup_onboarding_enabled
before_action
:find_namespace
,
only: :new
before_action
only:
[
:new
]
do
set_namespace
authorize_create_project!
end
feature_category
:navigation
...
...
@@ -28,9 +31,10 @@ module Registrations
record_experiment_user
(
:trial_onboarding_issues
,
trial_onboarding_context
)
record_experiment_conversion_event
(
:trial_onboarding_issues
)
redirect_to
trial_getting_started_users_sign_up_welcome_path
(
learn_gitlab_project_id:
learn_gitlab_project
.
id
)
else
redirect_to
users_sign_up_experience_level_path
(
namespace_path:
@project
.
namespace
,
trial_onboarding_flow:
params
[
:trial_onboarding_flow
]
)
redirect_to
users_sign_up_experience_level_path
(
namespace_path:
@project
.
namespace
)
end
else
render
:new
...
...
@@ -64,12 +68,14 @@ module Registrations
learn_gitlab_project
end
def
find_namespace
@namespace
=
Namespace
.
find_by_id
(
params
[
:namespace_id
])
def
authorize_create_project!
access_denied!
unless
can?
(
current_user
,
:create_projects
,
@namespace
)
end
def
set_namespace
@namespace
=
Namespace
.
find_by_id
(
params
[
:namespace_id
])
end
def
project_params
params
.
require
(
:project
).
permit
(
project_params_attributes
)
end
...
...
ee/spec/controllers/registrations/groups_controller_spec.rb
View file @
a3911576
This diff is collapsed.
Click to expand it.
ee/spec/support/shared_examples/controllers/concerns/group_invite_members_shared_examples.rb
View file @
a3911576
...
...
@@ -2,43 +2,35 @@
RSpec
.
shared_examples
GroupInviteMembers
do
context
'when inviting members'
,
:snowplow
do
before
do
allow
(
Gitlab
::
Tracking
).
to
receive
(
:event
)
# rubocop:disable RSpec/ExpectGitlabTracking
end
context
'without valid emails in the params'
do
it
'only adds creator as member'
do
expect
{
subject
}.
to
change
(
Member
,
:count
).
by
(
1
)
it
'no invites generated by default'
do
subject
expect
(
assigns
(
:group
).
members
.
invite
).
to
be_empty
end
it
'does not track the event'
do
subject
expect
_no_snowplow_event
expect
(
Gitlab
::
Tracking
).
not_to
have_received
(
:event
).
with
(
anything
,
'invite_members'
,
label:
'new_group_form'
)
# rubocop:disable RSpec/ExpectGitlabTracking
end
end
context
'with valid emails in the params'
do
before
do
group_params
[
:emails
]
=
[
'a@a.a'
,
'b@b.b'
,
''
,
''
,
'x'
,
'y'
]
end
it
'adds users with developer access and ignores blank emails'
do
expect_next_instance_of
(
Group
)
do
|
group
|
expect
(
group
).
to
receive
(
:add_users
).
with
(
%w[a@a.a b@b.b x y]
,
Gitlab
::
Access
::
DEVELOPER
,
expires_at:
nil
,
current_user:
user
).
and_call_original
end
let
(
:valid_emails
)
{
%w[a@a.a b@b.b]
}
subject
before
do
group_params
[
:emails
]
=
valid_emails
+
[
''
,
''
,
'x'
,
'y'
]
end
it
'
sends invitations to valid emails only
'
do
it
'
adds users with developer access and ignores blank and invalid emails
'
do
subject
emails
=
assigns
(
:group
).
members
.
pluck
(
:invite_email
)
expect
(
emails
).
to
include
(
'a@a.a'
,
'b@b.b'
)
expect
(
emails
).
not_to
include
(
'x'
,
'y'
)
expect
(
assigns
(
:group
).
members
.
invite
.
pluck
(
:invite_email
)).
to
match_array
(
valid_emails
)
end
it
'tracks the event'
do
...
...
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