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
5d24ea16
Commit
5d24ea16
authored
May 10, 2021
by
Doug Stull
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Decouple acceptance of invitations from query
- should not mutate and ask as part of if query
parent
e90e6d49
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
15 deletions
+23
-15
app/controllers/concerns/accepts_pending_invitations.rb
app/controllers/concerns/accepts_pending_invitations.rb
+2
-1
app/models/email.rb
app/models/email.rb
+1
-5
spec/features/users/add_email_to_existing_account_spec.rb
spec/features/users/add_email_to_existing_account_spec.rb
+15
-3
spec/models/email_spec.rb
spec/models/email_spec.rb
+5
-6
No files found.
app/controllers/concerns/accepts_pending_invitations.rb
View file @
5d24ea16
...
...
@@ -6,7 +6,8 @@ module AcceptsPendingInvitations
def
accept_pending_invitations
return
unless
resource
.
active_for_authentication?
if
resource
.
accept_pending_invitations!
.
any?
if
resource
.
pending_invitations
.
load
.
any?
resource
.
accept_pending_invitations!
clear_stored_location_for_resource
after_pending_invitations_hook
end
...
...
app/models/email.rb
View file @
5d24ea16
...
...
@@ -22,7 +22,7 @@ class Email < ApplicationRecord
self
.
reconfirmable
=
false
# currently email can't be changed, no need to reconfirm
delegate
:username
,
:can?
,
to: :user
delegate
:username
,
:can?
,
:pending_invitations
,
:accept_pending_invitations!
,
to: :user
def
email
=
(
value
)
write_attribute
(
:email
,
value
.
downcase
.
strip
)
...
...
@@ -32,10 +32,6 @@ class Email < ApplicationRecord
self
.
errors
.
add
(
:email
,
'has already been taken'
)
if
User
.
exists?
(
email:
self
.
email
)
end
def
accept_pending_invitations!
user
.
accept_pending_invitations!
end
def
validate_email_format
self
.
errors
.
add
(
:email
,
I18n
.
t
(
:invalid
,
scope:
'valid_email.validations.email'
))
unless
ValidateEmail
.
valid?
(
self
.
email
)
end
...
...
spec/features/users/add_email_to_existing_account_spec.rb
View file @
5d24ea16
...
...
@@ -4,13 +4,25 @@ require 'spec_helper'
RSpec
.
describe
'AdditionalEmailToExistingAccount'
do
describe
'add secondary email associated with account'
do
let
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:email
)
{
create
(
:email
,
user:
user
)
}
it
'verifies confirmation of additional email'
do
before
do
sign_in
(
user
)
end
it
'verifies confirmation of additional email'
do
visit
email_confirmation_path
(
confirmation_token:
email
.
confirmation_token
)
expect
(
page
).
to
have_content
'Your email address has been successfully confirmed.'
end
it
'accepts any pending invites for an email confirmation'
do
member
=
create
(
:group_member
,
:invited
,
invite_email:
email
.
email
)
email
=
create
(
:email
,
user:
user
)
visit
email_confirmation_path
(
confirmation_token:
email
.
confirmation_token
)
expect
(
member
.
reload
.
user
).
to
eq
(
user
)
expect
(
page
).
to
have_content
'Your email address has been successfully confirmed.'
end
end
...
...
spec/models/email_spec.rb
View file @
5d24ea16
...
...
@@ -44,12 +44,11 @@ RSpec.describe Email do
end
end
describe
'delegation'
do
let
(
:user
)
{
create
(
:user
)
}
it
'delegates to :user'
do
expect
(
build
(
:email
,
user:
user
).
username
).
to
eq
user
.
username
end
describe
'delegations'
do
it
{
is_expected
.
to
delegate_method
(
:can?
).
to
(
:user
)
}
it
{
is_expected
.
to
delegate_method
(
:username
).
to
(
:user
)
}
it
{
is_expected
.
to
delegate_method
(
:pending_invitations
).
to
(
:user
)
}
it
{
is_expected
.
to
delegate_method
(
:accept_pending_invitations!
).
to
(
:user
)
}
end
describe
'Devise emails'
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