Sha256: 6b5032ff789d3a72ce6609439c219a892238c87e735f72a35d4c54e8f4fda079

Contents?: true

Size: 866 Bytes

Versions: 17

Compression:

Stored size: 866 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

17 entries across 17 versions & 2 rubygems

Version Path
decidim-system-0.1.0 app/forms/decidim/system/admin_form.rb
decidim-0.1.0 decidim-system/app/forms/decidim/system/admin_form.rb
decidim-system-0.0.8.1 app/forms/decidim/system/admin_form.rb
decidim-0.0.8.1 decidim-system/app/forms/decidim/system/admin_form.rb
decidim-system-0.0.7 app/forms/decidim/system/admin_form.rb
decidim-0.0.7 decidim-system/app/forms/decidim/system/admin_form.rb
decidim-system-0.0.6 app/forms/decidim/system/admin_form.rb
decidim-0.0.6 decidim-system/app/forms/decidim/system/admin_form.rb
decidim-system-0.0.5 app/forms/decidim/system/admin_form.rb
decidim-0.0.5 decidim-system/app/forms/decidim/system/admin_form.rb
decidim-0.0.4 decidim-system/app/forms/decidim/system/admin_form.rb
decidim-system-0.0.3 app/forms/decidim/system/admin_form.rb
decidim-0.0.3 decidim-system/app/forms/decidim/system/admin_form.rb
decidim-system-0.0.2 app/forms/decidim/system/admin_form.rb
decidim-0.0.2 decidim-system/app/forms/decidim/system/admin_form.rb
decidim-system-0.0.1 app/forms/decidim/system/admin_form.rb
decidim-0.0.1 decidim-system/app/forms/decidim/system/admin_form.rb