mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 02:39:37 +02:00
Merge admin and api users
This commit is contained in:
parent
fcd3f4146b
commit
f3215680d5
6 changed files with 114 additions and 37 deletions
32
app/models/admin_user.rb
Normal file
32
app/models/admin_user.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
class AdminUser < User
|
||||
devise :trackable, :timeoutable
|
||||
# TODO: Foreign user will get email with activation link,email,temp-password.
|
||||
# After activisation, system should require to change temp password.
|
||||
# TODO: Estonian id validation
|
||||
|
||||
validates :username, :password, :country_code, presence: true
|
||||
validates :identity_code, uniqueness: true, allow_blank: true
|
||||
validates :identity_code, presence: true, if: -> { country_code == 'EE' }
|
||||
validates :email, presence: true, if: -> { country_code != 'EE' }
|
||||
|
||||
validate :validate_identity_code
|
||||
belongs_to :country_deprecated, foreign_key: :country_id
|
||||
|
||||
ROLES = %w(user customer_service admin)
|
||||
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue