Commit ef88945a authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '257880-user-admin-approval-email-when-approved' into 'master'

User admin approval - Email user when approved

See merge request gitlab-org/gitlab!45947
parents 3ba07f2a d6703c88
......@@ -13,6 +13,10 @@ class DeviseMailer < Devise::Mailer
devise_mail(record, :password_change_by_admin, opts)
end
def user_admin_approval(record, opts = {})
devise_mail(record, :user_admin_approval, opts)
end
protected
def subject_for(key)
......
......@@ -24,6 +24,10 @@ class DeviseMailerPreview < ActionMailer::Preview
DeviseMailer.password_change(unsaved_user, {})
end
def user_admin_approval
DeviseMailer.user_admin_approval(unsaved_user, {})
end
private
def unsaved_user
......
......@@ -15,6 +15,7 @@ module Users
# Please see Devise's implementation of `resend_confirmation_instructions` for detail.
user.resend_confirmation_instructions
user.accept_pending_invitations! if user.active_for_authentication?
DeviseMailer.user_admin_approval(user).deliver_later
success
else
......
= email_default_heading(say_hi(@resource))
%p
= _('Your GitLab account request has been approved!')
%p
= _('Your username is %{username}.') % { username: @resource.username }
%p
= _('Your sign-in page is %{url}.').html_safe % { url: link_to(Gitlab.config.gitlab.url, Gitlab.config.gitlab.url) }
<%= say_hi(@resource) %>
<%= _('Your GitLab account request has been approved!') %>
<%= _('Your username is %{username}.' % { username: @resource.username }) %>
<%= _('Your sign-in page is %{url}.' % { url: Gitlab.config.gitlab.url }) %>
---
title: Email user on admin account approval
merge_request: 45947
author:
type: added
......@@ -30,6 +30,8 @@ en:
subject: "Password Changed"
password_change_by_admin:
subject: "Password changed by administrator"
user_admin_approval:
subject: "Welcome to GitLab!"
omniauth_callbacks:
failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
success: "Successfully authenticated from %{kind} account."
......
......@@ -31202,6 +31202,9 @@ msgstr ""
msgid "Your GPG keys (%{count})"
msgstr ""
msgid "Your GitLab account request has been approved!"
msgstr ""
msgid "Your GitLab group"
msgstr ""
......@@ -31400,6 +31403,9 @@ msgstr ""
msgid "Your search didn't match any commits. Try a different query."
msgstr ""
msgid "Your sign-in page is %{url}."
msgstr ""
msgid "Your subscription expired!"
msgstr ""
......@@ -31409,6 +31415,9 @@ msgstr ""
msgid "Your subscription will expire in %{remaining_days}."
msgstr ""
msgid "Your username is %{username}."
msgstr ""
msgid "Zoom meeting added"
msgstr ""
......
......@@ -116,6 +116,11 @@ RSpec.describe Admin::UsersController do
expect(user).to be_active
expect(flash[:notice]).to eq('Successfully approved')
end
it 'emails the user on approval' do
expect(DeviseMailer).to receive(:user_admin_approval).with(user).and_call_original
expect { subject }.to have_enqueued_mail(DeviseMailer, :user_admin_approval)
end
end
context 'when unsuccessful' do
......@@ -133,6 +138,10 @@ RSpec.describe Admin::UsersController do
user.reload
expect(user).not_to be_active
end
it 'does not email the pending user' do
expect { subject }.not_to have_enqueued_mail(DeviseMailer, :user_admin_approval)
end
end
end
......
......@@ -64,4 +64,34 @@ RSpec.describe DeviseMailer do
is_expected.to have_body_text /#{Gitlab.config.gitlab.url}/
end
end
describe '#user_admin_approval' do
subject { described_class.user_admin_approval(user) }
let_it_be(:user) { create(:user) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like 'a user cannot unsubscribe through footer link'
it 'is sent to the user' do
is_expected.to deliver_to user.email
end
it 'has the correct subject' do
is_expected.to have_subject 'Welcome to GitLab!'
end
it 'greets the user' do
is_expected.to have_body_text /Hi #{user.name}!/
end
it 'includes the correct content' do
is_expected.to have_body_text /Your GitLab account request has been approved!/
end
it 'includes a link to GitLab' do
is_expected.to have_link(Gitlab.config.gitlab.url)
end
end
end
......@@ -61,6 +61,11 @@ RSpec.describe Users::ApproveService do
expect(user.reload).to be_active
end
it 'emails the user on approval' do
expect(DeviseMailer).to receive(:user_admin_approval).with(user).and_call_original
expect { subject }.to have_enqueued_mail(DeviseMailer, :user_admin_approval)
end
context 'email confirmation status' do
context 'user is unconfirmed' do
let(:user) { create(:user, :blocked_pending_approval, :unconfirmed) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment