diff --git a/app/decorators/decidim/amendable/edit_form_decorator.rb b/app/decorators/decidim/amendable/edit_form_decorator.rb
index 9ab509b..f27c73a 100644
--- a/app/decorators/decidim/amendable/edit_form_decorator.rb
+++ b/app/decorators/decidim/amendable/edit_form_decorator.rb
@@ -11,16 +11,4 @@ def map_model(model)
self.emendation_params = model.emendation.attributes.slice(*amendable_fields_as_string)
self.phone_number = model.amender.phone_number
end
-
- # Method added.
- # ProposalNote created in Decidim::Amendable::UpdateDraft.
- def proposal_note
- @proposal_note ||= Decidim::Proposals::ProposalNote.find_by(proposal: emendation, author: current_user)
- end
-
- # Method added.
- # The value to render in the :phone_number field at app/views/decidim/amendments/edit_draft.html.erb
- def phone_number_value
- proposal_note&.body || phone_number
- end
end
diff --git a/app/decorators/decidim/amendable/update_draft_decorator.rb b/app/decorators/decidim/amendable/update_draft_decorator.rb
index 75b1469..72143ba 100644
--- a/app/decorators/decidim/amendable/update_draft_decorator.rb
+++ b/app/decorators/decidim/amendable/update_draft_decorator.rb
@@ -10,7 +10,7 @@ def call
transaction do
update_draft
- handle_proposal_note
+ create_proposal_note
end
broadcast(:ok, @amendment)
@@ -29,15 +29,12 @@ def update_draft
end
# Method added.
- # Creates and/or updates or deletes the ProposalNote with the phone number.
- def handle_proposal_note
- proposal_note = Decidim::Proposals::ProposalNote.find_or_initialize_by(proposal: emendation, author: current_user)
-
- if form.phone_number.present?
- proposal_note&.update(body: form.phone_number)
- else
- proposal_note&.delete
- Decidim::Proposals::Proposal.reset_counters(emendation.id, :proposal_notes_count)
- end
+ # Creates a ProposalNote with the phone number.
+ def create_proposal_note
+ Decidim::Proposals::ProposalNote.find_or_create_by(
+ proposal: emendation,
+ author: current_user,
+ body: form.phone_number
+ )
end
end
diff --git a/app/views/decidim/amendments/edit_draft.html.erb b/app/views/decidim/amendments/edit_draft.html.erb
index 45b7b4f..3b8bdb0 100644
--- a/app/views/decidim/amendments/edit_draft.html.erb
+++ b/app/views/decidim/amendments/edit_draft.html.erb
@@ -20,8 +20,8 @@
<%= form.text_field :phone_number,
label: t(".phone_number"),
- help_text: t(".phone_number_help"),
- value: form.object.phone_number_value %>
+ help_text: t(".phone_number_help").html_safe,
+ readonly: true %>
diff --git a/config/locales/ca.yml b/config/locales/ca.yml
index 16027e6..a6c3ec9 100644
--- a/config/locales/ca.yml
+++ b/config/locales/ca.yml
@@ -16,8 +16,8 @@ ca:
discard: Descarta aquest esborrany
discard_confirmation: Estàs segur de que vols descartar aquest esborrany d'esmena?
phone_number: Telèfon de contacte
- phone_number_help: Siusplau, indica el teu telèfon de contacte per tal que
- la organització es pugui posar en contacte amb tu.
+ phone_number_help: Si aquest no és el teu telèfon de contacte, siusplau, posa't
+ en contacte amb administracio@erc.cat.
send: Vista prèvia
title: Completa l'esborrany d'esmena
emendation:
diff --git a/config/locales/en.yml b/config/locales/en.yml
index e0e7a0e..1c8ab90 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -4,5 +4,5 @@ en:
amendments:
edit_draft:
phone_number: Contact phone number
- phone_number_help: Please, review your phone number so the organization
- can contact you.
+ phone_number_help: Please, contact administracio@erc.cat if your data
+ is not up to date.
diff --git a/spec/system/amendments_wizard_spec.rb b/spec/system/amendments_wizard_spec.rb
index f07d88f..bcde410 100644
--- a/spec/system/amendments_wizard_spec.rb
+++ b/spec/system/amendments_wizard_spec.rb
@@ -77,93 +77,24 @@
it "show the phone_number field prefilled" do
within ".edit_amendment" do
- expect(page).to have_field("Contact phone number", with: "666-666-666")
- end
- end
-
- context "when the user leaves the phone number field prefilled as is" do
- before do
- within ".edit_amendment" do
- find("*[type=submit]").click
+ # Data returned from CiviCRM should be readonly and users must be informed.
+ expect(page).to have_field("Contact phone number", with: "666-666-666", readonly: true)
+ within "#amendment_phone_number" do
+ expect(page).to have_tag("p.help-text", text: /administracio@erc.cat/)
end
end
-
- it "creates a proposal note" do
- expect(emendation_draft.proposal_notes_count).to eq(1)
- expect(Decidim::Proposals::ProposalNote.last.body).to eq("666-666-666")
- end
end
- context "when the user fills the phone number field with another value" do
+ context "when the user submits the form" do
before do
within ".edit_amendment" do
- fill_in :amendment_phone_number, with: "999-999-999"
find("*[type=submit]").click
end
end
it "creates a proposal note" do
expect(emendation_draft.proposal_notes_count).to eq(1)
- expect(Decidim::Proposals::ProposalNote.last.body).to eq("999-999-999")
- end
- end
-
- context "when the user empties the phone number field" do
- before do
- within ".edit_amendment" do
- fill_in :amendment_phone_number, with: ""
- find("*[type=submit]").click
- end
- end
-
- it "does NOT create a proposal note" do
- expect(emendation_draft.proposal_notes_count).to eq(0)
- end
- end
- end
-
- context "and in step_4: Preview your amendment" do
- before do
- within ".new_amendment" do
- fill_in :amendment_emendation_params_title, with: title
- fill_in :amendment_emendation_params_body, with: body
- find("*[type=submit]").click
- end
- within ".edit_amendment" do
- find("*[type=submit]").click
- end
- end
-
- context "when the Modify link is clicked" do
- before do
- click_link "Modify"
- end
-
- context "and the empties the phone number field" do
- before do
- within ".edit_amendment" do
- fill_in :amendment_phone_number, with: ""
- find("*[type=submit]").click
- end
- end
-
- it "deletes the proposal note" do
- expect(emendation_draft.reload.proposal_notes_count).to eq(0)
- end
- end
-
- context "and updates the phone number field" do
- before do
- within ".edit_amendment" do
- fill_in :amendment_phone_number, with: "999-999-999"
- find("*[type=submit]").click
- end
- end
-
- it "updates the proposal note" do
- expect(emendation_draft.proposal_notes_count).to eq(1)
- expect(Decidim::Proposals::ProposalNote.last.body).to eq("999-999-999")
- end
+ expect(Decidim::Proposals::ProposalNote.last.body).to eq("666-666-666")
end
end
end