Add RemoteStorageAuthorization model
This commit is contained in:
32
app/models/remote_storage_authorization.rb
Normal file
32
app/models/remote_storage_authorization.rb
Normal file
@@ -0,0 +1,32 @@
|
||||
class RemoteStorageAuthorization < ApplicationRecord
|
||||
belongs_to :user
|
||||
|
||||
serialize :permissions
|
||||
|
||||
validates_presence_of :permissions
|
||||
validates_presence_of :client_id
|
||||
|
||||
scope :valid, -> { where(expire_at: nil).or(where(expire_at: (DateTime.now)..)) }
|
||||
scope :expired, -> { where(expire_at: ..(DateTime.now)) }
|
||||
|
||||
after_initialize do |a|
|
||||
a.permisisons = [] if a.permissions == nil
|
||||
end
|
||||
|
||||
before_create :generate_token
|
||||
|
||||
def url
|
||||
if self.redirect_uri
|
||||
uri = URI.parse self.redirect_uri
|
||||
"#{uri.scheme}://#{client_id}"
|
||||
else
|
||||
"http://#{client_id}"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_token(length=16)
|
||||
self.token = SecureRandom.hex(length) if self.token.blank?
|
||||
end
|
||||
end
|
||||
@@ -14,6 +14,8 @@ class User < ApplicationRecord
|
||||
|
||||
has_many :accounts, through: :lndhub_user
|
||||
|
||||
has_many :remote_storage_authorizations
|
||||
|
||||
validates_uniqueness_of :cn
|
||||
validates_length_of :cn, :minimum => 3
|
||||
validates_format_of :cn, with: /\A([a-z0-9\-])*\z/,
|
||||
|
||||
Reference in New Issue
Block a user