Added ApiUser and WhiteIp endpoints to REPP API

This commit is contained in:
Sergei Tsoganov 2023-05-29 14:26:53 +03:00
parent 0442f7f087
commit b84e9e1579
9 changed files with 206 additions and 3 deletions

View file

@ -24,6 +24,7 @@ class ApiUser < User
validates :username, :plain_text_password, :registrar, :roles, presence: true
validates :plain_text_password, length: { minimum: min_password_length }
validates :username, uniqueness: true
validates :identity_code, uniqueness: { scope: :registrar_id }, if: -> { identity_code.present? }
delegate :code, :name, to: :registrar, prefix: true
delegate :legaldoc_mandatory?, to: :registrar
@ -36,6 +37,8 @@ class ApiUser < User
ROLES = %w[super epp billing].freeze # should not match to admin roles
scope :non_super, -> { where.not('roles @> ARRAY[?]::varchar[]', ['super']) }
def ability
@ability ||= Ability.new(self)
end
@ -81,12 +84,16 @@ class ApiUser < User
end
def linked_users
self.class.where(identity_code: identity_code)
self.class.where(identity_code: identity_code, active: true)
.where("identity_code IS NOT NULL AND identity_code != ''")
.where.not(id: id)
.includes(:registrar)
end
def api_users
self.class.where(registrar_id: registrar_id)
end
def linked_with?(another_api_user)
another_api_user.identity_code == identity_code
end
@ -109,6 +116,14 @@ class ApiUser < User
'Accreditation Expire Date', 'Created', 'Updated']
end
def self.ransackable_associations(*)
authorizable_ransackable_associations
end
def self.ransackable_attributes(*)
authorizable_ransackable_attributes
end
private
def machine_readable_certificate(cert)