From fc33d5b7b59bc5051686d604fc0fcb60d1e418a4 Mon Sep 17 00:00:00 2001 From: Simonas Date: Wed, 3 Jan 2024 11:42:27 +0100 Subject: [PATCH] Develop into Master with Custom Proposal States (#93) * feat: Add custom proposal states * fix: Default filter params on proposals controller * lint: Fix rubocop offenses * fix: PP specs * fix: Explore meetings system specs --------- Co-authored-by: quentinchampenois <26109239+Quentinchampenois@users.noreply.github.com> --- Gemfile | 9 ++-- Gemfile.lock | 19 +++++++- .../decidim/proposals/proposals_controller.rb | 9 +++- ...al_state.decidim_custom_proposal_states.rb | 23 ++++++++++ ...roposals.decidim_custom_proposal_states.rb | 16 +++++++ ...l_states.decidim_custom_proposal_states.rb | 44 +++++++++++++++++++ db/schema.rb | 21 ++++++++- spec/factories.rb | 1 + spec/system/explore_meetings_spec.rb | 2 +- spec/system/participatory_processes_spec.rb | 2 +- 10 files changed, 137 insertions(+), 9 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 57f50143..b1702641 100644 --- a/Gemfile +++ b/Gemfile @@ -15,15 +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", \ - ref: "498631e9a5c2fa1628b25c6d6fecbedd8fc507f9" +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 8bc9d16b..731cfe7b 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 @@ -53,7 +63,6 @@ GIT GIT remote: https://github.com/alecslupu-pfa/decidim-module_homepage_proposals revision: 498631e9a5c2fa1628b25c6d6fecbedd8fc507f9 - ref: 498631e9a5c2fa1628b25c6d6fecbedd8fc507f9 branch: feature/reset-filters specs: decidim-homepage_proposals (1.0.2) @@ -449,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) @@ -695,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) @@ -977,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/app/controllers/decidim/proposals/proposals_controller.rb b/app/controllers/decidim/proposals/proposals_controller.rb index 98fb6dfe..225c5bf1 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 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 00000000..fa1f9975 --- /dev/null +++ b/db/migrate/20231221231804_create_decidim_proposals_proposal_state.decidim_custom_proposal_states.rb @@ -0,0 +1,23 @@ +# 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 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 00000000..13bcc335 --- /dev/null +++ b/db/migrate/20231221231805_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb @@ -0,0 +1,16 @@ +# 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 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 00000000..8255e0be --- /dev/null +++ b/db/migrate/20231221231806_create_default_proposal_states.decidim_custom_proposal_states.rb @@ -0,0 +1,44 @@ +# 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") + + # rubocop:disable Lint/UselessAssignment + states = { + "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 + 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 diff --git a/db/schema.rb b/db/schema.rb index d867f055..38df89bc 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" diff --git a/spec/factories.rb b/spec/factories.rb index 66195628..45ee4fba 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/explore_meetings_spec.rb b/spec/system/explore_meetings_spec.rb index 7ca1a69f..f6d4e42f 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) } diff --git a/spec/system/participatory_processes_spec.rb b/spec/system/participatory_processes_spec.rb index 7043c7d5..0488940b 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