Skip to content

Commit

Permalink
Add notification to valuators when a proposal is assigned (decidim#13022
Browse files Browse the repository at this point in the history
)

* Add notification to valuators when a proposal is assigned to them. Also adds a new notifications setting to disable this notification

* Update decidim-core/spec/commands/decidim/update_notifications_settings_spec.rb

Co-authored-by: Eduardo Martínez <[email protected]>

---------

Co-authored-by: Eduardo Martínez <[email protected]>
  • Loading branch information
2 people authored and fblupi committed Oct 31, 2024
1 parent bd07656 commit 09d0799
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def update_notifications_settings
@user.notification_types = @form.notification_types
@user.direct_message_types = @form.direct_message_types
@user.email_on_moderations = @form.email_on_moderations
@user.email_on_assigned_proposals = @form.email_on_assigned_proposals
@user.notification_settings = @user.notification_settings.merge(@form.notification_settings)
@user.notifications_sending_frequency = @form.notifications_sending_frequency
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class NotificationsSettingsForm < Form
mimic :user

attribute :email_on_moderations, Boolean
attribute :email_on_assigned_proposals, Boolean
attribute :newsletter_notifications, Boolean
attribute :notifications_from_followed, Boolean
attribute :notifications_from_own_activity, Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,28 @@
</label>
</div>

<label>
<%= t("valuators", scope: "decidim.notifications_settings.show") %>
</label>
<div class="toggle__switch-trigger">
<label for="email_on_assigned_proposals" class="toggle__switch-toggle">
<span>
<input
<%== %(checked="checked") if @notifications_settings.email_on_assigned_proposals %>
id="email_on_assigned_proposals"
type="checkbox"
name="email_on_assigned_proposals">
<span class="toggle__switch-toggle-content">
</span>
<%= icon "check-line", class: "toggle__switch-toggle-icon" %>
<%= icon "close-line", class: "toggle__switch-toggle-icon" %>
</span>
<span class="toggle__switch-trigger-text">
<%= t("assigned_to_proposal", scope: "decidim.notifications_settings.show") %>
</span>
</label>
</div>

<% if current_user.moderator? %>
<label>
<%= t("administrators", scope: "decidim.notifications_settings.show") %>
Expand Down
2 changes: 2 additions & 0 deletions decidim-core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,7 @@ en:
administrators: Administrators
allow_public_contact: Allow anyone to send me a direct message, even if I do not follow them.
allow_push_notifications: Get push notifications to find out what is going on when you are not on the platform. You can turn them off anytime.
assigned_to_proposal: I want to receive an email when someone assigns me a proposal to evaluate
direct_messages: Receive direct messages from anyone
email_on_moderations: I want to receive an email every time something or someone is reported for moderation.
everything_followed: Everything I follow
Expand All @@ -1278,6 +1279,7 @@ en:
push_notifications_reminder: To get notifications from the platform, you will need to allow them in your browser settings first.
receive_notifications_about: I want to get notifications about
update_notifications_settings: Save changes
valuators: Evaluators
update:
error: There was a problem updating your notifications settings.
success: Your notifications settings were successfully updated.
Expand Down
1 change: 1 addition & 0 deletions decidim-core/lib/decidim/core/test/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def generate_localized_title(field = nil, skip_injection: false)
accepted_tos_version { organization.tos_version }
notifications_sending_frequency { "real_time" }
email_on_moderations { true }
email_on_assigned_proposals { true }
password_updated_at { Time.current }
previous_passwords { [] }
extended_data { {} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module Decidim
let(:valid) { true }
let(:data) do
{
email_on_moderations: true,
email_on_moderations: false,
email_on_assigned_proposals: false,
newsletter_notifications_at: Time.current,
direct_message_types: "followed-only",
notification_settings: { close_meeting_reminder: "0" },
Expand All @@ -21,6 +22,7 @@ module Decidim
double(
notification_types: "none",
email_on_moderations: data[:email_on_moderations],
email_on_assigned_proposals: data[:email_on_assigned_proposals],
newsletter_notifications_at: data[:newsletter_notifications_at],
direct_message_types: data[:direct_message_types],
notification_settings: data[:notification_settings],
Expand Down Expand Up @@ -48,6 +50,8 @@ module Decidim
expect(user.direct_message_types).to eq "followed-only"
expect(user.notification_settings["close_meeting_reminder"]).to eq "0"
expect(user.notifications_sending_frequency).to eq "weekly"
expect(user.email_on_moderations).to be(false)
expect(user.email_on_assigned_proposals).to be(false)
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions decidim-core/spec/forms/notifications_settings_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Decidim
notifications_from_own_activity:,
notifications_sending_frequency:,
email_on_moderations:,
email_on_assigned_proposals:,
newsletter_notifications:,
allow_public_contact:
).with_context(
Expand All @@ -22,6 +23,7 @@ module Decidim
let(:notifications_from_followed) { "1" }
let(:notifications_from_own_activity) { "1" }
let(:email_on_moderations) { "1" }
let(:email_on_assigned_proposals) { "1" }
let(:newsletter_notifications) { "1" }
let(:allow_public_contact) { "1" }
let(:notifications_sending_frequency) { "real_time" }
Expand Down
1 change: 1 addition & 0 deletions decidim-core/spec/system/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@

it "updates the administrator's notifications" do
page.find("[for='email_on_moderations']").click
page.find("[for='email_on_assigned_proposals']").click
page.find("[for='user_notification_settings[close_meeting_reminder]']").click

within "form.edit_user" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def assign_proposals
form.proposals.flat_map do |proposal|
form.valuator_roles.each do |valuator_role|
find_assignment(proposal, valuator_role) || assign_proposal(proposal, valuator_role)
notify_valuator(proposal, valuator_role)
end
end
end
Expand All @@ -57,6 +58,19 @@ def assign_proposal(proposal, valuator_role)
valuator_role:
)
end

def notify_valuator(proposal, valuator_role)
return unless valuator_role.user.email_on_assigned_proposals?

data = {
event: "decidim.events.proposals.admin.proposal_assigned_to_valuator",
event_class: Decidim::Proposals::Admin::ProposalAssignedToValuatorEvent,
resource: proposal,
affected_users: [valuator_role.user]
}

Decidim::EventsManager.publish(**data)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Decidim
module Proposals
module Admin
class ProposalAssignedToValuatorEvent < Decidim::Events::SimpleEvent
include Rails.application.routes.mounted_helpers

i18n_attributes :admin_proposal_info_url, :admin_proposal_info_path

def admin_proposal_info_path
ResourceLocatorPresenter.new(resource).show
end

def admin_proposal_info_url
send(resource.component.mounted_admin_engine).proposal_url(resource, resource.component.mounted_params)
end

private

def organization
@organization ||= component.participatory_space.organization
end
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 @@ -235,6 +235,11 @@ en:
events:
proposals:
admin:
proposal_assigned_to_valuator:
email_intro: You have been assigned as a valuator to the proposal "%{resource_title}". This means you have been trusted to give them feedback and a proper response in the next coming days. Check it out at <a href="%{admin_proposal_info_url}">the admin panel</a>.
email_outro: You have received this notification because you can valuate the proposal.
email_subject: You have been assigned as a valuator to the proposal %{resource_title}.
notification_title: You have been assigned as a valuator to the proposal <a href="%{resource_path}">%{resource_title}</a>. Check it out at <a href="%{admin_proposal_info_path}">the admin panel</a>.
proposal_note_created:
email_intro: Someone has left a note on the proposal "%{resource_title}". Check it out at <a href="%{admin_proposal_info_url}">the admin panel</a>.
email_outro: You have received this notification because you can valuate the proposal.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddEmailOnAssignedProposalsToUsers < ActiveRecord::Migration[6.1]
def change
add_column :decidim_users, :email_on_assigned_proposals, :boolean, default: true
end
end

0 comments on commit 09d0799

Please sign in to comment.