Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send email to author when resource was hidden #29

Open
wants to merge 8 commits into
base: release/0.26-stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions decidim-admin/app/commands/decidim/admin/hide_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def call

send_hide_notification_to_author

send_hide_email_to_author

broadcast(:ok, @reportable)
end

Expand Down Expand Up @@ -63,6 +65,16 @@ def send_hide_notification_to_author
Decidim::EventsManager.publish(data)
end

def send_hide_email_to_author
Decidim::Admin::HiddenResourceMailer.notify_mail(
@reportable, resource_authors, report_reasons
).deliver_later
end

def resource_authors
@reportable.try(:authors) || [@reportable.try(:author)]
end

def report_reasons
@reportable.moderation.reports.pluck(:reason).uniq
end
Expand Down
28 changes: 28 additions & 0 deletions decidim-admin/app/mailers/decidim/admin/hidden_resource_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module Decidim
module Admin
# A custom mailer to mail Decidim users
# that they have been hidden
class HiddenResourceMailer < Decidim::ApplicationMailer
include Decidim::TranslationsHelper
include Decidim::SanitizeHelper
include Decidim::ApplicationHelper
include Decidim::TranslatableAttributes

helper Decidim::ResourceHelper
helper Decidim::TranslationsHelper
helper Decidim::ApplicationHelper

def notify_mail(resource, resource_authors, reason)
@resource_authors = resource_authors
@organization = resource.organization
@resource = resource
@reason = reason

mail(to: resource_authors.pluck(:email).uniq,
subject: I18n.t("decidim.admin.hidden_resource_mailer.notify_mail.subject"))
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p class="email-greeting"><%= t ".hello" %></p>

<p class="email-instructions">
<%= t ".body_1" %>
</p>

<p><strong><%= t ".reason", reason: h(@reason.join(", ")) %></strong></p>

<p><strong><%= translated_attribute(@resource.title) %></strong></p>

<p class="email-instructions">
<span><%= t ".body_2" %></span>
<span><%= link_to @organization.name, decidim.root_url(host: @organization.host).html_safe %></span>
antopalidi marked this conversation as resolved.
Show resolved Hide resolved
</p>
7 changes: 7 additions & 0 deletions decidim-admin/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@ en:
form:
save: Save
success: Help sections updated successfully
hidden_resource_mailer:
notify_mail:
body_1: An administrator removed your proposal because it has been reported.
body_2: If you feel that has been a mistake please contact the administrators of
hello: Hello,
reason: 'Reason: %{reason}'
subject: Your proposal has been hidden
impersonatable_users:
index:
filter:
Expand Down
10 changes: 10 additions & 0 deletions decidim-admin/spec/commands/decidim/admin/hide_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,20 @@ module Decidim::Admin

context "when the resource is already hidden" do
let(:moderation) { create(:moderation, reportable: reportable, report_count: 1, hidden_at: Time.current) }
let(:authors) { reportable.try(:authors) || [reportable.try(:author)] }
let(:reasons) { reportable.moderation.reports.pluck(:reason).uniq }

it "broadcasts invalid" do
expect { command.call }.to broadcast(:invalid)
end

it "sends email to author" do
clear_enqueued_jobs
command.call
expect(ActionMailer::MailDeliveryJob).to have_been_enqueued.on_queue("mailers")
queued_user, _, queued_options = ActiveJob::Arguments.deserialize(ActiveJob::Base.queue_adapter.enqueued_jobs.first[:args]).last[:args]
expect(queued_user).to eq(current_user)
end
end

context "when the resource is not reported" do
Expand Down