Sha256: 31ca879c0ea7c5f0383ef58fde2c0d00d429007ac862e06b3a4ee8ebc2a7f3de

Contents?: true

Size: 582 Bytes

Versions: 18

Compression:

Stored size: 582 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A form object to create or update scopes.
    class ScopeForm < Form
      attribute :name, String
      attribute :organization, Decidim::Organization
      mimic :scope

      validates :name, :organization, presence: true
      validate :name, :name_uniqueness

      alias organization current_organization

      private

      def name_uniqueness
        return unless organization && organization.scopes.where(name: name).where.not(id: id).any?

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

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
decidim-admin-0.4.4 app/forms/decidim/admin/scope_form.rb
decidim-0.4.4 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-admin-0.4.3 app/forms/decidim/admin/scope_form.rb
decidim-admin-0.4.2 app/forms/decidim/admin/scope_form.rb
decidim-admin-0.4.1 app/forms/decidim/admin/scope_form.rb
decidim-0.4.3 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-0.4.2 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-0.4.1 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-admin-0.4.0 app/forms/decidim/admin/scope_form.rb
decidim-0.4.0 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-admin-0.3.2 app/forms/decidim/admin/scope_form.rb
decidim-0.3.2 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-admin-0.3.1 app/forms/decidim/admin/scope_form.rb
decidim-0.3.1 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-admin-0.3.0 app/forms/decidim/admin/scope_form.rb
decidim-0.3.0 decidim-admin/app/forms/decidim/admin/scope_form.rb
decidim-admin-0.2.0 app/forms/decidim/admin/scope_form.rb
decidim-0.2.0 decidim-admin/app/forms/decidim/admin/scope_form.rb