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

Add Amendment Count column in Proposal admin panel #15

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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 .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
DATABASE_PASSWORD: postgres
- name: Precompile assets
run: |
sudo apt install imagemagick
npm install
bundle exec rake assets:precompile
env:
Expand Down
37 changes: 37 additions & 0 deletions app/models/decidim/amendment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

module Decidim
class Amendment < ApplicationRecord
STATES = { draft: 0, evaluating: 10, accepted: 20, rejected: 30, withdrawn: -1 }.freeze

belongs_to :amendable, foreign_key: "decidim_amendable_id", foreign_type: "decidim_amendable_type", polymorphic: true
belongs_to :amender, foreign_key: "decidim_user_id", class_name: "Decidim::User"
belongs_to :emendation, foreign_key: "decidim_emendation_id", foreign_type: "decidim_emendation_type", polymorphic: true

validates :state, presence: true, inclusion: { in: STATES.keys.map(&:to_s) }

enum state: STATES, _default: "draft"

after_destroy :update_proposal_amendments_count
after_save :update_proposal_amendments_count

# Reports the mapped resource type for authorization transfers.
#
# @return [String] The resource type as string (i.e. its class name).
def mapped_resource_type
decidim_amendable_type
end

def promoted?
return false unless rejected?

emendation.linked_promoted_resource.present?
end

private

def update_proposal_amendments_count
Decidim::Proposals::Proposal.find(decidim_amendable_id).update_amendments_count
end
end
end
Loading
Loading