Sha256: ddaa4d1ed3b6587ec7c6a8a7c8f177a8c3883ddfb26f53e67152be1bec3ae9ee

Contents?: true

Size: 893 Bytes

Versions: 22

Compression:

Stored size: 893 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 && organization.scopes.where(code: code).where.not(id: id).any?

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

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
decidim-admin-0.6.8 app/forms/decidim/admin/scope_form.rb
decidim-0.6.8 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-admin-0.6.7 app/forms/decidim/admin/scope_form.rb
decidim-0.6.7 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-admin-0.6.6 app/forms/decidim/admin/scope_form.rb
decidim-0.6.6 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-admin-0.6.5 app/forms/decidim/admin/scope_form.rb
decidim-0.6.5 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-admin-0.6.4 app/forms/decidim/admin/scope_form.rb
decidim-0.6.4 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-admin-0.6.3 app/forms/decidim/admin/scope_form.rb
decidim-0.6.3 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-admin-0.6.2 app/forms/decidim/admin/scope_form.rb
decidim-0.6.2 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-admin-0.6.1 app/forms/decidim/admin/scope_form.rb
decidim-0.6.1 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-admin-0.6.0 app/forms/decidim/admin/scope_form.rb
decidim-0.6.0 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-admin-0.5.1 app/forms/decidim/admin/scope_form.rb
decidim-0.5.1 decidim-admin/app/forms/decidim/admin/scope_form.rb