Sha256: 4446af3f4ca80968ed00fb832074ba3e9a0582f20ef4a920fa42ecae3fdb0d4d

Contents?: true

Size: 875 Bytes

Versions: 14

Compression:

Stored size: 875 Bytes

Contents

# frozen_string_literal: true
module Decidim
  module System
    # A form object used to create organizations from the system dashboard.
    #
    class AdminForm < Rectify::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

14 entries across 14 versions & 2 rubygems

Version Path
decidim-system-0.0.1.alpha9 app/forms/decidim/system/admin_form.rb
decidim-0.0.1.alpha9 decidim-system/app/forms/decidim/system/admin_form.rb
decidim-system-0.0.1.alpha8 app/forms/decidim/system/admin_form.rb
decidim-0.0.1.alpha8 decidim-system/app/forms/decidim/system/admin_form.rb
decidim-system-0.0.1.alpha7 app/forms/decidim/system/admin_form.rb
decidim-0.0.1.alpha7 decidim-system/app/forms/decidim/system/admin_form.rb
decidim-system-0.0.1.alpha6 app/forms/decidim/system/admin_form.rb
decidim-0.0.1.alpha6 decidim-system/app/forms/decidim/system/admin_form.rb
decidim-system-0.0.1.alpha5 app/forms/decidim/system/admin_form.rb
decidim-0.0.1.alpha5 decidim-system/app/forms/decidim/system/admin_form.rb
decidim-system-0.0.1.alpha4 app/forms/decidim/system/admin_form.rb
decidim-0.0.1.alpha4 decidim-system/app/forms/decidim/system/admin_form.rb
decidim-system-0.0.1.alpha3 app/forms/decidim/system/admin_form.rb
decidim-0.0.1.alpha3 decidim-system/app/forms/decidim/system/admin_form.rb