Class: Unidom::Authorization::Authorizing

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

Overview

Authorizing 是授权。

Class Method Summary collapse

Class Method Details

.authorize!(permission, authorized, authorizer = nil, opened_at = Time.now) ⇒ Object



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

def self.authorize!(permission, authorized, authorizer = nil, opened_at = Time.now)
  attributes = { opened_at: opened_at }
  if authorizer.present?
    attributes[:authorizer] = authorizer
  else
    attributes[:authorizer_id]   = Unidom::Common::NULL_UUID
    attributes[:authorizer_type] = ''
  end
  self.authorized_is(authorized).permission_is(permission).valid_at.alive.first_or_create! attributes
end