Skip to content

Commit

Permalink
feat: Allow admins to toggle notification sending
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentinchampenois committed Nov 13, 2024
1 parent 52e4dcb commit 0e9a7fa
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/commands/decidim/admin/create_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def build_attachment

def notify_followers
return unless @attachment.attached_to.is_a?(Decidim::Followable)
return unless form.send_notification_to_followers

Decidim::EventsManager.publish(
event: "decidim.events.attachments.attachment_created",
Expand Down
2 changes: 1 addition & 1 deletion app/forms/decidim/admin/attachment_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AttachmentForm < Form
translatable_attribute :description, String
attribute :weight, Integer, default: 0
attribute :attachment_collection_id, Integer
attribute :send_notification, Boolean, default: false
attribute :send_notification_to_followers, Boolean, default: false

mimic :attachment

Expand Down
33 changes: 33 additions & 0 deletions app/views/decidim/admin/attachments/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div class="card">
<div class="card-divider">
<h2 class="card-title">
<%= title %>
</h2>
</div>

<div class="card-section">
<div class="row column">
<%= form.translated :text_field, :title, autofocus: true %>
</div>

<div class="row column">
<%= form.number_field :weight %>
</div>

<div class="row column">
<%= form.translated :text_field, :description %>
</div>

<div class="row column">
<%= form.select :attachment_collection_id, @form.attachment_collections.collect { |c| [translated_attribute(c.name), c.id] }, include_blank: true %>
</div>

<div class="row column">
<%= form.upload :file, required: true %>
</div>

<div class="row column">
<%= form.check_box :send_notification_to_followers, label: t(".send_notification_to_followers") %>
</div>
</div>
</div>
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ en:
file: importing file
decidim:
admin:
attachments:
form:
send_notification_to_followers: Send a notification to all the people following the consultation who have agreed to receive email notifications
exports:
export_as: "%{name} as %{export_format}"
notice: Your export is currently in progress. You'll receive an email when it's complete.
Expand Down
3 changes: 3 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ fr:
file: importer un fichier d'utilisateurs
decidim:
admin:
attachments:
form:
send_notification_to_followers: Envoyer une notification à toutes les personnes qui suivent la concertation ayant accepté de recevoir des notifications par mail
exports:
export_as: "%{name} au format %{export_format}"
notice: Votre exportation est en cours. Vous recevrez un e-mail quand elle sera terminée.
Expand Down
16 changes: 16 additions & 0 deletions spec/commands/decidim/admin/create_attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Decidim::Admin
describe CreateAttachment do
subject { described_class.call(form, attached_to, user) }
let(:user) { create(:user) }
let(:send_notification) { true }
let(:form) do
instance_double(
AttachmentForm,
Expand All @@ -21,6 +22,7 @@ module Decidim::Admin
},
file: file,
attachment_collection: nil,
send_notification_to_followers: send_notification,
weight: 0
)
end
Expand Down Expand Up @@ -58,6 +60,20 @@ module Decidim::Admin
subject
end

context "when send notification option is false" do
let(:send_notification) { false }

it "does not notify the followers" do
follower = create(:user, organization: attached_to.organization)
create(:follow, followable: attached_to, user: follower)

expect(Decidim::EventsManager)
.not_to receive(:publish)

subject
end
end

it "traces the action", versioning: true do
expect(Decidim.traceability)
.to receive(:perform_action!)
Expand Down

0 comments on commit 0e9a7fa

Please sign in to comment.