Sha256: da46e49c86d71132f12695c229f146d1f6ee9735122cf5ade67d47db65db8c64
Contents?: true
Size: 886 Bytes
Versions: 4
Compression:
Stored size: 886 Bytes
Contents
# frozen_string_literal: true module Decidim # A reportable can be reported one time for each user. class Report < ApplicationRecord REASONS = %w(spam offensive does_not_belong).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 :moderation, :user, :reason, presence: true validates :user, uniqueness: { scope: :decidim_moderation_id } validates :reason, inclusion: { in: REASONS } validate :user_and_moderation_same_organization 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
4 entries across 4 versions & 1 rubygems