Skip to content
Snippets Groups Projects
Unverified Commit 2bc0f0cf authored by Alex Buijs's avatar Alex Buijs
Browse files

Add ConfirmEmailWarning concern

parent 7ee68572
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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?
Loading
Loading
# 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
# 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment