mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
33 lines
1,004 B
Ruby
33 lines
1,004 B
Ruby
class AdminUser < User
|
|
validates :username, :country_code, :roles, presence: true
|
|
validates :identity_code, uniqueness: true, allow_blank: true
|
|
validates :identity_code, presence: true, if: -> { country_code == 'EE' }
|
|
validates :email, presence: true
|
|
validates :password, :password_confirmation, presence: true, if: :new_record?
|
|
validates :password_confirmation, presence: true, if: :encrypted_password_changed?
|
|
validate :validate_identity_code, if: -> { country_code == 'EE' }
|
|
|
|
ROLES = %w(user customer_service admin) # should not match to api_users roles
|
|
|
|
devise :database_authenticatable, :rememberable, :trackable, :validatable, :lockable
|
|
|
|
def self.min_password_length
|
|
Devise.password_length.min
|
|
end
|
|
|
|
def to_s
|
|
username
|
|
end
|
|
|
|
def country
|
|
Country.new(country_code)
|
|
end
|
|
|
|
private
|
|
|
|
def validate_identity_code
|
|
return unless identity_code.present?
|
|
code = Isikukood.new(identity_code)
|
|
errors.add(:identity_code, :invalid) unless code.valid?
|
|
end
|
|
end
|