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
2bc0f0cf
Commit
2bc0f0cf
authored
Jul 31, 2019
by
Alex Buijs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ConfirmEmailWarning concern
parent
7ee68572
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
124 additions
and
0 deletions
+124
-0
app/controllers/application_controller.rb
app/controllers/application_controller.rb
+1
-0
app/controllers/concerns/confirm_email_warning.rb
app/controllers/concerns/confirm_email_warning.rb
+25
-0
spec/controllers/concerns/confirm_email_warning_spec.rb
spec/controllers/concerns/confirm_email_warning_spec.rb
+98
-0
No files found.
app/controllers/application_controller.rb
View file @
2bc0f0cf
...
...
@@ -12,6 +12,7 @@ class ApplicationController < ActionController::Base
include
EnforcesTwoFactorAuthentication
include
WithPerformanceBar
include
SessionlessAuthentication
include
ConfirmEmailWarning
before_action
:authenticate_user!
before_action
:enforce_terms!
,
if: :should_enforce_terms?
...
...
app/controllers/concerns/confirm_email_warning.rb
0 → 100644
View file @
2bc0f0cf
# frozen_string_literal: true
module
ConfirmEmailWarning
extend
ActiveSupport
::
Concern
included
do
before_action
:set_confirm_warning
,
if:
->
{
Feature
.
enabled?
(
:soft_email_confirmation
)
}
end
protected
def
set_confirm_warning
return
if
peek_request?
||
json_request?
||
!
request
.
get?
return
unless
current_user
return
if
current_user
.
confirmed?
email
=
current_user
.
unconfirmed_email
||
current_user
.
email
flash
.
now
[
:warning
]
=
_
(
"Please check your email (%{email}) to verify that you own this address. Didn't receive it? %{resend_link}. Wrong email address? %{update_link}."
).
html_safe
%
{
email:
email
,
resend_link:
view_context
.
link_to
(
_
(
'Resend it'
),
user_confirmation_path
(
user:
{
email:
email
}),
method: :post
),
update_link:
view_context
.
link_to
(
_
(
'Update it'
),
profile_path
)
}
end
end
spec/controllers/concerns/confirm_email_warning_spec.rb
0 → 100644
View file @
2bc0f0cf
# frozen_string_literal: true
require
'spec_helper'
describe
ConfirmEmailWarning
do
before
do
stub_feature_flags
(
soft_email_confirmation:
true
)
allow
(
User
).
to
receive
(
:allow_unconfirmed_access_for
).
and_return
2
.
days
end
controller
(
ApplicationController
)
do
# `described_class` is not available in this context
include
ConfirmEmailWarning
# rubocop:disable RSpec/DescribedClass
def
index
head
:ok
end
end
RSpec
::
Matchers
.
define
:set_confirm_warning_for
do
|
email
|
match
do
|
response
|
expect
(
response
).
to
set_flash
.
now
[
:warning
].
to
include
(
"Please check your email (
#{
email
}
) to verify that you own this address."
)
end
end
describe
'confirm email flash warning'
do
context
'when not signed in'
do
let
(
:user
)
{
create
(
:user
,
confirmed_at:
nil
)
}
before
do
get
:index
end
it
{
is_expected
.
not_to
set_confirm_warning_for
(
user
.
email
)
}
end
context
'when signed in'
do
before
do
sign_in
(
user
)
end
context
'with a confirmed user'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
get
:index
end
it
{
is_expected
.
not_to
set_confirm_warning_for
(
user
.
email
)
}
end
context
'with an unconfirmed user'
do
let
(
:user
)
{
create
(
:user
,
confirmed_at:
nil
)
}
context
'when executing a peek request'
do
before
do
request
.
path
=
'/-/peek'
get
:index
end
it
{
is_expected
.
not_to
set_confirm_warning_for
(
user
.
email
)
}
end
context
'when executing a json request'
do
before
do
get
:index
,
format: :json
end
it
{
is_expected
.
not_to
set_confirm_warning_for
(
user
.
email
)
}
end
context
'when executing a post request'
do
before
do
post
:index
end
it
{
is_expected
.
not_to
set_confirm_warning_for
(
user
.
email
)
}
end
context
'when executing a get request'
do
before
do
get
:index
end
context
'with an unconfirmed email address present'
do
let
(
:user
)
{
create
(
:user
,
confirmed_at:
nil
,
unconfirmed_email:
'unconfirmed@gitlab.com'
)
}
it
{
is_expected
.
to
set_confirm_warning_for
(
user
.
unconfirmed_email
)
}
end
context
'without an unconfirmed email address present'
do
it
{
is_expected
.
to
set_confirm_warning_for
(
user
.
email
)
}
end
end
end
end
end
end
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