Sha256: dfcc890ef26330d87b5bcc3f055a1c8e1ad3b9de40018818136fe6625b73e645

Contents?: true

Size: 971 Bytes

Versions: 25

Compression:

Stored size: 971 Bytes

Contents

# frozen_string_literal: true

module Decidim
  class UserReport < ApplicationRecord
    include Decidim::DataPortability

    REASONS = %w(spam offensive does_not_belong).freeze

    belongs_to :moderation, foreign_key: :user_moderation_id, class_name: "Decidim::UserModeration"
    belongs_to :user, class_name: "Decidim::User"

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

    def self.export_serializer
      raise NotImplementedError
      # Decidim::DataPortabilitySerializers::DataPortabilityReportSerializer
    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

25 entries across 25 versions & 1 rubygems

Version Path
decidim-core-0.26.10 app/models/decidim/user_report.rb
decidim-core-0.26.9 app/models/decidim/user_report.rb
decidim-core-0.26.8 app/models/decidim/user_report.rb
decidim-core-0.26.7 app/models/decidim/user_report.rb
decidim-core-0.26.5 app/models/decidim/user_report.rb
decidim-core-0.26.4 app/models/decidim/user_report.rb
decidim-core-0.26.3 app/models/decidim/user_report.rb
decidim-core-0.26.2 app/models/decidim/user_report.rb
decidim-core-0.26.1 app/models/decidim/user_report.rb
decidim-core-0.26.0 app/models/decidim/user_report.rb
decidim-core-0.26.0.rc2 app/models/decidim/user_report.rb
decidim-core-0.26.0.rc1 app/models/decidim/user_report.rb
decidim-core-0.25.2 app/models/decidim/user_report.rb
decidim-core-0.25.1 app/models/decidim/user_report.rb
decidim-core-0.25.0 app/models/decidim/user_report.rb
decidim-core-0.25.0.rc4 app/models/decidim/user_report.rb
decidim-core-0.25.0.rc3 app/models/decidim/user_report.rb
decidim-core-0.25.0.rc2 app/models/decidim/user_report.rb
decidim-core-0.25.0.rc1 app/models/decidim/user_report.rb
decidim-core-0.24.3 app/models/decidim/user_report.rb