Add a federated P2P creation email

This commit is contained in:
Eric Schultz 2019-02-11 16:10:57 -06:00 committed by Eric Schultz
parent adeb9c46cb
commit 0916fe74c0
4 changed files with 69 additions and 1 deletions

View file

@ -6,4 +6,10 @@ class CampaignMailer < BaseMailer
@campaign = campaign
mail(:to => @creator_profile.user.email, :subject => "Get your new campaign rolling! (via #{Settings.general.name})")
end
def federated_creation_followup(campaign)
@creator_profile = campaign.profile
@campaign = campaign
mail(:to => @creator_profile.user.email, :subject => "Get your new campaign rolling! (via #{Settings.general.name})")
end
end

View file

@ -101,7 +101,12 @@ class Campaign < ActiveRecord::Base
after_create do
user = self.profile.user
Role.create(name: :campaign_editor, user_id: user.id, host: self)
CampaignMailer.delay.creation_followup(self)
if child_campaign?
CampaignMailer.delay.federated_creation_followup(self)
else
CampaignMailer.delay.creation_followup(self)
end
NonprofitAdminMailer.delay.supporter_fundraiser(self) unless QueryRoles.is_nonprofit_user?(user.id, self.nonprofit_id)
self
end

View file

@ -0,0 +1,31 @@
<%- # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -%>
<% campaign_url = Format::Url.concat(root_url, @campaign.url) %>
<p>Dear <%= @creator_profile.name.blank? ? @creator_profile.user.email : @creator_profile.name %>,</p>
<br>
<p>Congratulations on creating your campaign to support <%= @campaign.nonprofit.name %>!</p>
<br>
<p>You can visit it here: <strong><a href='<%= campaign_url %>'><%= campaign_url %></a></strong>.</p>
<br>
<p>Before you share your campaign with the world, we recommend you personalize
your campaign by including a testimonial in your words about why
you launched your campaign. You can also set a goal amount to inspire you and your donors.
To edit your campaign, <strong><a href="<%= "#{profile_url(@creator_profile)}/fundraisers" %>">visit your fundraisers</a></strong> (you may be asked to login)
and select <strong><a href='<%= campaign_url %>'><%= @campaign.name%></a></strong>.</p>
<br>
<p>Make sure to tell your friends and family why they should support your cause and how their contributions will make a difference. Your words and your passion can make a big difference.
Share your fundraiser on:</p>
<ul>
<%- if ENV['FACEBOOK_APP_ID'] -%>
<li><%= link_to("Facebook", "https://www.facebook.com/dialog/feed?app_id=#{ENV['FACEBOOK_APP_ID']}&display=popup&caption=#{url_encode(@campaign.name)}&link=#{campaign_url}") %></li>
<%- end -%>
<li><%= link_to("Twitter", "https://twitter.com/intent/tweet?url=#{campaign_url}&via=#{Settings.general.name}&text=#{url_encode("Join me in supporting: #{@campaign.name}")}") %></li>
<li>Or copy and paste the link above into an email to your friends and family</li>
</ul>
<p>If you need some help getting your campaign up and running, don't hesitate to contact <strong><%= Settings.devise.mailer_sender %></strong>.</p>
<%= render 'emails/sig' %>

View file

@ -0,0 +1,26 @@
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
require 'rails_helper'
RSpec.describe Campaign, type: :model do
describe 'sends correct email based on type of campaign' do
let(:nonprofit) { force_create(:nonprofit)}
let(:parent_campaign) { force_create(:campaign, name: 'Parent campaign', nonprofit: nonprofit) }
let(:child_campaign) do
force_create(:campaign,
name: 'Child campaign',
parent_campaign_id: parent_campaign.id,
slug: "twehotiheiotheiofnieoth",
goal_amount_dollars: "1000", nonprofit: nonprofit )
end
it 'parent campaign sends out general campaign email' do
expect { parent_campaign }.to change { ActionMailer::Base.deliveries.count }.by(1)
expect(ActionMailer::Base.deliveries.last.body.include?("Create one-time or recurring")).to be_truthy
end
it 'child campaign sends out federated campaign email' do
expect { child_campaign}.to change { ActionMailer::Base.deliveries.count }.by(2)
expect(ActionMailer::Base.deliveries.last.body.include?("including a testimonial")).to be_truthy
end
end
end