unidom-authorization 1.3 → 1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e92ebc01f042c72654ae42e148df2a1f6def842d
4
- data.tar.gz: 4a69e629d0b8d1a3ac2b81573ec095826d2349b0
3
+ metadata.gz: 4cf0961f1843a8b6345fb9d4c2e47d272cdff6b5
4
+ data.tar.gz: 88a981b09287bd6344624c95d6f62db57fb1862e
5
5
  SHA512:
6
- metadata.gz: 6e7741f794d5b0109029db0077a912b5fcd6cadafa3e2dfdf3cf419b65fa5b09ec4a78aa72f06107f472dafe858e1b73f5e707227d218eb19a2096157cea2ead
7
- data.tar.gz: f62ea63e6380558dfb33bd4e31a957a2d7c28f4493bf7d65f1c483d866b5fa1407817a1d5582201450979299db33ae6663257a896faecb5380d4d6e5269fa681
6
+ metadata.gz: 7eba7c80d048bcfdac0ae9e47af0d6bbdfaf92e77f3e0b071f99346dac1400f85a230e15d8bc44becc2d63e7c7f07eee6c9577d813e0d4818bd5965de416629e
7
+ data.tar.gz: 17137ef55a188f21da4ba28348b0b4ce1f292208f21a18699d3cbc87fa4bafece7905163ec87da4f81b4ffa80ea850fc8db4381f3ba938d9d353ef9a6dd9d396
data/README.md CHANGED
@@ -56,13 +56,13 @@ include Unidom::Authorization::Concerns::AsPermission
56
56
 
57
57
  ### As Authorized concern
58
58
  The As Authorized concern do the following tasks for the includer automatically:
59
- 1. Define the has_many :authorizings macro as: ``has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing', as: :authorized``
60
- 2. Define the has_many :permissions macro as: ``has_many :permissions, through: :authorizings, source: :permission``
61
- 3. Define the #is_authorized! method as: ``is_authorized!(permission: nil, by: nil, at: Time.now)``
59
+ 1. Define the has_many :authorizings macro as: ``has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing', as: :authorized``
60
+ 2. Define the has_many :permissions macro as: ``has_many :permissions, through: :authorizings, source: :permission``
61
+ 3. Define the #is_authorized! method as: ``is_authorized!(permission: nil, by: nil, at: Time.now)``
62
62
  4. Define the #is_authorized? method as: ``is_authorized?(permission: nil, at: Time.now)``
63
63
 
64
64
  ### As Permission concern
65
65
  The As Permission concern do the following tasks for the includer automatically:
66
- 1. Define the has_many :authorizings macro as: ``has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing'``
67
- 2. Define the #authorize! method as: ``authorize!(authorized, by: nil, at: Time.now)``
68
- 3. Define the #authorize? method as: ``authorize?(authorized, at: Time.now)``
66
+ 1. Define the has_many :authorizings macro as: ``has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing'``
67
+ 2. Define the #authorize! method as: ``authorize!(authorized, by: nil, at: Time.now)``
68
+ 3. Define the #authorize? method as: ``authorize?(authorized, at: Time.now)``
@@ -15,9 +15,10 @@ class Unidom::Authorization::Authorizing < ActiveRecord::Base
15
15
  scope :authorized_by, ->(authorizer) { where authorizer: authorizer }
16
16
 
17
17
  def self.authorize!(permission: nil, authorized: nil, authorizer: nil, opened_at: Time.now)
18
- raise ArgumentError.new('The authorized argument is required.') if authorized.blank?
19
- raise ArgumentError.new('The opened_at argument is required.' ) if opened_at.blank?
20
- raise ArgumentError.new('The permission argument is required.') if permission.blank?
18
+
19
+ assert_present! :permission, permission
20
+ assert_present! :authorized, authorized
21
+ assert_present! :opened_at, opened_at
21
22
 
22
23
  attributes = { opened_at: opened_at }
23
24
  if authorizer.present?
@@ -26,7 +27,9 @@ class Unidom::Authorization::Authorizing < ActiveRecord::Base
26
27
  attributes[:authorizer_id] = Unidom::Common::NULL_UUID
27
28
  attributes[:authorizer_type] = ''
28
29
  end
30
+
29
31
  self.authorized_is(authorized).permission_is(permission).valid_at.alive.first_or_create! attributes
32
+
30
33
  end
31
34
 
32
35
  end
@@ -8,16 +8,22 @@ module Unidom::Authorization::Concerns::AsAuthorized
8
8
  has_many :permissions, through: :authorizings, source: :permission
9
9
 
10
10
  def is_authorized!(permission: nil, by: nil, at: Time.now)
11
- raise ArgumentError.new('The permission argument is required.') if permission.blank?
12
- raise ArgumentError.new('The by argument is required.' ) if by.blank?
13
- raise ArgumentError.new('The at argument is required.' ) if at.blank?
11
+
12
+ assert_present! :permission, permission
13
+ assert_present! :by, by
14
+ assert_present! :at, at
15
+
14
16
  authorizings.create! permission: permission, authorizer: by, opened_at: at
17
+
15
18
  end
16
19
 
17
20
  def is_authorized?(permission: nil, at: Time.now)
18
- raise ArgumentError.new('The permission argument is required.') if permission.blank?
19
- raise ArgumentError.new('The at argument is required.' ) if at.blank?
21
+
22
+ assert_present! :permission, permission
23
+ assert_present! :at, at
24
+
20
25
  authorizings.permission_is(permission).valid_at(now: at).alive.exists?
26
+
21
27
  end
22
28
 
23
29
  end
@@ -8,9 +8,8 @@ module Unidom::Authorization::Concerns::AsPermission
8
8
 
9
9
  def authorize!(authorized, by: nil, at: Time.now)
10
10
 
11
- raise ArgumentError.new('The authorized argument is required.') if authorized.blank?
12
- raise ArgumentError.new('The by argument is required.' ) if by.blank?
13
- raise ArgumentError.new('The at argument is required.' ) if at.blank?
11
+ assert_present! :authorized, authorized
12
+ assert_present! :at, at
14
13
 
15
14
  attributes = { authorized: authorized, opened_at: at }
16
15
  if by.present?
@@ -25,8 +24,8 @@ module Unidom::Authorization::Concerns::AsPermission
25
24
 
26
25
  def authorize?(authorized, at: Time.now)
27
26
 
28
- raise ArgumentError.new('The authorized argument is required.') if authorized.blank?
29
- raise ArgumentError.new('The at argument is required.' ) if at.blank?
27
+ assert_present! :authorized, authorized
28
+ assert_present! :at, at
30
29
 
31
30
  authorizings.authorized_is(authorized).valid_at(now: at).alive.exists?
32
31
 
@@ -5,9 +5,9 @@ class CreateUnidomAuthorizings < ActiveRecord::Migration
5
5
  create_table :unidom_authorizings, id: :uuid do |t|
6
6
 
7
7
  t.references :authorizer, type: :uuid, null: false,
8
- polymorphic: { type: :uuid, null: false }
8
+ polymorphic: { null: false, limit: 200 }
9
9
  t.references :authorized, type: :uuid, null: false,
10
- polymorphic: { type: :uuid, null: false }
10
+ polymorphic: { null: false, limit: 200 }
11
11
  t.references :permission, type: :uuid, null: false
12
12
 
13
13
  t.text :description
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Authorization
3
- VERSION = '1.3'.freeze
3
+ VERSION = '1.4'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-authorization
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.3'
4
+ version: '1.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-20 00:00:00.000000000 Z
11
+ date: 2016-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common