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

Feat: add author notification on proposal publication #1252

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def call
increment_scores
send_notification
send_notification_to_participatory_space
send_publication_notification
end

broadcast(:ok, @proposal)
Expand Down Expand Up @@ -87,6 +88,17 @@ def send_notification_to_participatory_space
)
end

def send_publication_notification
Decidim::EventsManager.publish(
event: "decidim.events.proposals.author_confirmation_proposal_event",
event_class: Decidim::Proposals::AuthorConfirmationProposalEvent,
resource: @proposal,
affected_users: [@proposal.creator_identity],
extra: { force_email: true },
force_send: true
)
end

def coauthors_followers
@coauthors_followers ||= @proposal.authors.flat_map(&:followers)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Decidim
module Proposals
class AuthorConfirmationProposalEvent < Decidim::Events::SimpleEvent
def self.model_name
ActiveModel::Name.new(self, nil, I18n.t("decidim.events.proposals.author_confirmation_proposal_event.email_subject"))
end

def resource_title
decidim_sanitize_translated(resource.title)
end
end
end
end
5 changes: 5 additions & 0 deletions decidim-proposals/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ en:
email_outro: You have received this notification because you are the author of the note.
email_subject: "%{author_name} has replied your private note in %{resource_title}."
notification_title: <a href="%{author_path}">%{author_name} %{author_nickname}</a> has replied your private note in <a href="%{resource_path}">%{resource_title}</a>. Check it out at <a href="%{admin_proposal_info_path}">the admin panel</a>.
author_confirmation_proposal_event:
email_intro: 'Your proposal " %{resource_title} " was successfully received and is now public. Thank you for participating ! You can view it here:'
email_outro: You received this notification because you are the author of the proposal. You can unfollow it by visiting the proposal page (" %{resource_title} ") and clicking on " Unfollow ".
email_subject: Your proposal has been published!
notification_title: Your proposal <a href="%{resource_path}">%{resource_title}</a> is now live.
coauthor_accepted_invite:
notification_title: <a href="%{coauthor_path}">%{coauthor_name}</a> has accepted your invitation to become a co-author of the proposal <a href="%{resource_path}">%{resource_title}</a>.
coauthor_invited:
Expand Down
5 changes: 5 additions & 0 deletions decidim-proposals/config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ fr:
email_outro: Vous avez reçu cette notification parce que vous êtes l'auteur/autrice de la note.
email_subject: "%{author_name} a répondu à votre note privée dans %{resource_title}."
notification_title: <a href="%{author_path}">%{author_name} %{author_nickname}</a> a répondu à votre note privée dans <a href="%{resource_path}">%{resource_title}</a>. Consultez-la sur <a href="%{admin_proposal_info_path}">le panneau d'administration</a>.
author_confirmation_proposal_event:
email_intro: 'Votre proposition « %{resource_title} » a été reçue avec succès et est maintenant publique. Merci pour votre participation ! Vous pouvez la consulter ici :'
email_outro: Vous recevez cette notification car vous êtes l’auteur de la proposition. Vous pouvez vous désabonner en visitant la page de la proposition (« %{resource_title} ») et en cliquant sur « Ne plus suivre ».
email_subject: Votre proposition a été publiée !
notification_title: Votre proposition <a href="%{resource_path}">%{resource_title}</a> est maintenant en ligne.
coauthor_accepted_invite:
notification_title: <a href="%{coauthor_path}">%{coauthor_name}</a> a accepté votre invitation à devenir co-auteur de la proposition <a href="%{resource_path}">%{resource_title}</a>.
coauthor_invited:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ module Proposals
}
)

expect(Decidim::EventsManager)
.to receive(:publish)
.with(
event: "decidim.events.proposals.author_confirmation_proposal_event",
event_class: Decidim::Proposals::AuthorConfirmationProposalEvent,
resource: kind_of(Decidim::Proposals::Proposal),
affected_users: [proposal_draft.creator_identity],
extra: { force_email: true },
force_send: true
)

subject.call
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require "spec_helper"

module Decidim
module Proposals
describe AuthorConfirmationProposalEvent do
let(:resource) { create(:proposal) }
let(:participatory_process) { create(:participatory_process, organization:) }
let(:proposal_component) { create(:proposal_component, participatory_space: participatory_process) }
let(:event_name) { "decidim.events.proposals.author_confirmation_proposal_event" }

include_context "when a simple event"

it_behaves_like "a simple event"

describe "resource_title" do
it "returns the proposal title" do
expect(subject.resource_title).to eq(decidim_sanitize_translated(resource.title))
end
end
end
end
end
Loading