-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add admin page for emailing petitioners
- Loading branch information
Showing
9 changed files
with
391 additions
and
0 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,38 @@ | ||
class Admin::PetitionEmailsController < Admin::AdminController | ||
respond_to :html | ||
before_action :fetch_petition | ||
before_action :build_email | ||
|
||
def new | ||
render 'admin/petitions/show' | ||
end | ||
|
||
def create | ||
if @email.update(email_params) | ||
EmailPetitionersJob.run_later_tonight(petition: @petition, email: @email) | ||
PetitionMailer.email_signer(@petition, feedback_signature, @email).deliver_now | ||
|
||
redirect_to [:admin, @petition], notice: 'Email will be sent overnight' | ||
else | ||
render 'admin/petitions/show' | ||
end | ||
end | ||
|
||
private | ||
|
||
def fetch_petition | ||
@petition = Petition.moderated.find(params[:petition_id]) | ||
end | ||
|
||
def build_email | ||
@email = @petition.emails.build(sent_by: current_user.pretty_name) | ||
end | ||
|
||
def email_params | ||
params.require(:petition_email).permit(:subject, :body) | ||
end | ||
|
||
def feedback_signature | ||
FeedbackSignature.new(@petition) | ||
end | ||
end |
1 change: 1 addition & 0 deletions
1
app/views/admin/admin/_petition_action_email_petitioners.html.erb
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 @@ | ||
<%= link_to 'Email petitioners', new_admin_petition_email_path(@petition), class: 'petition-action-heading' %> |
20 changes: 20 additions & 0 deletions
20
app/views/admin/petition_emails/_petition_action_email_petitioners.html.erb
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,20 @@ | ||
<h2 class="petition-action-heading">Email petitioners</h2> | ||
<%= form_for @email, url: admin_petition_emails_path(petition), method: :post do |f| -%> | ||
<%= form_row :for => [f.object, :subject] do %> | ||
<%= f.label :subject, 'Subject', class: 'form-label' %> | ||
<%= error_messages_for_field f.object, :subject %> | ||
<%= f.text_area :subject, rows: 2, cols: 70, tabindex: increment, data: { max_length: 100 }, class: 'form-control' %> | ||
<p class="character-count">100 characters max</p> | ||
<% end %> | ||
|
||
<%= form_row :for => [f.object, :body] do %> | ||
<%= f.label :body, 'Body', class: 'form-label' %> | ||
<%= error_messages_for_field f.object, :body %> | ||
<%= f.text_area :body, rows: 8, cols: 70, tabindex: increment, data: { max_length: 5000 }, class: 'form-control' %> | ||
<p class="character-count">5000 characters max</p> | ||
<% end %> | ||
|
||
<%= email_signatures_with_count_submit_button(f, petition) %> | ||
<% end -%> | ||
|
||
<%= javascript_include_tag 'character-counter' %> |
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
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,23 @@ | ||
@admin | ||
Feature: Emailing petitioner supporters | ||
In order to keep petition supporters up-to-date on their petition | ||
As an admin user | ||
I want to send an email to all petition supporters | ||
|
||
Scenario: Sending an email to all petitioners | ||
Given an open petition "Ban Badger Baiting" with some signatures | ||
And I am logged in as a sysadmin with the email "[email protected]", first_name "Admin", last_name "User" | ||
When I am on the admin all petitions page | ||
And I follow "Ban Badger Baiting" | ||
And I follow "Email petitioners" | ||
Then I should be on the admin email petitioners form page for "Ban Badger Baiting" | ||
And the markup should be valid | ||
When I press "Email 6 signatures" | ||
Then the petition should not have any emails | ||
And I should see an error | ||
When I fill in the email details | ||
And press "Email 6 signatures" | ||
Then the petition should have the email details I provided | ||
And the petition creator should have been emailed with the update | ||
And all the signatories of the petition should have been emailed with the update | ||
And the feedback email address should have been emailed a copy |
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,52 @@ | ||
When(/^I fill in the email details$/) do | ||
fill_in "Subject", :with => "Petition email subject" | ||
fill_in "Body", :with => "Petition email body" | ||
end | ||
|
||
Then(/^the petition should not have any emails$/) do | ||
@petition.reload | ||
expect(@petition.emails).to be_empty | ||
end | ||
|
||
Then(/^the petition should have the email details I provided$/) do | ||
@petition.reload | ||
@email = @petition.emails.last | ||
expect(@email.subject).to eq("Petition email subject") | ||
expect(@email.body).to match(%r[Petition email body]) | ||
expect(@email.sent_by).to eq("Admin User") | ||
end | ||
|
||
Then(/^the petition creator should have been emailed with the update$/) do | ||
@petition.reload | ||
steps %Q( | ||
Then "#{@petition.creator_signature.email}" should receive an email | ||
When they open the email | ||
Then they should see "Petition email body" in the email body | ||
When they follow "#{petition_url(@petition)}" in the email | ||
Then I should be on the petition page for "#{@petition.action}" | ||
) | ||
end | ||
|
||
Then(/^all the signatories of the petition should have been emailed with the update$/) do | ||
@petition.reload | ||
@petition.signatures.notify_by_email.validated.where.not(id: @petition.creator_signature.id).each do |signatory| | ||
steps %Q( | ||
Then "#{signatory.email}" should receive an email | ||
When they open the email | ||
Then they should see "Petition email body" in the email body | ||
When they follow "#{petition_url(@petition)}" in the email | ||
Then I should be on the petition page for "#{@petition.action}" | ||
) | ||
end | ||
end | ||
|
||
Then(/^the feedback email address should have been emailed a copy$/) do | ||
signatory = FeedbackSignature.new(@petition) | ||
steps %Q( | ||
Then "#{signatory.email}" should receive an email | ||
When they open the email | ||
Then they should see "Petition email body" in the email body | ||
When they follow "#{petition_url(@petition)}" in the email | ||
Then I should be on the petition page for "#{@petition.action}" | ||
) | ||
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
Oops, something went wrong.