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 +4 -4
- data/README.md +6 -6
- data/app/models/unidom/authorization/authorizing.rb +6 -3
- data/app/models/unidom/authorization/concerns/as_authorized.rb +11 -5
- data/app/models/unidom/authorization/concerns/as_permission.rb +4 -5
- data/db/migrate/20000402000000_create_unidom_authorizings.rb +2 -2
- data/lib/unidom/authorization/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cf0961f1843a8b6345fb9d4c2e47d272cdff6b5
|
4
|
+
data.tar.gz: 88a981b09287bd6344624c95d6f62db57fb1862e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
19
|
-
|
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
|
-
|
12
|
-
|
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
|
-
|
29
|
-
|
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: {
|
8
|
+
polymorphic: { null: false, limit: 200 }
|
9
9
|
t.references :authorized, type: :uuid, null: false,
|
10
|
-
polymorphic: {
|
10
|
+
polymorphic: { null: false, limit: 200 }
|
11
11
|
t.references :permission, type: :uuid, null: false
|
12
12
|
|
13
13
|
t.text :description
|
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.
|
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-
|
11
|
+
date: 2016-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|