Skip to content

Commit

Permalink
Merge pull request #9040 from CitizenLabDotCo/TAN-2224/co-sponsors-em…
Browse files Browse the repository at this point in the history
…ails

TAN-2224/co sponsors emails
  • Loading branch information
kogre authored Oct 2, 2024
2 parents 56e4512 + 8deb594 commit 00ad895
Show file tree
Hide file tree
Showing 15 changed files with 432 additions and 1 deletion.
2 changes: 1 addition & 1 deletion back/app/services/side_fx_idea_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def sanitize_location_point(change)
end

def log_activities_if_cosponsors_added(idea, user, old_cosponsor_ids)
added_ids = idea.reload.cosponsors.map(&:id) - old_cosponsor_ids
added_ids = idea.cosponsors.map(&:id) - old_cosponsor_ids
if added_ids.present?
new_cosponsorships = idea.cosponsorships.where(user_id: added_ids)
new_cosponsorships.each do |cosponsorship|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module EmailCampaigns
class CosponsorOfYourIdeaMailer < ApplicationMailer
protected

def subject
format_message('subject', values: { cosponsorName: event.post_cosponsor_name })
end

def header_title
format_message('main_header', values: { cosponsorName: event.post_cosponsor_name })
end

private

def header_message
format_message('event_description', values: { cosponsorName: event.post_cosponsor_name })
end

def preheader
format_message('preheader', values: { cosponsorName: event.post_cosponsor_name })
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module EmailCampaigns
class InvitationToCosponsorIdeaMailer < ApplicationMailer
protected

def subject
format_message('subject')
end

def header_title
format_message('main_header')
end

private

def header_message
format_message('event_description', values: { authorName: event.post_author_name })
end

def preheader
format_message('preheader', values: { authorName: event.post_author_name })
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: email_campaigns_campaigns
#
# id :uuid not null, primary key
# type :string not null
# author_id :uuid
# enabled :boolean
# sender :string
# reply_to :string
# schedule :jsonb
# subject_multiloc :jsonb
# body_multiloc :jsonb
# created_at :datetime not null
# updated_at :datetime not null
# deliveries_count :integer default(0), not null
# context_id :uuid
#
# Indexes
#
# index_email_campaigns_campaigns_on_author_id (author_id)
# index_email_campaigns_campaigns_on_context_id (context_id)
# index_email_campaigns_campaigns_on_type (type)
#
# Foreign Keys
#
# fk_rails_... (author_id => users.id)
#
module EmailCampaigns
class Campaigns::CosponsorOfYourIdea < Campaign
include Consentable
include ActivityTriggerable
include RecipientConfigurable
include Disableable
include Trackable
include LifecycleStageRestrictable
allow_lifecycle_stages only: %w[trial active]

recipient_filter :filter_notification_recipient

def mailer_class
CosponsorOfYourIdeaMailer
end

def activity_triggers
{ 'Notifications::CosponsorOfYourIdea' => { 'created' => true } }
end

def filter_notification_recipient(users_scope, activity:, time: nil)
users_scope.where(id: activity.item.recipient.id)
end

def self.recipient_role_multiloc_key
'email_campaigns.admin_labels.recipient_role.registered_users'
end

def self.recipient_segment_multiloc_key
'email_campaigns.admin_labels.recipient_segment.user_who_published_the_proposal'
end

def self.content_type_multiloc_key
'email_campaigns.admin_labels.content_type.proposals'
end

def self.trigger_multiloc_key
'email_campaigns.admin_labels.trigger.user_accepts_invitation_to_cosponsor_a_proposal'
end

def generate_commands(recipient:, activity:)
idea = activity.item.post
cosponsor = activity.item.initiating_user
name_service = UserDisplayNameService.new(AppConfiguration.instance, recipient)

[{
event_payload: {
post_title_multiloc: idea.title_multiloc,
post_body_multiloc: idea.body_multiloc,
post_author_name: name_service.display_name!(idea.author),
post_cosponsor_name: name_service.display_name!(cosponsor),
post_url: Frontend::UrlService.new.model_to_url(idea, locale: Locale.new(recipient.locale)),
post_image_medium_url: post_image_medium_url(idea)
}
}]
end

private

def post_image_medium_url(idea)
image = idea&.idea_images&.first
image.image.versions[:medium].url if image&.image&.versions
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# frozen_string_literal: true

# == Schema Information
#
# Table name: email_campaigns_campaigns
#
# id :uuid not null, primary key
# type :string not null
# author_id :uuid
# enabled :boolean
# sender :string
# reply_to :string
# schedule :jsonb
# subject_multiloc :jsonb
# body_multiloc :jsonb
# created_at :datetime not null
# updated_at :datetime not null
# deliveries_count :integer default(0), not null
# context_id :uuid
#
# Indexes
#
# index_email_campaigns_campaigns_on_author_id (author_id)
# index_email_campaigns_campaigns_on_context_id (context_id)
# index_email_campaigns_campaigns_on_type (type)
#
# Foreign Keys
#
# fk_rails_... (author_id => users.id)
#
module EmailCampaigns
class Campaigns::InvitationToCosponsorIdea < Campaign
include Consentable
include ActivityTriggerable
include RecipientConfigurable
include Disableable
include Trackable
include LifecycleStageRestrictable
allow_lifecycle_stages only: %w[trial active]

recipient_filter :filter_notification_recipient

def mailer_class
InvitationToCosponsorIdeaMailer
end

def activity_triggers
{ 'Notifications::InvitationToCosponsorIdea' => { 'created' => true } }
end

def filter_notification_recipient(users_scope, activity:, time: nil)
users_scope.where(id: activity.item.recipient.id)
end

def self.recipient_role_multiloc_key
'email_campaigns.admin_labels.recipient_role.registered_users'
end

def self.recipient_segment_multiloc_key
'email_campaigns.admin_labels.recipient_segment.user_who_is_invited_to_cosponsor_a_proposal'
end

def self.content_type_multiloc_key
'email_campaigns.admin_labels.content_type.proposals'
end

def self.trigger_multiloc_key
'email_campaigns.admin_labels.trigger.user_is_invited_to_cosponsor_a_proposal'
end

def generate_commands(recipient:, activity:)
idea = activity.item.post
name_service = UserDisplayNameService.new(AppConfiguration.instance, recipient)

[{
event_payload: {
post_title_multiloc: idea.title_multiloc,
post_body_multiloc: idea.body_multiloc,
post_author_name: name_service.display_name!(idea.author),
post_url: Frontend::UrlService.new.model_to_url(idea, locale: Locale.new(recipient.locale)),
post_image_medium_url: post_image_medium_url(idea)
}
}]
end

private

def post_image_medium_url(idea)
image = idea&.idea_images&.first
image.image.versions[:medium].url if image&.image&.versions
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class DeliveryService
Campaigns::CommentOnInitiativeYouFollow,
Campaigns::CommentOnYourComment,
Campaigns::CosponsorOfYourInitiative,
Campaigns::CosponsorOfYourIdea,
Campaigns::EventRegistrationConfirmation,
Campaigns::IdeaMarkedAsSpam,
Campaigns::IdeaPublished,
Expand All @@ -27,6 +28,7 @@ class DeliveryService
Campaigns::InternalCommentOnUnassignedInitiative,
Campaigns::InternalCommentOnUnassignedUnmoderatedIdea,
Campaigns::InternalCommentOnYourInternalComment,
Campaigns::InvitationToCosponsorIdea,
Campaigns::InvitationToCosponsorInitiative,
Campaigns::InviteReceived,
Campaigns::InviteReminder,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%= render 'email_campaigns/posts/post_with_image', post_image_url: event&.post_image_medium_url, post_title_multiloc: event.post_title_multiloc, post_body_multiloc: event.post_body_multiloc %>
<%= render partial: 'application/cta_button', locals: { href: event.post_url, message: format_message('cta_reply_to', values: { authorName: event.post_author_name }) } %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<mj-section padding="0 25px 0 25px">
<mj-column>
<mj-text>
<p><%= format_message('event_description_cosponsoring', escape_html: false) %></p>
</mj-text>
</mj-column>
</mj-section>

<mj-section padding="0 25px 0 25px">
<mj-column>
<mj-text>
<p><%= format_message('event_description_before_action', escape_html: false) %></p>
</mj-text>
</mj-column>
</mj-section>

<mj-section padding="0 25px 0 25px">
<mj-column>
<mj-text>
<p><%= format_message('event_description_action') %></p>
</mj-text>
</mj-column>
</mj-section>

