Sha256: 3bb534a14f797440bc737f375226480a4d37dd81232114540f299ec17c214f18

Contents?: true

Size: 867 Bytes

Versions: 111

Compression:

Stored size: 867 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module System
    # A form object used to create organizations from the system dashboard.
    #
    class AdminForm < Form
      mimic :admin

      attribute :email, String
      attribute :password, String
      attribute :password_confirmation, String

      validates :email, presence: true
      validates :password, presence: true, unless: :admin_exists?
      validates :password_confirmation, presence: true, unless: :admin_exists?

      validate :email, :email_uniqueness

      private

      def email_uniqueness
        return unless Admin.where(email: email).where.not(id: id).any?

        errors.add(:email, I18n.t("models.admin.validations.email_uniqueness",
                                  scope: "decidim.system"))
      end

      def admin_exists?
        id.present?
      end
    end
  end
end

Version data entries

111 entries across 111 versions & 2 rubygems

Version Path
decidim-system-0.15.0 app/forms/decidim/system/admin_form.rb
decidim-system-0.14.4 app/forms/decidim/system/admin_form.rb
decidim-system-0.14.3 app/forms/decidim/system/admin_form.rb
decidim-system-0.14.2 app/forms/decidim/system/admin_form.rb
decidim-system-0.14.1 app/forms/decidim/system/admin_form.rb
decidim-system-0.13.1 app/forms/decidim/system/admin_form.rb
decidim-system-0.12.2 app/forms/decidim/system/admin_form.rb
decidim-system-0.13.0 app/forms/decidim/system/admin_form.rb
decidim-system-0.12.1 app/forms/decidim/system/admin_form.rb
decidim-system-0.13.0.pre1 app/forms/decidim/system/admin_form.rb
decidim-system-0.12.0 app/forms/decidim/system/admin_form.rb
decidim-system-0.11.2 app/forms/decidim/system/admin_form.rb
decidim-system-0.12.0.pre app/forms/decidim/system/admin_form.rb
decidim-system-0.11.1 app/forms/decidim/system/admin_form.rb
decidim-system-0.11.0.pre1 app/forms/decidim/system/admin_form.rb
decidim-system-0.10.1 app/forms/decidim/system/admin_form.rb
decidim-system-0.10.0 app/forms/decidim/system/admin_form.rb
decidim-system-0.9.3 app/forms/decidim/system/admin_form.rb
decidim-system-0.9.2 app/forms/decidim/system/admin_form.rb
decidim-system-0.9.1 app/forms/decidim/system/admin_form.rb