Class: Unidom::Authorization::Authorizing

Inherits:
ApplicationRecord 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: nil, authorized: nil, authorizer: nil, opened_at: Time.now) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/unidom/authorization/authorizing.rb', line 22

def self.authorize!(permission: nil, authorized: nil, authorizer: nil, opened_at: Time.now)

  assert_present! :permission, permission
  assert_present! :authorized, authorized
  assert_present! :opened_at,  opened_at

  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