<%= render 'email_campaigns/posts/post_with_image', post_image_url: event&.post_image_medium_url, post_title_multiloc: event.post_title_multiloc, post_body_multiloc: event.post_body_multiloc %>
<%= render partial: 'application/cta_button', locals: { href: event.post_url, message: format_message('cta_reply_to', values: { authorName: event.post_author_name }) } %>
17 changes: 17 additions & 0 deletions back/engines/free/email_campaigns/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ en:
"comment_on_idea_you_follow": A comment on an idea that you follow
"comment_on_initiative_you_follow": A comment on a proposal that you follow
"cosponsor_of_your_initiative": A user accepts my invitation to co-sponsor my proposal
"cosponsor_of_your_idea": A user accepts my invitation to co-sponsor my proposal
"event_registration_confirmation": Event registration confirmation
"first_idea_published": Publication of my first idea
"idea_marked_as_spam": Idea spam report
Expand All @@ -18,6 +19,7 @@ en:
"initiative_marked_as_spam": Proposal spam report
"initiative_published": Publication of my proposal
"invitation_to_cosponsor_initiative": Invitation to co-sponsor a proposal
"invitation_to_cosponsor_idea": Invitation to co-sponsor a proposal
"initiative_resubmitted_for_review": Proposal resubmitted for review
"invite_received": Invitation
"invite_reminder": Invitation reminder
Expand Down Expand Up @@ -138,6 +140,12 @@ en:
today: Today
wrong_content: 'The comment is not relevant.'
yesterday: Yesterday
cosponsor_of_your_idea:
cta_reply_to: 'View your proposal'
event_description: 'Congratulations! %{cosponsorName} has accepted your invitation to co-sponsor your proposal.'
main_header: '%{cosponsorName} has accepted your invitation to co-sponsor your proposal'
subject: '%{cosponsorName} has accepted your invitation to co-sponsor your proposal'
preheader: '%{cosponsorName} has accepted your invitation to co-sponsor your proposal'
cosponsor_of_your_initiative:
cta_reply_to: 'View your proposal'
event_description_initiative: 'Congratulations! %{cosponsorName} has accepted your invitation to co-sponsor your proposal.'
Expand Down Expand Up @@ -181,6 +189,15 @@ en:
main_header: '%{firstName}, you have a new assignment'
subject: 'You have an assignment on the platform of %{organizationName}'
preheader_initiative: 'The proposal of %{authorName} has been assigned to you'
invitation_to_cosponsor_idea:
cta_reply_to: 'Co-sponsor this proposal'
event_description: '%{authorName} has created a new proposal and would like you to co-sponsor it.'
event_description_cosponsoring: 'Co-sponsoring a proposal means that <strong>your name will be displayed</strong> with the names of other co-sponsors of the proposal.'
event_description_before_action: 'To see the proposal and accept the invitation, you must be logged in to your account.'
event_description_action: 'Click below to read the proposal.'
main_header: 'You have been invited to co-sponsor a proposal'
subject: 'You have been invited to co-sponsor a proposal'
preheader: 'You have been invited to co-sponsor the proposal of %{authorName}'
invitation_to_cosponsor_initiative:
cta_reply_to: 'Co-sponsor this proposal'
event_description_initiative: '%{authorName} has created a new proposal and would like you to co-sponsor it.'
Expand Down
8 changes: 8 additions & 0 deletions back/engines/free/email_campaigns/spec/factories/campaigns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
enabled { true }
end

factory :cosponsor_of_your_idea_campaign, class: EmailCampaigns::Campaigns::CosponsorOfYourIdea do
enabled { true }
end

factory :idea_marked_as_spam_campaign, class: EmailCampaigns::Campaigns::IdeaMarkedAsSpam do
enabled { true }
end
Expand Down Expand Up @@ -114,6 +118,10 @@
enabled { true }
end

factory :invitation_to_cosponsor_idea_campaign, class: EmailCampaigns::Campaigns::InvitationToCosponsorIdea do
enabled { true }
end

factory :invitation_to_cosponsor_initiative_campaign, class: EmailCampaigns::Campaigns::InvitationToCosponsorInitiative do
enabled { true }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ en:
invitation_expiry_message: 'This invitation expires in %{expiryDays} days.'
preheader: '%{organizationName} sent you an invite to join their participation platform.'
subject: 'You are invited to join the platform of %{organizationName}'
invitation_to_cosponsor_idea:
cta_reply_to: 'Co-sponsor this proposal'
event_description: '%{authorName} has created a new proposal and would like you to co-sponsor it.'
event_description_cosponsoring: 'Co-sponsoring a proposal means that <strong>your name will be displayed</strong> with the names of other co-sponsors of the proposal'
event_description_before_action: 'To see the proposal and accept the invitation, you must be logged in to your account.'
event_description_action: 'Click below to read the proposal'
main_header: 'You have been invited to co-sponsor a proposal'
subject: 'You have been invited to co-sponsor a proposal'
preheader: 'You have been invited to co-sponsor the proposal of %{authorName}'
invitation_to_cosponsor_initative:
cta_reply_to: 'Co-sponsor this proposal'
event_description_initiative: '%{authorName} has created a new proposal and would like you to co-sponsor it.'
Expand Down
Loading

0 comments on commit 00ad895

Please sign in to comment.