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.26.1 lib/decidim/user_reportable.rb
decidim-core-0.26.0 lib/decidim/user_reportable.rb
decidim-core-0.26.0.rc2 lib/decidim/user_reportable.rb
decidim-core-0.26.0.rc1 lib/decidim/user_reportable.rb
decidim-core-0.25.2 lib/decidim/user_reportable.rb
decidim-core-0.25.1 lib/decidim/user_reportable.rb
decidim-core-0.25.0 lib/decidim/user_reportable.rb
decidim-core-0.25.0.rc4 lib/decidim/user_reportable.rb
decidim-core-0.25.0.rc3 lib/decidim/user_reportable.rb
decidim-core-0.25.0.rc2 lib/decidim/user_reportable.rb
decidim-core-0.25.0.rc1 lib/decidim/user_reportable.rb
decidim-core-0.24.3 lib/decidim/user_reportable.rb
decidim-core-0.24.2 lib/decidim/user_reportable.rb
decidim-core-0.24.1 lib/decidim/user_reportable.rb
decidim-core-0.24.0 lib/decidim/user_reportable.rb
decidim-core-0.24.0.rc2 lib/decidim/user_reportable.rb
decidim-core-0.24.0.rc1 lib/decidim/user_reportable.rb