-
Notifications
You must be signed in to change notification settings - Fork 657
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- a new mailer + new template - a new method in BlockUserAlert to mail to a set of concerned people which replace the current one in blocked_user_monitor.rb - the corresponding spec - new line in preview mailer
- Loading branch information
Showing
6 changed files
with
119 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
class BlockedUserAlertMailer < ApplicationMailer | ||
def self.send_mails_to_concerned(alert) | ||
return unless Features.email? | ||
email(alert).deliver_now | ||
end | ||
|
||
def email(alert) | ||
@alert = alert | ||
set_recipients | ||
return if @recipients.empty? | ||
params = { to: @recipients, | ||
subject: @alert.main_subject } | ||
params[:reply_to] = @alert.reply_to unless @alert.reply_to.nil? | ||
mail(params) | ||
end | ||
|
||
private | ||
|
||
def set_recipients | ||
@course = @alert.course | ||
@user = @alert.user | ||
@recipients = (@course.instructors.pluck(:email) + | ||
@course.nonstudents.where(greeter: true).pluck(:email)) << | ||
@user.email | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
%link{rel: 'stylesheet', href:'/mailer.css'} | ||
%p.paragraph | ||
Please investigate: | ||
%a.link{ href: @alert.url }= @alert.main_subject | ||
|
||
- if @alert.user_contributions_url | ||
%p.paragraph | ||
%a.link{href: @alert.user_contributions_url}= "#{@alert.user.username} contributions" | ||
|
||
- if @alert.message | ||
%p.paragraph.preserve-whitespace | ||
= "Message regarding #{@alert.user.username}:" | ||
= @alert.message | ||
|
||
%p.paragraph | ||
User email: | ||
= @alert.user.email | ||
|
||
%p.paragraph | ||
User real name: | ||
= @alert.user.real_name | ||
|
||
- if @alert.article | ||
%p.paragraph | ||
Article: | ||
%a.link{href: @alert.article.url}= @alert.article.title | ||
|
||
- if @alert.revision | ||
%p.paragraph | ||
%a.link{href: @alert.revision.url} diff | ||
|
||
- if @alert.details | ||
%p.paragraph.preserve-whitespace | ||
Alert details: | ||
= @alert.details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,25 +5,48 @@ | |
|
||
describe BlockedUserMonitor do | ||
describe '.create_alerts_for_recently_blocked_users' do | ||
let(:user) { create(:user, username: 'Verdantpowerinc') } | ||
let(:course) { create(:course) } | ||
let(:user) { create(:user, username: 'Verdantpowerinc', email: '[email protected]') } | ||
let(:instructor_1) { create(:user, username: 'Instructor1', email: '[email protected]') } | ||
let(:instructor_2) { create(:user, username: 'Instructor2', email: '[email protected]') } | ||
let(:staff) { create(:user, username: 'staff', email: '[email protected]', greeter: true) } | ||
let(:course) do | ||
now = Time.zone.now | ||
create(:course, start: now.days_ago(7), end: now.days_since(7)) | ||
end | ||
|
||
before do | ||
create(:courses_user, user:, course:) | ||
create(:courses_user, course:, user: instructor_1, | ||
role: CoursesUsers::Roles::INSTRUCTOR_ROLE) | ||
create(:courses_user, course:, user: instructor_2, | ||
role: CoursesUsers::Roles::INSTRUCTOR_ROLE) | ||
create(:courses_user, course:, user: staff, | ||
role: CoursesUsers::Roles::WIKI_ED_STAFF_ROLE) | ||
stub_block_log_query | ||
end | ||
|
||
it 'creates an Alert record for a blocked user' do | ||
expect(Alert.count).to eq(0) | ||
described_class.create_alerts_for_recently_blocked_users | ||
expect(Alert.count).to eq(1) | ||
expect { described_class.create_alerts_for_recently_blocked_users } | ||
.to change(BlockedUserAlert, :count).by(1) | ||
end | ||
|
||
it 'does not create multiple alerts for the same block' do | ||
expect(Alert.count).to eq(0) | ||
described_class.create_alerts_for_recently_blocked_users | ||
expect do | ||
2.times { described_class.create_alerts_for_recently_blocked_users } | ||
end.to change(BlockedUserAlert, :count).by(1) | ||
end | ||
|
||
it 'uses the proper mailer' do | ||
expect(BlockedUserAlertMailer).to receive(:send_mails_to_concerned) | ||
described_class.create_alerts_for_recently_blocked_users | ||
expect(Alert.count).to eq(1) | ||
end | ||
|
||
it 'sends a mail to staff, instructors & student' do | ||
expect do | ||
described_class.create_alerts_for_recently_blocked_users | ||
end.to change { BlockedUserAlertMailer.deliveries.count }.by(1) | ||
msg = BlockedUserAlertMailer.deliveries.first | ||
expect(msg.to).to match_array([instructor_1, instructor_2, user, staff].map(&:email)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters