From 334f82dfa415e3d209afeaea43792518aa062fee Mon Sep 17 00:00:00 2001 From: Alexandru Emil Lupu Date: Sat, 12 Oct 2024 01:24:48 +0300 Subject: [PATCH] Compatibility changes --- Gemfile.lock | 1 + decidim-generators/Gemfile.lock | 1 + .../proposals/admin/create_proposal_state.rb | 33 ++++++++++++++++--- .../proposals/admin/destroy_proposal_state.rb | 25 +++++++++++++- .../proposals/admin/update_proposal_state.rb | 31 +++++++++++++++-- .../admin/proposal_states_controller.rb | 2 +- .../admin/valuator_manages_proposals_spec.rb | 2 +- .../admin/proposal_answer_template_chooser.js | 2 ++ ...tor_uses_proposal_answer_templates_spec.rb | 5 +-- 9 files changed, 90 insertions(+), 12 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 78ebd65465d54..9c45f96dc44ed 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -190,6 +190,7 @@ PATH decidim-templates (0.28.4) decidim-core (= 0.28.4) decidim-forms (= 0.28.4) + decidim-proposals (= 0.28.4) decidim-verifications (0.28.4) decidim-core (= 0.28.4) diff --git a/decidim-generators/Gemfile.lock b/decidim-generators/Gemfile.lock index c183487fa4346..b01212abd2f3e 100644 --- a/decidim-generators/Gemfile.lock +++ b/decidim-generators/Gemfile.lock @@ -190,6 +190,7 @@ PATH decidim-templates (0.28.4) decidim-core (= 0.28.4) decidim-forms (= 0.28.4) + decidim-proposals (= 0.28.4) decidim-verifications (0.28.4) decidim-core (= 0.28.4) diff --git a/decidim-proposals/app/commands/decidim/proposals/admin/create_proposal_state.rb b/decidim-proposals/app/commands/decidim/proposals/admin/create_proposal_state.rb index c722d2ed29fab..00c6df6de6c23 100644 --- a/decidim-proposals/app/commands/decidim/proposals/admin/create_proposal_state.rb +++ b/decidim-proposals/app/commands/decidim/proposals/admin/create_proposal_state.rb @@ -3,11 +3,36 @@ module Decidim module Proposals module Admin - class CreateProposalState < Decidim::Commands::CreateResource - fetch_form_attributes :title, :text_color, :bg_color, :announcement_title, :component + class CreateProposalState < Decidim::Command + # Public: Initializes the command. + # + # form - A form object with the params. + def initialize(form) + @form = form + end + + # Executes the command. Broadcasts these events: + # + # - :ok when everything is valid, together with the proposal. + # - :invalid if the form was not valid and we could not proceed. + # + # Returns nothing. + def call + return broadcast(:invalid) if @form.invalid? + + transaction do + Decidim.traceability.create!( + Decidim::Proposals::ProposalState, + @form.current_user, + title: @form.title, + text_color: @form.text_color, + bg_color: @form.bg_color, + announcement_title: @form.announcement_title, + component: @form.current_component + ) + end - def resource_class - Decidim::Proposals::ProposalState + broadcast(:ok) end end end diff --git a/decidim-proposals/app/commands/decidim/proposals/admin/destroy_proposal_state.rb b/decidim-proposals/app/commands/decidim/proposals/admin/destroy_proposal_state.rb index c97253959f16f..49218b2868f0e 100644 --- a/decidim-proposals/app/commands/decidim/proposals/admin/destroy_proposal_state.rb +++ b/decidim-proposals/app/commands/decidim/proposals/admin/destroy_proposal_state.rb @@ -3,7 +3,30 @@ module Decidim module Proposals module Admin - class DestroyProposalState < Decidim::Commands::DestroyResource + class DestroyProposalState < Decidim::Command + # Initializes an UpdateResult Command. + # + # result - The current instance of the proposal state to be destroyed. + # current_user - the user performing the action + def initialize(state, current_user) + @state = state + @current_user = current_user + end + + # Destroys the result. + # + # Broadcasts :ok if successful, :invalid otherwise. + def call + Decidim.traceability.perform_action!( + :delete, + @state, + @current_user + ) do + @state.destroy! + end + + broadcast(:ok) + end end end end diff --git a/decidim-proposals/app/commands/decidim/proposals/admin/update_proposal_state.rb b/decidim-proposals/app/commands/decidim/proposals/admin/update_proposal_state.rb index e0c3105f96b5c..086687b91a62a 100644 --- a/decidim-proposals/app/commands/decidim/proposals/admin/update_proposal_state.rb +++ b/decidim-proposals/app/commands/decidim/proposals/admin/update_proposal_state.rb @@ -3,10 +3,35 @@ module Decidim module Proposals module Admin - class UpdateProposalState < Decidim::Commands::UpdateResource - include TranslatableAttributes + class UpdateProposalState < Decidim::Command + # Initializes an UpdateResult Command. + # + # form - The form from which to get the data. + # state - The current instance of the proposal state to be updated. + def initialize(form, state) + @form = form + @state = state + end - fetch_form_attributes :title, :text_color, :bg_color, :announcement_title, :component + # Updates the result if valid. + # + # Broadcasts :ok if successful, :invalid otherwise. + def call + return broadcast(:invalid) if @form.invalid? + + transaction do + Decidim.traceability.update!( + @state, + @form.current_user, + title: @form.title, + text_color: @form.text_color, + bg_color: @form.bg_color, + announcement_title: @form.announcement_title, + component: @form.current_component + ) + end + broadcast(:ok) + end end end end diff --git a/decidim-proposals/app/controllers/decidim/proposals/admin/proposal_states_controller.rb b/decidim-proposals/app/controllers/decidim/proposals/admin/proposal_states_controller.rb index 92540ebdf1e84..a9c1b729ed2b6 100644 --- a/decidim-proposals/app/controllers/decidim/proposals/admin/proposal_states_controller.rb +++ b/decidim-proposals/app/controllers/decidim/proposals/admin/proposal_states_controller.rb @@ -4,7 +4,7 @@ module Decidim module Proposals module Admin class ProposalStatesController < Admin::ApplicationController - include Decidim::Admin::Paginable + include Decidim::Paginable helper_method :proposal_states, :proposal_state def index diff --git a/decidim-proposals/spec/system/admin/valuator_manages_proposals_spec.rb b/decidim-proposals/spec/system/admin/valuator_manages_proposals_spec.rb index 73b037a1fd8eb..5e67c906276b8 100644 --- a/decidim-proposals/spec/system/admin/valuator_manages_proposals_spec.rb +++ b/decidim-proposals/spec/system/admin/valuator_manages_proposals_spec.rb @@ -45,7 +45,7 @@ end it "cannot unassign others" do - expect(page).to have_no_content("Unassign from valuator") + expect(page).not_to have_content("Unassign from valuator") end end diff --git a/decidim-templates/app/packs/src/decidim/templates/admin/proposal_answer_template_chooser.js b/decidim-templates/app/packs/src/decidim/templates/admin/proposal_answer_template_chooser.js index 60e344125fdcd..94220485dabef 100644 --- a/decidim-templates/app/packs/src/decidim/templates/admin/proposal_answer_template_chooser.js +++ b/decidim-templates/app/packs/src/decidim/templates/admin/proposal_answer_template_chooser.js @@ -19,6 +19,7 @@ document.addEventListener("DOMContentLoaded", () => { return Promise.reject(response); }). then((data) => { + console.error(JSON.stringify(data)); document.getElementById(`proposal_answer_internal_state_${data.state}`).click(); let editorContainer = null; @@ -30,6 +31,7 @@ document.addEventListener("DOMContentLoaded", () => { } }). catch((response) => { + console.error(response); response.json().then((data) => { const el = document.createElement("p"); el.classList.add("text-alert"); diff --git a/decidim-templates/spec/system/admin/valuator_uses_proposal_answer_templates_spec.rb b/decidim-templates/spec/system/admin/valuator_uses_proposal_answer_templates_spec.rb index fbe4040136ee0..6852a0596cc52 100644 --- a/decidim-templates/spec/system/admin/valuator_uses_proposal_answer_templates_spec.rb +++ b/decidim-templates/spec/system/admin/valuator_uses_proposal_answer_templates_spec.rb @@ -3,7 +3,7 @@ require "spec_helper" describe "Valuator uses proposal answer templates" do - let(:field_values) { { internal_state: :rejected } } + let(:field_values) { { proposal_state_id: } } let(:token) { "rejected" } let!(:organization) { create(:organization) } let(:user) { create(:user, :confirmed, :admin_terms_accepted, organization:) } @@ -11,6 +11,7 @@ let!(:valuation_assignment) { create(:valuation_assignment, proposal:, valuator_role:) } let(:participatory_space) { create(:participatory_process, title: { en: "A participatory process" }, organization:) } let!(:templatable) { create(:proposal_component, name: { en: "A component" }, participatory_space:) } + let(:proposal_state_id) { Decidim::Proposals::ProposalState.find_by(component: templatable, token:).id } let(:description) { "Some meaningful answer" } let!(:template) { create(:template, target: :proposal_answer, description: { en: description }, organization:, templatable:, field_values:) } let!(:proposal) { create(:proposal, component: templatable) } @@ -31,7 +32,7 @@ expect(page).not_to have_select(:proposal_answer_template_chooser, with_options: [translated(other_component_template.name)]) select template.name["en"], from: :proposal_answer_template_chooser expect(page).to have_content(description) - click_on "Answer" + click_button "Answer" end expect(page).to have_admin_callout("Proposal successfully answered")