Class: Unidom::Authorization::Permission

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Common::Concerns::ModelExtension
Defined in:
app/models/unidom/authorization/permission.rb

Overview

Permission 是权限。

Instance Method Summary collapse

Instance Method Details

#authorize!(authorized, by: nil, at: Time.now) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'app/models/unidom/authorization/permission.rb', line 16

def authorize!(authorized, by: nil, at: Time.now)
  attributes = { authorized: authorized, opened_at: at }
  if by.present?
    attributes[:authorizer] = by
  else
    attributes[:authorizer_id]   = Unidom::Common::NULL_UUID
    attributes[:authorizer_type] = ''
  end
  authorizings.create! attributes
end

#authorized?(authorized, at: Time.now) ⇒ Boolean



27
28
29
# File 'app/models/unidom/authorization/permission.rb', line 27

def authorized?(authorized, at: Time.now)
  authorizings.authorized_is(authorized).valid_at(now: at).alive.exists?
end