Sha256: 55c7fe864b1f28aac7ee5910dc05ddb7bab8897552d5e23d0bba98f3e819e4f1

Contents?: true

Size: 1.02 KB

Versions: 84

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Decidim
  # A ResourceLink allows linking resources (other entities in Decidim) between
  # them without them having to know each other.
  #
  # In order to group the relations between resources you need to specify a name.
  #
  # Some examples could be: proposals that have been created in a meeting or
  # projects that are a result of merging diffrent proposals.
  class ResourceLink < ApplicationRecord
    belongs_to :from, polymorphic: true
    belongs_to :to, polymorphic: true

    validates :name, presence: true, uniqueness: { scope: [:from, :to] }
    validate :same_organization
    validate :same_participatory_space

    private

    def same_organization
      return if from.try(:organization) == to.try(:organization)

      errors.add(:from, :invalid)
      errors.add(:to, :invalid)
    end

    def same_participatory_space
      return if from.try(:participatory_space) == to.try(:participatory_space)

      errors.add(:from, :invalid)
      errors.add(:to, :invalid)
    end
  end
end

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
decidim-core-0.28.4 app/models/decidim/resource_link.rb
decidim-core-0.27.9 app/models/decidim/resource_link.rb
decidim-core-0.28.3 app/models/decidim/resource_link.rb
decidim-core-0.27.8 app/models/decidim/resource_link.rb
decidim-core-0.28.2 app/models/decidim/resource_link.rb
decidim-core-0.27.7 app/models/decidim/resource_link.rb
decidim-core-0.28.1 app/models/decidim/resource_link.rb
decidim-core-0.27.6 app/models/decidim/resource_link.rb
decidim-core-0.26.10 app/models/decidim/resource_link.rb
decidim-core-0.26.9 app/models/decidim/resource_link.rb
decidim-core-0.28.0 app/models/decidim/resource_link.rb
decidim-core-0.27.5 app/models/decidim/resource_link.rb
decidim-core-0.28.0.rc5 app/models/decidim/resource_link.rb
decidim-core-0.28.0.rc4 app/models/decidim/resource_link.rb
decidim-core-0.26.8 app/models/decidim/resource_link.rb
decidim-core-0.27.4 app/models/decidim/resource_link.rb
decidim-core-0.27.3 app/models/decidim/resource_link.rb
decidim-core-0.26.7 app/models/decidim/resource_link.rb
decidim-core-0.26.5 app/models/decidim/resource_link.rb
decidim-core-0.27.2 app/models/decidim/resource_link.rb