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 ...@@ -13,6 +13,10 @@ class DeviseMailer < Devise::Mailer
devise_mail(record, :password_change_by_admin, opts) devise_mail(record, :password_change_by_admin, opts)
end end
def user_admin_approval(record, opts = {})
devise_mail(record, :user_admin_approval, opts)
end
protected protected
def subject_for(key) def subject_for(key)
......
...@@ -24,6 +24,10 @@ class DeviseMailerPreview < ActionMailer::Preview ...@@ -24,6 +24,10 @@ class DeviseMailerPreview < ActionMailer::Preview
DeviseMailer.password_change(unsaved_user, {}) DeviseMailer.password_change(unsaved_user, {})
end end
def user_admin_approval
DeviseMailer.user_admin_approval(unsaved_user, {})
end
private private
def unsaved_user def unsaved_user
......
...@@ -15,6 +15,7 @@ module Users ...@@ -15,6 +15,7 @@ module Users
# Please see Devise's implementation of `resend_confirmation_instructions` for detail. # Please see Devise's implementation of `resend_confirmation_instructions` for detail.
user.resend_confirmation_instructions user.resend_confirmation_instructions
user.accept_pending_invitations! if user.active_for_authentication? user.accept_pending_invitations! if user.active_for_authentication?
DeviseMailer.user_admin_approval(user).deliver_later
success success
else 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: ...@@ -30,6 +30,8 @@ en:
subject: "Password Changed" subject: "Password Changed"
password_change_by_admin: password_change_by_admin:
subject: "Password changed by administrator" subject: "Password changed by administrator"
user_admin_approval:
subject: "Welcome to GitLab!"
omniauth_callbacks: omniauth_callbacks:
failure: "Could not authenticate you from %{kind} because \"%{reason}\"." failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
success: "Successfully authenticated from %{kind} account." success: "Successfully authenticated from %{kind} account."
......
...@@ -31202,6 +31202,9 @@ msgstr "" ...@@ -31202,6 +31202,9 @@ msgstr ""
msgid "Your GPG keys (%{count})" msgid "Your GPG keys (%{count})"
msgstr "" msgstr ""
msgid "Your GitLab account request has been approved!"
msgstr ""
msgid "Your GitLab group" msgid "Your GitLab group"
msgstr "" msgstr ""
...@@ -31400,6 +31403,9 @@ msgstr "" ...@@ -31400,6 +31403,9 @@ msgstr ""
msgid "Your search didn't match any commits. Try a different query." msgid "Your search didn't match any commits. Try a different query."
msgstr "" msgstr ""
msgid "Your sign-in page is %{url}."
msgstr ""
msgid "Your subscription expired!" msgid "Your subscription expired!"
msgstr "" msgstr ""
...@@ -31409,6 +31415,9 @@ msgstr "" ...@@ -31409,6 +31415,9 @@ msgstr ""
msgid "Your subscription will expire in %{remaining_days}." msgid "Your subscription will expire in %{remaining_days}."
msgstr "" msgstr ""
msgid "Your username is %{username}."
msgstr ""
msgid "Zoom meeting added" msgid "Zoom meeting added"
msgstr "" msgstr ""
......
...@@ -116,6 +116,11 @@ RSpec.describe Admin::UsersController do ...@@ -116,6 +116,11 @@ RSpec.describe Admin::UsersController do
expect(user).to be_active expect(user).to be_active
expect(flash[:notice]).to eq('Successfully approved') expect(flash[:notice]).to eq('Successfully approved')
end 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 end
context 'when unsuccessful' do context 'when unsuccessful' do
...@@ -133,6 +138,10 @@ RSpec.describe Admin::UsersController do ...@@ -133,6 +138,10 @@ RSpec.describe Admin::UsersController do
user.reload user.reload
expect(user).not_to be_active expect(user).not_to be_active
end end
it 'does not email the pending user' do
expect { subject }.not_to have_enqueued_mail(DeviseMailer, :user_admin_approval)
end
end end
end end
......
...@@ -64,4 +64,34 @@ RSpec.describe DeviseMailer do ...@@ -64,4 +64,34 @@ RSpec.describe DeviseMailer do
is_expected.to have_body_text /#{Gitlab.config.gitlab.url}/ is_expected.to have_body_text /#{Gitlab.config.gitlab.url}/
end end
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 end
...@@ -61,6 +61,11 @@ RSpec.describe Users::ApproveService do ...@@ -61,6 +61,11 @@ RSpec.describe Users::ApproveService do
expect(user.reload).to be_active expect(user.reload).to be_active
end 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 'email confirmation status' do
context 'user is unconfirmed' do context 'user is unconfirmed' do
let(:user) { create(:user, :blocked_pending_approval, :unconfirmed) } 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