Sha256: 24eba638823be6b54fe5fc1fe54eec931b707b13558fbcc4b2e4ef7ec0c12500

Contents?: true

Size: 904 Bytes

Versions: 37

Compression:

Stored size: 904 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  # A concern with the components needed when you want a model to be reportable
  module UserReportable
    extend ActiveSupport::Concern

    included do
      has_one :user_moderation, class_name: "Decidim::UserModeration", foreign_key: :decidim_user_id, dependent: :destroy
      has_many :user_reports, through: :user_moderation, source: :reports, class_name: "Decidim::UserReport"

      def report_count
        user_moderation&.report_count.to_i
      end

      # Public: Check if the user has reported the reportable.
      #
      # Returns Boolean.
      def reported_by?(user)
        user_reports.where(user: user).any?
      end

      # Public: Checks if the reportable has been reported or not.
      #
      # Returns Boolean.
      def reported?
        report_count&.positive?
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
decidim-core-0.27.9 lib/decidim/user_reportable.rb
decidim-core-0.27.8 lib/decidim/user_reportable.rb
decidim-core-0.27.7 lib/decidim/user_reportable.rb
decidim-core-0.27.6 lib/decidim/user_reportable.rb
decidim-core-0.26.10 lib/decidim/user_reportable.rb
decidim-core-0.26.9 lib/decidim/user_reportable.rb
decidim-core-0.27.5 lib/decidim/user_reportable.rb
decidim-core-0.26.8 lib/decidim/user_reportable.rb
decidim-core-0.27.4 lib/decidim/user_reportable.rb
decidim-core-0.27.3 lib/decidim/user_reportable.rb
decidim-core-0.26.7 lib/decidim/user_reportable.rb
decidim-core-0.26.5 lib/decidim/user_reportable.rb
decidim-core-0.27.2 lib/decidim/user_reportable.rb
decidim-core-0.27.1 lib/decidim/user_reportable.rb
decidim-core-0.26.4 lib/decidim/user_reportable.rb
decidim-core-0.27.0 lib/decidim/user_reportable.rb
decidim-core-0.26.3 lib/decidim/user_reportable.rb
decidim-core-0.27.0.rc2 lib/decidim/user_reportable.rb
decidim-core-0.27.0.rc1 lib/decidim/user_reportable.rb
decidim-core-0.26.2 lib/decidim/user_reportable.rb