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: Custom proposal states #61

Closed
wants to merge 9 commits into from
Closed
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 @@ -21,6 +21,7 @@ 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"

# Omniauth gems
gem "decidim-custom_proposal_states", git: "https://github.com/alecslupu-pfa/decidim-module-custom_proposal_states", branch: "chore/fix-module-dependency"
gem "decidim-slider", git: "https://github.com/alecslupu-pfa/decidim-module-slider", branch: "main"
gem "omniauth-publik", git: "https://github.com/OpenSourcePolitics/omniauth-publik"

Expand Down
20 changes: 19 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ GIT
omniauth (~> 2.0)
omniauth-oauth2 (>= 1.7.2, < 2.0)

GIT
remote: https://github.com/alecslupu-pfa/decidim-module-custom_proposal_states
revision: 5a01dcd0c61f7760adb929d53a6ccdbe6af5b050
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: 63e29e03b2bc300f4941a079ecb993cab006e254
Expand All @@ -28,7 +38,7 @@ GIT

GIT
remote: https://github.com/opensourcepolitics/decidim-module-term_customizer.git
revision: f5208f3cad23cb68e502e77cb0d2d3d441d09e40
revision: 11724f312f77a0a9199d0c79538058e0e5ae10c8
branch: fix/multi-threading-compliant-0.26
specs:
decidim-term_customizer (0.26.0)
Expand Down Expand Up @@ -395,6 +405,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.3)
Expand Down Expand Up @@ -640,6 +656,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 @@ -922,6 +939,7 @@ DEPENDENCIES
dalli
decidim (~> 0.26.0)
decidim-cache_cleaner
decidim-custom_proposal_states!
decidim-decidim_awesome (= 0.8.3)
decidim-dev (~> 0.26.0)
decidim-homepage_interactive_map!
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require "decidim/rails"
# Add the frameworks used by your app that are not loaded by Decidim.
require "action_cable/engine"

# require "action_mailbox/engine"
# require "action_text/engine"
require_relative "../lib/active_storage/downloadable"
Expand Down Expand Up @@ -46,7 +47,6 @@ class Application < Rails::Application

config.after_initialize do
require "extends/controllers/decidim/devise/sessions_controller_extends"
require "extends/lib/decidim/dependency_resolver_extends"

Decidim::GraphiQL::Rails.config.tap do |config|
config.initial_query = "{\n deployment {\n version\n branch\n remote\n upToDate\n currentCommit\n latestCommit\n locallyModified\n }\n}".html_safe
Expand Down
1 change: 1 addition & 0 deletions config/initializers/extends.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
require "extends/serializers/proposals/proposals_serializer_extends"
require "extends/components/decidim/budgets/component"
require "extends/cells/decidim/content_blocks/hero_cell_extends"
require "extends/lib/decidim/dependency_resolver_extends"
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

# rubocop:disable Lint/UselessAssignment
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
# rubocop:enable Lint/UselessAssignment

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_11_27_111726) do
ActiveRecord::Schema.define(version: 2024_01_04_141153) do

# These are extensions that must be enabled in order to support this database
enable_extension "ltree"
Expand Down Expand Up @@ -1259,6 +1259,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 @@ -1300,6 +1317,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 @@ -1735,6 +1753,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
5 changes: 3 additions & 2 deletions lib/extends/lib/decidim/dependency_resolver_extends.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ module DependencyResolverExtends
# Gemfile, e.g. when the Decidim gems are installed through git.
#
# @param name [String] The name of the gem to find.
# @return [Bundler::LazySpecification, nil] The specification for the gem
# or nil if the gem is not listed in the locked gems.
# @return [Gem::Specification, nil] The specification for the gem
# or nil if the gem is not listed in the locked gems or nil when the
# returned spec is not installed in the current gem environment.
def spec(name)
sp = Bundler.definition.locked_gems.specs.find { |s| s.name == name }

