From c5887fb944339b6548b5f69370c73d62dd718811 Mon Sep 17 00:00:00 2001 From: quentinchampenois <26109239+Quentinchampenois@users.noreply.github.com> Date: Fri, 22 Dec 2023 10:51:46 +0100 Subject: [PATCH 1/5] feat: Add custom proposal states --- Gemfile | 6 ++- Gemfile.lock | 20 ++++++++- ...al_state.decidim_custom_proposal_states.rb | 22 ++++++++++ ...roposals.decidim_custom_proposal_states.rb | 15 +++++++ ...l_states.decidim_custom_proposal_states.rb | 41 +++++++++++++++++++ db/schema.rb | 21 +++++++++- 6 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20231221231804_create_decidim_proposals_proposal_state.decidim_custom_proposal_states.rb create mode 100644 db/migrate/20231221231805_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb create mode 100644 db/migrate/20231221231806_create_default_proposal_states.decidim_custom_proposal_states.rb diff --git a/Gemfile b/Gemfile index 1a3cf6f..b170264 100644 --- a/Gemfile +++ b/Gemfile @@ -15,14 +15,16 @@ gem "decidim-budgets_paper_ballots", git: "https://github.com/digidemlab/decidim gem "decidim-decidim_awesome" gem "decidim-half_signup", git: "https://github.com/OpenSourcePolitics/decidim-module-half_sign_up", branch: DECIDIM_BRANCH gem "decidim-homepage_interactive_map", git: "https://github.com/OpenSourcePolitics/decidim-module-homepage_interactive_map.git", branch: DECIDIM_BRANCH -# gem "decidim-homepage_proposals", git: "https://github.com/OpenSourcePolitics/decidim-module_homepage_proposals.git", branch: DECIDIM_BRANCH gem "decidim-homepage_proposals", git: "https://github.com/alecslupu-pfa/decidim-module_homepage_proposals", branch: "feature/reset-filters" gem "decidim-phone_authorization_handler", git: "https://github.com/OpenSourcePolitics/decidim-module_phone_authorization_handler", branch: DECIDIM_BRANCH -gem "decidim-simple_proposal", git: "https://github.com/mainio/decidim-module-simple_proposal", branch: DECIDIM_BRANCH gem "decidim-slider", git: "https://github.com/alecslupu-pfa/decidim-module-slider", branch: "main" gem "decidim-spam_detection" gem "decidim-term_customizer", git: "https://github.com/opensourcepolitics/decidim-module-term_customizer.git", branch: "fix/multi-threading-compliant-0.26" +# NOTE: Custom proposal states must be before simple_proposal +gem "decidim-custom_proposal_states", git: "https://github.com/alecslupu-pfa/decidim-module-custom_proposal_states", branch: "chore/fix-module-dependency" +gem "decidim-simple_proposal", git: "https://github.com/mainio/decidim-module-simple_proposal", branch: DECIDIM_BRANCH + gem "dotenv-rails" gem "bootsnap", "~> 1.4" diff --git a/Gemfile.lock b/Gemfile.lock index 2ce633f..731cfe7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,6 +42,16 @@ GIT countries (~> 5.1, >= 5.1.2) decidim-core (~> 0.26.0) +GIT + remote: https://github.com/alecslupu-pfa/decidim-module-custom_proposal_states + revision: 92b02c1ed2311547b9b4688d16411b4d9be99af6 + branch: chore/fix-module-dependency + specs: + decidim-custom_proposal_states (0.26.8) + decidim-core (~> 0.26.0) + decidim-proposals (~> 0.26.0) + deface (>= 1.9) + GIT remote: https://github.com/alecslupu-pfa/decidim-module-slider revision: 1004d0abff85b74e323d00bc14bd2aa35eb0fdce @@ -52,7 +62,7 @@ GIT GIT remote: https://github.com/alecslupu-pfa/decidim-module_homepage_proposals - revision: 37ac5b73893ab532e06729bef6f5d3b4b6553f35 + revision: 498631e9a5c2fa1628b25c6d6fecbedd8fc507f9 branch: feature/reset-filters specs: decidim-homepage_proposals (1.0.2) @@ -448,6 +458,12 @@ GEM declarative-builder (0.1.0) declarative-option (< 0.2.0) declarative-option (0.1.0) + deface (1.9.0) + actionview (>= 5.2) + nokogiri (>= 1.6) + polyglot + railties (>= 5.2) + rainbow (>= 2.1.0) descendants_tracker (0.0.4) thread_safe (~> 0.3, >= 0.3.1) devise (4.9.2) @@ -694,6 +710,7 @@ GEM pg_search (2.3.6) activerecord (>= 5.2) activesupport (>= 5.2) + polyglot (0.3.5) premailer (1.21.0) addressable css_parser (>= 1.12.0) @@ -976,6 +993,7 @@ DEPENDENCIES decidim-budgets_booth! decidim-budgets_paper_ballots! decidim-conferences (~> 0.26.0) + decidim-custom_proposal_states! decidim-decidim_awesome decidim-dev (~> 0.26.0) decidim-half_signup! diff --git a/db/migrate/20231221231804_create_decidim_proposals_proposal_state.decidim_custom_proposal_states.rb b/db/migrate/20231221231804_create_decidim_proposals_proposal_state.decidim_custom_proposal_states.rb new file mode 100644 index 0000000..efb0a8a --- /dev/null +++ b/db/migrate/20231221231804_create_decidim_proposals_proposal_state.decidim_custom_proposal_states.rb @@ -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 \ No newline at end of file diff --git a/db/migrate/20231221231805_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb b/db/migrate/20231221231805_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb new file mode 100644 index 0000000..7fadb12 --- /dev/null +++ b/db/migrate/20231221231805_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb @@ -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 \ No newline at end of file diff --git a/db/migrate/20231221231806_create_default_proposal_states.decidim_custom_proposal_states.rb b/db/migrate/20231221231806_create_default_proposal_states.decidim_custom_proposal_states.rb new file mode 100644 index 0000000..b88f839 --- /dev/null +++ b/db/migrate/20231221231806_create_default_proposal_states.decidim_custom_proposal_states.rb @@ -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.26") + + 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 \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index d867f05..38df89b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2023_09_05_123704) do +ActiveRecord::Schema.define(version: 2023_12_21_231806) do # These are extensions that must be enabled in order to support this database enable_extension "ltree" @@ -1413,6 +1413,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 @@ -1455,6 +1472,7 @@ t.integer "comments_count", default: 0, null: false t.integer "follows_count", default: 0, null: false t.datetime "deleted_at" + 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" @@ -1893,6 +1911,7 @@ add_foreign_key "decidim_participatory_process_steps", "decidim_participatory_processes" add_foreign_key "decidim_participatory_processes", "decidim_organizations" add_foreign_key "decidim_participatory_processes", "decidim_scope_types" + add_foreign_key "decidim_proposals_proposals", "decidim_proposals_proposal_states" add_foreign_key "decidim_scope_types", "decidim_organizations" add_foreign_key "decidim_scopes", "decidim_organizations" add_foreign_key "decidim_scopes", "decidim_scope_types", column: "scope_type_id" From 6a6db3856b897240c7daf30429d5197ecd866684 Mon Sep 17 00:00:00 2001 From: quentinchampenois <26109239+Quentinchampenois@users.noreply.github.com> Date: Fri, 22 Dec 2023 10:52:29 +0100 Subject: [PATCH 2/5] fix: Default filter params on proposals controller --- .../decidim/proposals/proposals_controller.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/decidim/proposals/proposals_controller.rb b/app/controllers/decidim/proposals/proposals_controller.rb index 98fb6df..225c5bf 100644 --- a/app/controllers/decidim/proposals/proposals_controller.rb +++ b/app/controllers/decidim/proposals/proposals_controller.rb @@ -218,16 +218,23 @@ def search_klass def default_filter_params { search_text: "", + state: default_states, origin: default_filter_origin_params, activity: "all", category_id: default_filter_category_params, - state: %w(accepted evaluating state_not_published), scope_id: default_filter_scope_params, related_to: "", type: "all" } end + def default_states + [ + Decidim::CustomProposalStates::ProposalState.not_system.where(component: current_component).pluck(:token).map(&:to_s), + %w(accepted evaluating state_not_published) + ].flatten + end + def default_filter_origin_params filter_origin_params = %w(citizens meeting) filter_origin_params << "official" if component_settings.official_proposals_enabled From db9cccbf64b35c0ff7407b3a9723c2d3fea6d2d7 Mon Sep 17 00:00:00 2001 From: quentinchampenois <26109239+Quentinchampenois@users.noreply.github.com> Date: Fri, 22 Dec 2023 10:54:54 +0100 Subject: [PATCH 3/5] lint: Fix rubocop offenses --- ...s_proposal_state.decidim_custom_proposal_states.rb | 3 ++- ...posals_proposals.decidim_custom_proposal_states.rb | 3 ++- ..._proposal_states.decidim_custom_proposal_states.rb | 11 +++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/db/migrate/20231221231804_create_decidim_proposals_proposal_state.decidim_custom_proposal_states.rb b/db/migrate/20231221231804_create_decidim_proposals_proposal_state.decidim_custom_proposal_states.rb index efb0a8a..fa1f997 100644 --- a/db/migrate/20231221231804_create_decidim_proposals_proposal_state.decidim_custom_proposal_states.rb +++ b/db/migrate/20231221231804_create_decidim_proposals_proposal_state.decidim_custom_proposal_states.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # This migration comes from decidim_custom_proposal_states (originally 20231102173159) class CreateDecidimProposalsProposalState < ActiveRecord::Migration[6.0] @@ -19,4 +20,4 @@ def change t.string :css_class end end -end \ No newline at end of file +end diff --git a/db/migrate/20231221231805_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb b/db/migrate/20231221231805_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb index 7fadb12..13bcc33 100644 --- a/db/migrate/20231221231805_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb +++ b/db/migrate/20231221231805_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # This migration comes from decidim_custom_proposal_states (originally 20231102173214) class AddStateIdToDecidimProposalsProposals < ActiveRecord::Migration[6.0] @@ -12,4 +13,4 @@ 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 \ No newline at end of file +end diff --git a/db/migrate/20231221231806_create_default_proposal_states.decidim_custom_proposal_states.rb b/db/migrate/20231221231806_create_default_proposal_states.decidim_custom_proposal_states.rb index b88f839..8255e0b 100644 --- a/db/migrate/20231221231806_create_default_proposal_states.decidim_custom_proposal_states.rb +++ b/db/migrate/20231221231806_create_default_proposal_states.decidim_custom_proposal_states.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # This migration comes from decidim_custom_proposal_states (originally 20231102234909) class CreateDefaultProposalStates < ActiveRecord::Migration[6.0] @@ -15,17 +16,19 @@ class Proposal < ApplicationRecord def up return unless Decidim.version.to_s.include?("0.26") + # rubocop:disable Lint/UselessAssignment states = { - "0" => :not_answered, + "0" => :not_answered, "10" => :evaluating, "20" => :accepted, "-10" => :rejected, "-20" => :withdrawn } - + # rubocop:enable Lint/UselessAssignment + # rubocop:disable Rails/SkipsModelValidations Proposal.where(state: "").update_all(state: "not_answered") Proposal.where(state: nil).update_all(state: "not_answered") - + # rubocop:enable Rails/SkipsModelValidations 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 @@ -38,4 +41,4 @@ def up end def down; end -end \ No newline at end of file +end From a2e3d0842540e53a3dcd8181a4f88bd6839bea58 Mon Sep 17 00:00:00 2001 From: quentinchampenois <26109239+Quentinchampenois@users.noreply.github.com> Date: Fri, 22 Dec 2023 11:27:33 +0100 Subject: [PATCH 4/5] fix: PP specs --- spec/factories.rb | 1 + spec/system/participatory_processes_spec.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/factories.rb b/spec/factories.rb index 6619562..45ee4fb 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -11,3 +11,4 @@ require "decidim/decidim_awesome/test/factories" require "decidim/verifications/test/factories" require "decidim/budgets_booth/test/factories" +require "decidim/custom_proposal_states/test/factories" diff --git a/spec/system/participatory_processes_spec.rb b/spec/system/participatory_processes_spec.rb index 7043c7d..0488940 100644 --- a/spec/system/participatory_processes_spec.rb +++ b/spec/system/participatory_processes_spec.rb @@ -239,7 +239,7 @@ context "when going to the participatory process page" do let!(:participatory_process) { base_process } - let!(:proposals_component) { create(:component, :published, participatory_space: participatory_process, manifest_name: :proposals) } + let!(:proposals_component) { create(:extended_proposal_component, :published, participatory_space: participatory_process, manifest_name: :proposals) } let!(:meetings_component) { create(:component, :unpublished, participatory_space: participatory_process, manifest_name: :meetings) } before do From bc942d9ff73324d5e26a71ab5863cb6d6e3dcc1e Mon Sep 17 00:00:00 2001 From: quentinchampenois <26109239+Quentinchampenois@users.noreply.github.com> Date: Fri, 22 Dec 2023 14:02:15 +0100 Subject: [PATCH 5/5] fix: Explore meetings system specs --- spec/system/explore_meetings_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/explore_meetings_spec.rb b/spec/system/explore_meetings_spec.rb index 7ca1a69..f6d4e42 100644 --- a/spec/system/explore_meetings_spec.rb +++ b/spec/system/explore_meetings_spec.rb @@ -500,7 +500,7 @@ context "with linked proposals" do let(:proposal_component) do - create(:component, manifest_name: :proposals, participatory_space: meeting.component.participatory_space) + create(:extended_proposal_component, manifest_name: :proposals, participatory_space: meeting.component.participatory_space) end let(:proposals) { create_list(:proposal, 3, component: proposal_component) }