mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 06:34:46 +02:00
Merge branch 'registry-700' into registry-694
# Conflicts: # db/structure.sql
This commit is contained in:
commit
709dba7664
54 changed files with 535 additions and 274 deletions
|
@ -1,36 +1,14 @@
|
|||
class EppSession < ActiveRecord::Base
|
||||
before_save :marshal_data!
|
||||
belongs_to :user, required: true
|
||||
|
||||
belongs_to :registrar
|
||||
# rubocop: disable Rails/ReadWriteAttribute
|
||||
# Turned back to read_attribute, thus in Rails 4
|
||||
# there is differences between self[:data] and read_attribute.
|
||||
def data
|
||||
@data ||= self.class.unmarshal(read_attribute(:data)) || {}
|
||||
end
|
||||
# rubocop: enable Rails/ReadWriteAttribute
|
||||
validates :session_id, uniqueness: true, presence: true
|
||||
|
||||
def [](key)
|
||||
data[key.to_sym]
|
||||
def self.limit_per_registrar
|
||||
4
|
||||
end
|
||||
|
||||
def []=(key, value)
|
||||
data[key.to_sym] = value
|
||||
save!
|
||||
end
|
||||
|
||||
def marshal_data!
|
||||
self.data = self.class.marshal(data)
|
||||
end
|
||||
|
||||
class << self
|
||||
def marshal(data)
|
||||
::Base64.encode64(Marshal.dump(data)) if data
|
||||
end
|
||||
|
||||
def unmarshal(data)
|
||||
return data unless data.is_a? String
|
||||
Marshal.load(::Base64.decode64(data)) if data
|
||||
end
|
||||
def self.limit_reached?(registrar)
|
||||
count = where(user_id: registrar.api_users.ids).where('updated_at >= ?', Time.zone.now - 1.second).count
|
||||
count >= limit_per_registrar
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue