Sha256: eb0abe711954547851c95aa399d43b7ff80099e1c037808912290773c5de1341

Contents?: true

Size: 1.63 KB

Versions: 21

Compression:

Stored size: 1.63 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  # A concern with the components needed when you want a model to be able to create
  # links from it to another resource.
  module HasAttachments
    extend ActiveSupport::Concern

    included do
      has_many :attachments,
               class_name: "Decidim::Attachment",
               dependent: :destroy,
               inverse_of: :attached_to,
               as: :attached_to

      # All the attachments that are photos for this process.
      #
      # Returns an Array<Attachment>
      def photos
        @photos ||= attachments.select(&:photo?)
      end

      # All the attachments that are documents for this process.
      #
      # Returns an Array<Attachment>
      def documents
        @documents ||= attachments.includes(:attachment_collection).select(&:document?)
      end

      # All the attachments that are documents for this process that has a collection.
      #
      # Returns an Array<Attachment>
      def documents_with_collection
        documents.select(&:attachment_collection_id?)
      end

      # All the attachments that are documents for this process that not has a collection.
      #
      # Returns an Array<Attachment>
      def documents_without_collection
        documents.reject(&:attachment_collection_id?)
      end
    end

    # Attachment context for the file uploaders checks (e.g. which kind of files
    # the user is allowed to upload in this context).
    #
    # Override this in the model class if it is for a different context.
    #
    # Returns a Symbol.
    def attachment_context
      :participant
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
decidim-core-0.25.2 lib/decidim/has_attachments.rb
decidim-core-0.25.1 lib/decidim/has_attachments.rb
decidim-core-0.25.0 lib/decidim/has_attachments.rb
decidim-core-0.25.0.rc4 lib/decidim/has_attachments.rb
decidim-core-0.25.0.rc3 lib/decidim/has_attachments.rb
decidim-core-0.25.0.rc2 lib/decidim/has_attachments.rb
decidim-core-0.25.0.rc1 lib/decidim/has_attachments.rb
decidim-core-0.24.3 lib/decidim/has_attachments.rb
decidim-core-0.23.6 lib/decidim/has_attachments.rb
decidim-core-0.24.2 lib/decidim/has_attachments.rb
decidim-core-0.23.5 lib/decidim/has_attachments.rb
decidim-core-0.24.1 lib/decidim/has_attachments.rb
decidim-core-0.24.0 lib/decidim/has_attachments.rb
decidim-core-0.24.0.rc2 lib/decidim/has_attachments.rb
decidim-core-0.23.4 lib/decidim/has_attachments.rb
decidim-core-0.24.0.rc1 lib/decidim/has_attachments.rb
decidim-core-0.23.3 lib/decidim/has_attachments.rb
decidim-core-0.23.2 lib/decidim/has_attachments.rb
decidim-core-0.23.1 lib/decidim/has_attachments.rb
decidim-core-0.23.1.rc1 lib/decidim/has_attachments.rb