Sha256: 9d0eaf9baab5109bb4c1b0c00b366765a2150b3611e58734f6312b7bdacc1c15

Contents?: true

Size: 905 Bytes

Versions: 13

Compression:

Stored size: 905 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A form object to create or update scopes.
    class ScopeForm < Form
      include TranslatableAttributes

      translatable_attribute :name, String
      attribute :organization, Decidim::Organization
      attribute :code, String
      attribute :parent_id, Integer
      attribute :scope_type_id, Integer

      mimic :scope

      validates :name, translatable_presence: true
      validates :organization, :code, presence: true
      validate :code, :code_uniqueness

      alias organization current_organization

      def scope_type
        Decidim::ScopeType.find_by(id: scope_type_id) if scope_type_id
      end

      private

      def code_uniqueness
        return unless organization
        return unless organization.scopes.where(code:).where.not(id:).any?

        errors.add(:code, :taken)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-admin-0.29.1 app/forms/decidim/admin/scope_form.rb
decidim-admin-0.28.4 app/forms/decidim/admin/scope_form.rb
decidim-admin-0.29.0 app/forms/decidim/admin/scope_form.rb
decidim-admin-0.28.3 app/forms/decidim/admin/scope_form.rb
decidim-admin-0.29.0.rc4 app/forms/decidim/admin/scope_form.rb
decidim-admin-0.29.0.rc3 app/forms/decidim/admin/scope_form.rb
decidim-admin-0.29.0.rc2 app/forms/decidim/admin/scope_form.rb
decidim-admin-0.29.0.rc1 app/forms/decidim/admin/scope_form.rb
decidim-admin-0.28.2 app/forms/decidim/admin/scope_form.rb
decidim-admin-0.28.1 app/forms/decidim/admin/scope_form.rb
decidim-admin-0.28.0 app/forms/decidim/admin/scope_form.rb
decidim-admin-0.28.0.rc5 app/forms/decidim/admin/scope_form.rb
decidim-admin-0.28.0.rc4 app/forms/decidim/admin/scope_form.rb