Sha256: 371b0573ce302a6b72e0061bd23258ce3adc3160e8eee4b7c0e66b5c6e810c39

Contents?: true

Size: 974 Bytes

Versions: 13

Compression:

Stored size: 974 Bytes

Contents

# 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"

    # 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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/models/decidim/amendment.rb
decidim-core-0.28.4 app/models/decidim/amendment.rb
decidim-core-0.29.0 app/models/decidim/amendment.rb
decidim-core-0.28.3 app/models/decidim/amendment.rb
decidim-core-0.29.0.rc4 app/models/decidim/amendment.rb
decidim-core-0.29.0.rc3 app/models/decidim/amendment.rb
decidim-core-0.29.0.rc2 app/models/decidim/amendment.rb
decidim-core-0.29.0.rc1 app/models/decidim/amendment.rb
decidim-core-0.28.2 app/models/decidim/amendment.rb
decidim-core-0.28.1 app/models/decidim/amendment.rb
decidim-core-0.28.0 app/models/decidim/amendment.rb
decidim-core-0.28.0.rc5 app/models/decidim/amendment.rb
decidim-core-0.28.0.rc4 app/models/decidim/amendment.rb