Skip to content

Commit

Permalink
Merge pull request #92 from OpenSourcePolitics/feat/custom_proposals_…
Browse files Browse the repository at this point in the history
…states

feat: Add module custom proposals states
  • Loading branch information
simonaszilinskas authored Dec 22, 2023
2 parents 8a2789c + bc942d9 commit 88747d6
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 7 deletions.
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 19 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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!
Expand Down
9 changes: 8 additions & 1 deletion app/controllers/decidim/proposals/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
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: 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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion spec/system/explore_meetings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
2 changes: 1 addition & 1 deletion spec/system/participatory_processes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 88747d6

Please sign in to comment.