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

Raises:

  • (ArgumentError)


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

def self.authorize!(permission: nil, authorized: nil, authorizer: nil, opened_at: Time.now)
  raise ArgumentError.new('The authorized argument is required.') if authorized.blank?
  raise ArgumentError.new('The opened_at argument is required.' ) if opened_at.blank?
  raise ArgumentError.new('The permission argument is required.') if permission.blank?

  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