Sha256: 129acb5b4e54114fa995f87588673af9102bd7eb4c023832d6165ff597fca138

Contents?: true

Size: 809 Bytes

Versions: 25

Compression:

Stored size: 809 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # This concern contains the logic related with resources that can be endorsed.
  # Thus, it is expected to be included into a resource that is wanted to be endorsable.
  # This resource will have many `Decidim::Endorsement`s.
  module Endorsable
    extend ActiveSupport::Concern

    included do
      has_many :endorsements,
               as: :resource,
               dependent: :destroy,
               counter_cache: "endorsements_count"

      # Public: Check if the user has endorsed the resource.
      # - user_group: may be nil if user is not representing any user_group.
      #
      # Returns Boolean.
      def endorsed_by?(user, user_group = nil)
        endorsements.where(author: user, user_group: user_group).any?
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

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