Sha256: 0a9933862d58334fec9fcf6f5b7c86f9db3774b5d7dcc3c44840fdeacce6897b

Contents?: true

Size: 1.59 KB

Versions: 25

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

module Decidim
  # Initiative type.
  class InitiativesType < ApplicationRecord
    include Decidim::HasResourcePermission
    include Decidim::TranslatableResource
    include Decidim::HasUploadValidations
    include Decidim::Traceable

    translatable_fields :title, :description, :extra_fields_legal_information

    belongs_to :organization,
               foreign_key: "decidim_organization_id",
               class_name: "Decidim::Organization"

    has_many :scopes,
             foreign_key: "decidim_initiatives_types_id",
             class_name: "Decidim::InitiativesTypeScope",
             dependent: :destroy,
             inverse_of: :type

    has_many :initiatives,
             through: :scopes,
             class_name: "Decidim::Initiative"

    enum signature_type: [:online, :offline, :any], _suffix: true

    validates :title, :description, :signature_type, presence: true
    validates :document_number_authorization_handler, presence: true, if: ->(form) { form.collect_user_extra_fields? }

    has_one_attached :banner_image
    validates_upload :banner_image, uploader: Decidim::BannerImageUploader

    def allowed_signature_types_for_initiatives
      return %w(online offline any) if any_signature_type?

      Array(signature_type.to_s)
    end

    def allow_resource_permissions?
      true
    end

    def mounted_admin_engine
      "decidim_admin_initiatives"
    end

    def mounted_params
      { host: organization.host }
    end

    def self.log_presenter_class_for(_log)
      Decidim::Initiatives::AdminLog::InitiativesTypePresenter
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-initiatives-0.27.2 app/models/decidim/initiatives_type.rb
decidim-initiatives-0.27.1 app/models/decidim/initiatives_type.rb
decidim-initiatives-0.27.0 app/models/decidim/initiatives_type.rb
decidim-initiatives-0.27.0.rc2 app/models/decidim/initiatives_type.rb
decidim-initiatives-0.27.0.rc1 app/models/decidim/initiatives_type.rb