Sha256: eb9ef93bc433a3e294e6a79056b5081cd1e1dad5e08f6c4a3e17ef731a4526bb
Contents?: true
Size: 881 Bytes
Versions: 59
Compression:
Stored size: 881 Bytes
Contents
# frozen_string_literal: true module Decidim # A resource can have an endorsement for each user or group the author/endorser belongs to. class Endorsement < ApplicationRecord include Decidim::Authorable belongs_to :resource, polymorphic: true, counter_cache: true validates :resource_id, uniqueness: { scope: [:resource_type, :author, :user_group] } validate :author_and_resource_same_organization scope :for_listing, -> { order(:decidim_user_group_id, :created_at) } private def organization resource&.component&.organization end # Private: check if the resource and the author have the same organization def author_and_resource_same_organization return if !resource || !author errors.add(:resource, :invalid) unless author.organization == resource.organization end end end
Version data entries
59 entries across 59 versions & 1 rubygems