-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Addition of custom proposal states (#574)
* feat: Add custom proposal states * fix: Fix failing tests * fix: Try to fix some more failing tests * fix: Fix last tests by backporting library's tests * lint: Update Gemfile to put the gem in the right place * lint: Rubocop fixes --------- Co-authored-by: Lucie Grau <[email protected]>
- Loading branch information
Showing
14 changed files
with
200 additions
and
113 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
22 changes: 22 additions & 0 deletions
22
.../20240812083116_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,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 |
15 changes: 15 additions & 0 deletions
15
...40812083117_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,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 |
41 changes: 41 additions & 0 deletions
41
db/migrate/20240812083118_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,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.27") | ||
|
||
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 |
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
Oops, something went wrong.