Skip to content

Commit

Permalink
add custom message to modal
Browse files Browse the repository at this point in the history
  • Loading branch information
microstudi committed Feb 1, 2024
1 parent 9001c68 commit 13d4234
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 7 deletions.
4 changes: 4 additions & 0 deletions app/commands/concerns/amendable_accept_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ module AmendableAcceptOverride
extend ActiveSupport::Concern

included do
alias_method :original_notify_amendable_and_emendation_authors_and_followers, :notify_amendable_and_emendation_authors_and_followers

private

def notify_amendable_and_emendation_authors_and_followers
return original_notify_amendable_and_emendation_authors_and_followers unless @amendable.component.settings.limit_pending_amendments

affected_users = emendation.authors + @amendable.notifiable_identities
followers = emendation.followers + affected_users
# do not send the standard notification to the amnendable followers
Expand Down
6 changes: 5 additions & 1 deletion app/commands/concerns/amendable_reject_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ module AmendableRejectOverride
extend ActiveSupport::Concern

included do
alias_method :original_notify_emendation_authors_and_followers, :notify_emendation_authors_and_followers

private

def notify_emendation_authors_and_followers
return original_notify_emendation_authors_and_followers unless @amendable.component.settings.limit_pending_amendments

# do not send the standard notification to the amnendable followers
affected_users = @emendation.authors + @amendable.notifiable_identities
followers = @emendation.followers - affected_users
followers = @emendation.followers + affected_users

Decidim::EventsManager.publish(
event: "decidim.events.amendments.amendment_rejected",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- insert_before 'div.text-center' -->

<div class="instructions"><%= t("gpc.amendments.limit_modal.extra_html") %></div>
<br>
12 changes: 11 additions & 1 deletion app/packs/src/decidim/decidim_application.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,14 @@ import "iframe-resizer"
// Load images
require.context("../../images", true)

iFrameResize({ log: true }, '.auto-height-iframe')
iFrameResize({ log: true }, '.auto-height-iframe')

document.addEventListener("DOMContentLoaded", () => {
document.querySelector(".js-limit-amendment-follow-proposal").addEventListener("click", (evt) => {
evt.preventDefault();
const button = document.querySelector('.view-side form[action="/follow"] button')
if(button.querySelector('.text-wrap').innerText.indexOf("Follow") == 0) {
button.click();
}
});
});
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ en:
subject: Your invitation to the Green Party of Canada's Participatory Democracy Platform
email_not_registered: Sorry, the email %{email} is not registered. Only existing users are allowed to login.
gpc:
amendments:
limit_modal:
extra_html: You can also be notified when the current amendment is accepted or rejected by <a href="#" class="js-limit-amendment-follow-proposal">following this proposal</a> (you will receive a notification/email when the amendment is accepted or rejected depending on your notification preferences).
campaign_space: "%{name} Campaign"
chat_button: GREEN CHAT (beta)
donate: Donate to %{name}
Expand Down
77 changes: 72 additions & 5 deletions spec/system/limit_amendments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
let(:settings) { { amendments_enabled: amendments_enabled, limit_pending_amendments: limit_pending_amendments } }
let(:creator) { create(:user, :confirmed, organization: organization) }
let(:user) { create(:user, :confirmed, organization: organization) }
let(:amender) { create(:user, :confirmed, organization: organization) }
let(:follower) { create(:user, :confirmed, organization: organization) }
let!(:follow) { create :follow, user: follower, followable: proposal }

let!(:proposal) { create :proposal, users: [creator], component: component }
let!(:emendation) { create(:proposal, title: { en: "An emendation for the proposal" }, component: component) }
let!(:emendation) { create(:proposal, users: [amender], title: { en: "An emendation for the proposal" }, component: component) }
let!(:amendment) { create(:amendment, amendable: proposal, emendation: emendation, state: amendment_state) }

let(:amendment_state) { "evaluating" }
Expand Down Expand Up @@ -55,7 +56,7 @@ def amendment_path
within ".limit_amendments_modal" do
expect(page).to have_link(href: amendment_path)
expect(page).to have_content("Currently, there's another amendment being evaluated for this proposal.")
# TODO: check text with "follow" to be notified is present
expect(page).to have_content("You can also be notified when the current amendment is accepted or rejected")
end
end
end
Expand All @@ -70,13 +71,79 @@ def amendment_path
click_button "Accept amendment"
end

# TODO: check authors have received emails as creators
# todo: check followers have received emails as followers (if not already creators)
emails.each do |email|
expect(email.subject).to have_content("Accepted amendment for")
case email.to.first
when follower.email
expect(email.text_part.to_s).to have_content("If you are planning to make an amendment yourself")
else
expect(email.text_part.to_s).not_to have_content("If you are planning to make an amendment yourself")
end
end
expect(page).to have_content("The amendment has been accepted successfully")
end

it "can be rejected" do
# todo
click_link "An emendation for the proposal"
perform_enqueued_jobs do
click_link "Reject"
end

emails.each do |email|
expect(email.subject).to have_content("Amendment rejected for")
case email.to.first
when follower.email
expect(email.text_part.to_s).to have_content("planning to make an amendment yourself")
else
expect(email.text_part.to_s).not_to have_content("planning to make an amendment yourself")
end
end
expect(page).to have_content("The amendment has been successfully rejected")
end
end

context "when amendments are not limited" do
let(:limit_pending_amendments) { false }

it "can create a new one" do
expect(page).to have_content(proposal.title["en"])
expect(page).to have_content(emendation.title["en"])
click_link "Amend"

expect(page).not_to have_content("Currently, there's another amendment being evaluated for this proposal.")
expect(page).not_to have_content(proposal.title["en"])
expect(page).to have_content("CREATE AMENDMENT DRAFT")
end

context "when the author is logged" do
let(:logged_user) { creator }

it "can be accepted" do
click_link "An emendation for the proposal"
click_link "Accept"
perform_enqueued_jobs do
click_button "Accept amendment"
end

emails.each do |email|
expect(email.subject).to have_content("Accepted amendment for")
expect(email.text_part.to_s).not_to have_content("If you are planning to make an amendment yourself")
end
expect(page).to have_content("The amendment has been accepted successfully")
end

it "can be rejected" do
click_link "An emendation for the proposal"
perform_enqueued_jobs do
click_link "Reject"
end

emails.each do |email|
expect(email.subject).to have_content("Amendment rejected for")
expect(email.text_part.to_s).not_to have_content("planning to make an amendment yourself")
end
expect(page).to have_content("The amendment has been successfully rejected")
end
end
end
end

0 comments on commit 13d4234

Please sign in to comment.