Expand Down
2 changes: 1 addition & 1 deletion spec/commands/budgets/admin/create_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Decidim::Budgets
let(:latitude) { 40.1234 }
let(:longitude) { 2.1234 }
let(:proposal_component) do
create(:component, manifest_name: :proposals, participatory_space: participatory_process)
create(:extended_proposal_component, manifest_name: :proposals, participatory_space: participatory_process)
end
let(:proposals) do
create_list(
Expand Down
2 changes: 1 addition & 1 deletion spec/commands/budgets/admin/update_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Decidim::Budgets
let(:longitude) { 2.1234 }
let(:current_photos) { [] }
let(:proposal_component) do
create(:component, manifest_name: :proposals, participatory_space: participatory_process)
create(:extended_proposal_component, manifest_name: :proposals, participatory_space: participatory_process)
end
let(:proposals) do
create_list(
Expand Down
14 changes: 7 additions & 7 deletions spec/controllers/decidim/proposals/proposals_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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 Down Expand Up @@ -72,7 +72,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,7 +97,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 Down Expand Up @@ -134,7 +134,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 @@ -153,7 +153,7 @@ module Proposals
end

describe "PATCH update" do
let(:component) { create(:proposal_component, :with_creation_enabled, :with_attachments_allowed) }
let(:component) { create(:extended_proposal_component, :with_creation_enabled, :with_attachments_allowed) }
let(:proposal) { create(:proposal, component: component, users: [user]) }
let(:proposal_params) do
{
Expand Down Expand Up @@ -203,7 +203,7 @@ 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 }

Expand Down Expand Up @@ -253,7 +253,7 @@ module Proposals
end

describe "GET show" do
let!(:component) { create(:proposal_component, :with_amendments_enabled) }
let!(:component) { create(:extended_proposal_component, :with_amendments_enabled) }
let!(:amendable) { create(:proposal, component: component) }
let!(:emendation) { create(:proposal, component: component) }
let!(:amendment) { create(:amendment, amendable: amendable, emendation: emendation) }
Expand Down
1 change: 1 addition & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
require "decidim/system/test/factories"
require "decidim/participatory_processes/test/factories"
require "decidim/decidim_awesome/test/factories"
require "decidim/custom_proposal_states/test/factories"
2 changes: 1 addition & 1 deletion spec/forms/decidim/budgets/admin/project_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ module Decidim::Budgets
context "with proposals" do
subject { described_class.from_model(project).with_context(context) }

let(:proposals_component) { create :component, manifest_name: :proposals, participatory_space: participatory_process }
let(:proposals_component) { create :extended_proposal_component, manifest_name: :proposals, participatory_space: participatory_process }
let!(:proposal) { create :proposal, component: proposals_component }

let(:project) do
Expand Down
8 changes: 4 additions & 4 deletions spec/services/decidim/proposals/proposal_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ module Proposals
described_class.new(proposal)
end

let!(:proposal) { create(:proposal, :accepted) }
let!(:proposal) { create(:proposal, :accepted, component: component) }
let!(:category) { create(:category, participatory_space: component.participatory_space) }
let!(:scope) { create(:scope, organization: component.participatory_space.organization) }
let(:participatory_process) { component.participatory_space }
let(:component) { proposal.component }
let(:component) { create(:extended_proposal_component, manifest_name: "proposals") }

let!(:meetings_component) { create(:component, manifest_name: "meetings", participatory_space: participatory_process) }
let(:meetings) { create_list(:meeting, 2, component: meetings_component) }

let!(:proposals_component) { create(:component, manifest_name: "proposals", participatory_space: participatory_process) }
let!(:proposals_component) { create(:extended_proposal_component, manifest_name: "proposals", participatory_space: participatory_process) }
let(:other_proposals) { create_list(:proposal, 2, component: proposals_component) }

let(:expected_answer) do
Expand Down Expand Up @@ -142,7 +142,7 @@ module Proposals
end

context "with proposal having an answer" do
let!(:proposal) { create(:proposal, :with_answer) }
let!(:proposal) { create(:proposal, :with_answer, component: component) }

it "serializes the answer" do
expect(serialized).to include(answer: expected_answer)
Expand Down
10 changes: 5 additions & 5 deletions spec/shared/proposal_form_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

let(:organization) { create(:organization, available_locales: [:en]) }
let(:participatory_space) { create(:participatory_process, :with_steps, organization: organization) }
let(:component) { create(:proposal_component, participatory_space: participatory_space) }
let(:component) { create(:extended_proposal_component, participatory_space: participatory_space) }
let(:title) do
if options[:i18n] == false
"More sidewalks and less roads!"
Expand Down Expand Up @@ -144,7 +144,7 @@
end

context "when geocoding is enabled" do
let(:component) { create(:proposal_component, :with_geocoding_enabled, participatory_space: participatory_space) }
let(:component) { create(:extended_proposal_component, :with_geocoding_enabled, participatory_space: participatory_space) }

context "when the has address checkbox is checked" do
context "when the address is not present" do
Expand Down Expand Up @@ -181,7 +181,7 @@
end

context "when the proposal is unchanged" do
let(:previous_proposal) { create(:proposal, address: address) }
let(:previous_proposal) { create(:proposal, address: address, component: component) }

let(:title) do
if options[:skip_etiquette_validation]
Expand Down Expand Up @@ -289,7 +289,7 @@

let(:component) do
create(
:proposal_component,
:extended_proposal_component,
:with_extra_hashtags,
participatory_space: participatory_space,
suggested_hashtags: component_suggested_hashtags,
Expand Down Expand Up @@ -336,7 +336,7 @@

let(:organization) { create(:organization, available_locales: [:en]) }
let(:participatory_space) { create(:participatory_process, :with_steps, organization: organization) }
let(:component) { create(:proposal_component, participatory_space: participatory_space) }
let(:component) { create(:extended_proposal_component, participatory_space: participatory_space) }
let(:title) { { en: "More sidewalks and less roads!" } }
let(:body) { { en: "Everything would be better" } }
let(:created_in_meeting) { true }
Expand Down
Loading
Loading