Sha256: ad602a1e22f8ab6b225360eadf759f4fe946c012823159fe5445bf94a8032a1e

Contents?: true

Size: 487 Bytes

Versions: 58

Compression:

Stored size: 487 Bytes

Contents

# frozen_string_literal: true

# This validator ensures the scope is a scope of a component scope
class ScopeBelongsToComponentValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    return unless component_for(record)

    record.errors.add(attribute, :invalid) if component_for(record).out_of_scope?(Decidim::Scope.find_by(id: value))
  end

  private

  def component_for(record)
    record.try(:component) || record.try(:current_component)
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.28.4 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.27.9 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.29.0 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.28.3 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.27.8 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.29.0.rc4 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.29.0.rc3 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.29.0.rc2 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.29.0.rc1 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.28.2 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.27.7 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.28.1 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.27.6 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.26.10 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.26.9 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.28.0 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.27.5 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.28.0.rc5 app/validators/scope_belongs_to_component_validator.rb
decidim-core-0.28.0.rc4 app/validators/scope_belongs_to_component_validator.rb