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
5c5d49e2
Commit
5c5d49e2
authored
Aug 31, 2021
by
Jackie Fraser
Committed by
Etienne Baqué
Aug 31, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate new user saved before accepting invite
parent
94468c74
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
3 deletions
+46
-3
app/controllers/registrations_controller.rb
app/controllers/registrations_controller.rb
+2
-1
app/models/member.rb
app/models/member.rb
+4
-2
spec/controllers/registrations_controller_spec.rb
spec/controllers/registrations_controller_spec.rb
+20
-0
spec/features/invites_spec.rb
spec/features/invites_spec.rb
+10
-0
spec/models/member_spec.rb
spec/models/member_spec.rb
+10
-0
No files found.
app/controllers/registrations_controller.rb
View file @
5c5d49e2
...
...
@@ -21,9 +21,10 @@ class RegistrationsController < Devise::RegistrationsController
def
create
set_user_state
accept_pending_invitations
super
do
|
new_user
|
accept_pending_invitations
if
new_user
.
persisted?
persist_accepted_terms_if_required
(
new_user
)
set_role_required
(
new_user
)
...
...
app/models/member.rb
View file @
5c5d49e2
...
...
@@ -278,12 +278,14 @@ class Member < ApplicationRecord
def
accept_invite!
(
new_user
)
return
false
unless
invite?
return
false
unless
new_user
self
.
user
=
new_user
return
false
unless
self
.
user
.
save
self
.
invite_token
=
nil
self
.
invite_accepted_at
=
Time
.
current
.
utc
self
.
user
=
new_user
saved
=
self
.
save
after_accept_invite
if
saved
...
...
spec/controllers/registrations_controller_spec.rb
View file @
5c5d49e2
...
...
@@ -283,6 +283,26 @@ RSpec.describe RegistrationsController do
end
end
context
'when the registration fails'
do
let_it_be
(
:member
)
{
create
(
:project_member
,
:invited
)
}
let_it_be
(
:missing_user_params
)
do
{
username:
''
,
email:
member
.
invite_email
,
password:
'Any_password'
}
end
let_it_be
(
:user_params
)
{
{
user:
missing_user_params
}
}
let
(
:session_params
)
{
{
invite_email:
member
.
invite_email
}
}
subject
{
post
(
:create
,
params:
user_params
,
session:
session_params
)
}
it
'does not delete the invitation or register the new user'
do
subject
expect
(
member
.
invite_token
).
not_to
be_nil
expect
(
controller
.
current_user
).
to
be_nil
end
end
context
'when soft email confirmation is enabled'
do
before
do
stub_feature_flags
(
soft_email_confirmation:
true
)
...
...
spec/features/invites_spec.rb
View file @
5c5d49e2
...
...
@@ -189,6 +189,16 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
end
context
'email confirmation enabled'
do
context
'when user is not valid in sign up form'
do
let
(
:new_user
)
{
build_stubbed
(
:user
,
first_name:
''
,
last_name:
''
)
}
it
'fails sign up and redirects back to sign up'
,
:aggregate_failures
do
expect
{
fill_in_sign_up_form
(
new_user
)
}.
not_to
change
{
User
.
count
}
expect
(
page
).
to
have_content
(
'prohibited this user from being saved'
)
expect
(
current_path
).
to
eq
(
user_registration_path
)
end
end
context
'with invite email acceptance'
,
:snowplow
do
it
'tracks the accepted invite'
do
fill_in_sign_up_form
(
new_user
)
...
...
spec/models/member_spec.rb
View file @
5c5d49e2
...
...
@@ -645,6 +645,16 @@ RSpec.describe Member do
expect
(
user
.
authorized_projects
.
reload
).
to
include
(
project
)
end
it
'does not accept the invite if saving a new user fails'
do
invalid_user
=
User
.
new
(
first_name:
''
,
last_name:
''
)
member
.
accept_invite!
invalid_user
expect
(
member
.
invite_accepted_at
).
to
be_nil
expect
(
member
.
invite_token
).
not_to
be_nil
expect_any_instance_of
(
Member
).
not_to
receive
(
:after_accept_invite
)
end
end
describe
"#decline_invite!"
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