-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from OpenSourcePolitics/feat/custom_proposals_…
…states feat: Add module custom proposals states
- Loading branch information
Showing
10 changed files
with
137 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
.../20231221231804_create_decidim_proposals_proposal_state.decidim_custom_proposal_states.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
16 changes: 16 additions & 0 deletions
16
...31221231805_add_state_id_to_decidim_proposals_proposals.decidim_custom_proposal_states.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
44 changes: 44 additions & 0 deletions
44
db/migrate/20231221231806_create_default_proposal_states.decidim_custom_proposal_states.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters