Sha256: e544c54708e8ad9fcca82a84ed1510a942772c96670e18a6aa9d4c931a76ed30

Contents?: true

Size: 1.1 KB

Versions: 13

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Decidim
  # A reportable can be reported one time for each user.
  class Report < ApplicationRecord
    include Decidim::DownloadYourData

    REASONS = %w(spam offensive does_not_belong hidden_during_block).freeze

    belongs_to :moderation, foreign_key: "decidim_moderation_id", class_name: "Decidim::Moderation"
    belongs_to :user, foreign_key: "decidim_user_id", class_name: "Decidim::User"

    validates :reason, presence: true
    validates :user, uniqueness: { scope: :decidim_moderation_id }
    validates :reason, inclusion: { in: REASONS }
    validate :user_and_moderation_same_organization

    def self.user_collection(user)
      where(decidim_user_id: user.id)
    end

    def self.export_serializer
      Decidim::DownloadYourDataSerializers::DownloadYourDataReportSerializer
    end

    private

    # Private: check if the moderation and the user have the same organization
    def user_and_moderation_same_organization
      return if !moderation || !user

      errors.add(:moderation, :invalid) unless user.organization == moderation.organization
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/models/decidim/report.rb
decidim-core-0.28.4 app/models/decidim/report.rb
decidim-core-0.29.0 app/models/decidim/report.rb
decidim-core-0.28.3 app/models/decidim/report.rb
decidim-core-0.29.0.rc4 app/models/decidim/report.rb
decidim-core-0.29.0.rc3 app/models/decidim/report.rb
decidim-core-0.29.0.rc2 app/models/decidim/report.rb
decidim-core-0.29.0.rc1 app/models/decidim/report.rb
decidim-core-0.28.2 app/models/decidim/report.rb
decidim-core-0.28.1 app/models/decidim/report.rb
decidim-core-0.28.0 app/models/decidim/report.rb
decidim-core-0.28.0.rc5 app/models/decidim/report.rb
decidim-core-0.28.0.rc4 app/models/decidim/report.rb