Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Addition of custom proposal states #574

Merged
merged 8 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ gem "decidim-anonymous_proposals", DECIDIM_ANONYMOUS_PROPOSALS_VERSION
gem "decidim-budget_category_voting", git: "https://github.com/alecslupu-pfa/decidim-budget_category_voting.git", branch: DECIDIM_BRANCH
gem "decidim-cache_cleaner"
gem "decidim-category_enhanced", "~> 0.0.1"
gem "decidim-custom_proposal_states", git: "https://github.com/alecslupu-pfa/decidim-module-custom_proposal_states", branch: DECIDIM_BRANCH
gem "decidim-decidim_awesome", git: "https://github.com/decidim-ice/decidim-module-decidim_awesome", branch: "main"
gem "decidim-extended_socio_demographic_authorization_handler", git: "https://github.com/OpenSourcePolitics/decidim-module-extended_socio_demographic_authorization_handler.git",
branch: DECIDIM_BRANCH
Expand Down
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ GIT
decidim-core (~> 0.27.0)
deface (>= 1.9)

GIT
remote: https://github.com/alecslupu-pfa/decidim-module-custom_proposal_states
revision: 66bc4d1a9f00eb66356e583365597e737e1d6917
branch: release/0.27-stable
specs:
decidim-custom_proposal_states (0.27.5)
decidim-core (~> 0.27)
decidim-proposals (~> 0.27)
deface (>= 1.9)

GIT
remote: https://github.com/decidim-ice/decidim-module-decidim_awesome
revision: 058af7db47737e3ca108ac8e08efd5ec55d67a44
Expand Down Expand Up @@ -1154,6 +1164,7 @@ DEPENDENCIES
decidim-cache_cleaner
decidim-category_enhanced (~> 0.0.1)
decidim-conferences (~> 0.27.0)
decidim-custom_proposal_states!
decidim-decidim_awesome!
decidim-dev (~> 0.27.0)
decidim-extended_socio_demographic_authorization_handler!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true
# This migration comes from decidim_custom_proposal_states (originally 20231102173159)

class CreateDecidimProposalsProposalState < ActiveRecord::Migration[6.0]
def change
create_table :decidim_proposals_proposal_states do |t|
t.jsonb :title
t.jsonb :description
t.jsonb :announcement_title
t.string :token, null: false
t.boolean :system, null: false, default: false
t.references :decidim_component, index: true, null: false
t.integer :proposals_count, default: 0, null: false
t.boolean :default, default: false, null: false
t.boolean :answerable, default: false, null: false
t.boolean :notifiable, default: false, null: false
t.boolean :gamified, default: false, null: false
t.json :include_in_stats, default: {}, null: false
t.string :css_class
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true
# This migration comes from decidim_custom_proposal_states (originally 20231102173214)

class AddStateIdToDecidimProposalsProposals < ActiveRecord::Migration[6.0]
def up
add_column :decidim_proposals_proposals, :decidim_proposals_proposal_state_id, :integer, index: true

add_foreign_key :decidim_proposals_proposals, :decidim_proposals_proposal_states, column: :decidim_proposals_proposal_state_id
end

def down
remove_foreign_key :decidim_proposals_proposals, column: :decidim_proposals_proposal_state_id
remove_column :decidim_proposals_proposals, :decidim_proposals_proposal_state_id
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true
# This migration comes from decidim_custom_proposal_states (originally 20231102234909)

class CreateDefaultProposalStates < ActiveRecord::Migration[6.0]
class Proposal < ApplicationRecord
belongs_to :proposal_state,
class_name: "Decidim::CustomProposalStates::ProposalState",
foreign_key: "decidim_proposals_proposal_state_id",
inverse_of: :proposals,
optional: true

self.table_name = :decidim_proposals_proposals
end

def up
return unless Decidim.version.to_s.include?("0.27")

states = {
"0" => :not_answered,
"10" => :evaluating,
"20" => :accepted,
"-10" => :rejected,
"-20" => :withdrawn
}

Proposal.where(state: "").update_all(state: "not_answered")
Proposal.where(state: nil).update_all(state: "not_answered")

Decidim::Component.where(manifest_name: "proposals").find_each do |component|
admin_user = component.organization.admins.first
default_states = Decidim::CustomProposalStates.create_default_states!(component, admin_user).with_indifferent_access
Proposal.where(decidim_component_id: component.id).find_each do |proposal|
proposal.proposal_state = default_states.dig(proposal.state.to_s, :object)
proposal.save!
end
end
change_column_null :decidim_proposals_proposals, :decidim_proposals_proposal_state_id, false
end

def down; end
end
21 changes: 20 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_04_26_092405) do
ActiveRecord::Schema.define(version: 2024_08_12_083118) do

# These are extensions that must be enabled in order to support this database
enable_extension "ltree"
Expand Down Expand Up @@ -1568,6 +1568,23 @@
t.index ["decidim_proposal_id"], name: "decidim_proposals_proposal_note_proposal"
end

create_table "decidim_proposals_proposal_states", force: :cascade do |t|
t.jsonb "title"
t.jsonb "description"
t.jsonb "announcement_title"
t.string "token", null: false
t.boolean "system", default: false, null: false
t.bigint "decidim_component_id", null: false
t.integer "proposals_count", default: 0, null: false
t.boolean "default", default: false, null: false
t.boolean "answerable", default: false, null: false
t.boolean "notifiable", default: false, null: false
t.boolean "gamified", default: false, null: false
t.json "include_in_stats", default: {}, null: false
t.string "css_class"
t.index ["decidim_component_id"], name: "index_decidim_proposals_proposal_states_on_decidim_component_id"
end

create_table "decidim_proposals_proposal_votes", id: :serial, force: :cascade do |t|
t.integer "decidim_proposal_id", null: false
t.integer "decidim_author_id", null: false
Expand Down Expand Up @@ -1609,6 +1626,7 @@
t.jsonb "body"
t.integer "comments_count", default: 0, null: false
t.integer "follows_count", default: 0, null: false
t.integer "decidim_proposals_proposal_state_id", null: false
t.index "md5((body)::text)", name: "decidim_proposals_proposal_body_search"
t.index "md5((title)::text)", name: "decidim_proposals_proposal_title_search"
t.index ["created_at"], name: "index_decidim_proposals_proposals_on_created_at"
Expand Down Expand Up @@ -2130,6 +2148,7 @@
add_foreign_key "decidim_participatory_processes", "decidim_organizations"
add_foreign_key "decidim_participatory_processes", "decidim_participatory_process_types"
add_foreign_key "decidim_participatory_processes", "decidim_scope_types"
add_foreign_key "decidim_proposals_proposals", "decidim_proposals_proposal_states"
add_foreign_key "decidim_reminder_deliveries", "decidim_reminders"
add_foreign_key "decidim_reminder_records", "decidim_reminders"
add_foreign_key "decidim_reminders", "decidim_components"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ module Budgets
module Admin
describe ImportProposalsToBudgets do
describe "call" do
let!(:proposal) { create(:proposal, :accepted) }
let!(:first_proposal) { create(:proposal, :accepted) }
let!(:second_proposal) { create(:proposal, :accepted) }
let!(:proposal) { create(:extended_proposal, :accepted) }
let!(:first_proposal) { create(:extended_proposal, :accepted) }
let!(:second_proposal) { create(:extended_proposal, :accepted) }
let!(:current_component) do
create(
:component,
Expand Down
46 changes: 23 additions & 23 deletions spec/controllers/decidim/proposals/proposals_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module Proposals
end

describe "default_filter_scope_params" do
let!(:component) { create(:proposal_component) }
let!(:component) { create(:extended_proposal_component) }

context "when component has no scopes" do
it "returns all" do
Expand Down Expand Up @@ -55,7 +55,7 @@ module Proposals

describe "GET index" do
context "when participatory texts are disabled" do
let(:component) { create(:proposal_component, :with_geocoding_enabled) }
let(:component) { create(:extended_proposal_component, :with_geocoding_enabled) }

it "sorts proposals by search defaults" do
get :index
Expand All @@ -74,8 +74,8 @@ module Proposals
end

it "sets two different collections" do
geocoded_proposals = create_list :proposal, 10, component: component, latitude: 1.1, longitude: 2.2
_non_geocoded_proposals = create_list :proposal, 2, component: component, latitude: nil, longitude: nil
geocoded_proposals = create_list :extended_proposal, 10, component: component, latitude: 1.1, longitude: 2.2
_non_geocoded_proposals = create_list :extended_proposal, 2, component: component, latitude: nil, longitude: nil

get :index
expect(response).to have_http_status(:ok)
Expand All @@ -87,7 +87,7 @@ module Proposals
end

context "when participatory texts are enabled" do
let(:component) { create(:proposal_component, :with_participatory_texts_enabled) }
let(:component) { create(:extended_proposal_component, :with_participatory_texts_enabled) }

it "sorts proposals by position" do
get :index
Expand All @@ -97,8 +97,8 @@ module Proposals
end

context "when emendations exist" do
let!(:amendable) { create(:proposal, component: component) }
let!(:emendation) { create(:proposal, component: component) }
let!(:amendable) { create(:extended_proposal, component: component) }
let!(:emendation) { create(:extended_proposal, component: component) }
let!(:amendment) { create(:amendment, amendable: amendable, emendation: emendation, state: "accepted") }

it "does not include emendations" do
Expand All @@ -112,7 +112,7 @@ module Proposals
end

describe "GET new" do
let(:component) { create(:proposal_component, :with_creation_enabled) }
let(:component) { create(:extended_proposal_component, :with_creation_enabled) }

before { sign_in user }

Expand All @@ -125,7 +125,7 @@ module Proposals
end

context "when draft proposals exist from other users" do
let!(:others_draft) { create(:proposal, :draft, component: component) }
let!(:others_draft) { create(:extended_proposal, :draft, component: component) }

it "renders the empty form" do
get :new, params: params
Expand All @@ -139,7 +139,7 @@ module Proposals
before { sign_in user }

context "when creation is not enabled" do
let(:component) { create(:proposal_component) }
let(:component) { create(:extended_proposal_component) }

it "raises an error" do
post :create, params: params
Expand All @@ -149,7 +149,7 @@ module Proposals
end

context "when creation is enabled" do
let(:component) { create(:proposal_component, :with_creation_enabled) }
let(:component) { create(:extended_proposal_component, :with_creation_enabled) }
let(:proposal_params) do
{
component_id: component.id,
Expand All @@ -168,8 +168,8 @@ module Proposals
end

describe "PATCH update" do
let(:component) { create(:proposal_component, :with_creation_enabled, :with_attachments_allowed) }
let(:proposal) { create(:proposal, component: component, users: [user]) }
let(:component) { create(:extended_proposal_component, :with_creation_enabled, :with_attachments_allowed) }
let(:proposal) { create(:extended_proposal, component: component, users: [user]) }
let(:proposal_params) do
{
title: "Lorem ipsum dolor sit amet, consectetur adipiscing elit",
Expand Down Expand Up @@ -203,7 +203,7 @@ module Proposals
documents: proposal.documents.map { |a| a.id.to_s }
}
end
let(:proposal) { create(:proposal, :with_photo, :with_document, component: component, users: [user]) }
let(:proposal) { create(:extended_proposal, :with_photo, :with_document, component: component, users: [user]) }

it "displays the editing form with errors" do
patch :update, params: params
Expand All @@ -218,9 +218,9 @@ module Proposals
end

describe "access links from creating proposal steps" do
let!(:component) { create(:proposal_component, :with_creation_enabled) }
let!(:component) { create(:extended_proposal_component, :with_creation_enabled) }
let!(:current_user) { create(:user, :confirmed, organization: component.organization) }
let!(:proposal_extra) { create(:proposal, :draft, component: component, users: [current_user]) }
let!(:proposal_extra) { create(:extended_proposal, :draft, component: component, users: [current_user]) }
let!(:params) do
{
id: proposal_extra.id,
Expand Down Expand Up @@ -260,12 +260,12 @@ module Proposals
end

describe "withdraw a proposal" do
let(:component) { create(:proposal_component, :with_creation_enabled) }
let(:component) { create(:extended_proposal_component, :with_creation_enabled) }

before { sign_in user }

context "when an authorized user is withdrawing a proposal" do
let(:proposal) { create(:proposal, component: component, users: [user]) }
let(:proposal) { create(:extended_proposal, component: component, users: [user]) }

it "withdraws the proposal" do
put :withdraw, params: params.merge(id: proposal.id)
Expand All @@ -277,7 +277,7 @@ module Proposals
end

context "and the proposal already has supports" do
let(:proposal) { create(:proposal, :with_votes, component: component, users: [user]) }
let(:proposal) { create(:extended_proposal, :with_votes, component: component, users: [user]) }

it "is not able to withdraw the proposal" do
put :withdraw, params: params.merge(id: proposal.id)
Expand All @@ -292,7 +292,7 @@ module Proposals

describe "when current user is NOT the author of the proposal" do
let(:current_user) { create(:user, :confirmed, organization: component.organization) }
let(:proposal) { create(:proposal, component: component, users: [current_user]) }
let(:proposal) { create(:extended_proposal, component: component, users: [current_user]) }

context "and the proposal has no supports" do
it "is not able to withdraw the proposal" do
Expand All @@ -310,9 +310,9 @@ module Proposals
end

describe "GET show" do
let!(:component) { create(:proposal_component, :with_amendments_enabled) }
let!(:amendable) { create(:proposal, component: component) }
let!(:emendation) { create(:proposal, component: component) }
let!(:component) { create(:extended_proposal_component, :with_amendments_enabled) }
let!(:amendable) { create(:extended_proposal, component: component) }
let!(:emendation) { create(:extended_proposal, component: component) }
let!(:amendment) { create(:amendment, amendable: amendable, emendation: emendation) }
let(:active_step_id) { component.participatory_space.active_step.id }

Expand Down
1 change: 1 addition & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
require "decidim/forms/test/factories"
require "decidim/surveys/test/factories"
require "decidim/initiatives/test/factories"
require "decidim/custom_proposal_states/test/factories"
Loading
Loading