Skip to content

Commit

Permalink
Compatibility changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alecslupu committed Oct 12, 2024
1 parent 00a15be commit 334f82d
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 12 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions decidim-generators/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
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:) }
let!(:valuator_role) { create(:participatory_process_user_role, role: :valuator, user:, participatory_process: participatory_space) }
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) }
Expand All @@ -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")
Expand Down

0 comments on commit 334f82d

Please sign in to comment.