unidom-authorization 1.0 → 1.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea29ec666170f123b6e3ff8a9e408a47283f3f69
|
4
|
+
data.tar.gz: 959fb6bbba7b827b9090fe9536ed5f8aff7f38b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42d1405280d706980f7922d05844dde1ee83c755083a58688ad59100a16963ea0b25b24bf9812e1f1290ed575ee227abf53553606fdb820400086f9a072bd480
|
7
|
+
data.tar.gz: 428228b087dce180039c7a994a56b6a83dcd2c6a7e1578c640e9a347a62b8a147868f3f913ed6562f4b0f1b4c5c9312b755cbc6d117b21ce5e1010f576c55888
|
data/README.md
CHANGED
@@ -27,5 +27,21 @@ Unidom::Authorization::Permission.valid_at.alive
|
|
27
27
|
Unidom::Authorization::Authorizing.valid_at.alive
|
28
28
|
|
29
29
|
permission = Unidom::Authorization::Permission.valid_at.alive.first
|
30
|
+
|
31
|
+
permission.authorized? user, at: Time.now # false
|
30
32
|
Unidom::Authorization::Authorizing.authorize! permission: permission, authorized: user
|
33
|
+
# or
|
34
|
+
permission.authorize! user, by: current_user, at: Time.now
|
35
|
+
permission.authorized? user, at: Time.now # true
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
## Include the Conerns
|
40
|
+
```ruby
|
41
|
+
include Unidom::Authorization::Concerns::AsAuthorized
|
31
42
|
```
|
43
|
+
|
44
|
+
### As Authorized concern
|
45
|
+
The As Authorized concern do the following tasks for the includer automatically:
|
46
|
+
1. Define the has_many :authorizings macro as: ``has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing', as: :authorized``
|
47
|
+
2. Define the has_many :permissions macro as: ``has_many :permissions, through: :authorizings, source: :permission``
|
@@ -4,7 +4,8 @@ module Unidom::Authorization::Concerns::AsAuthorized
|
|
4
4
|
|
5
5
|
self.included do |includer|
|
6
6
|
|
7
|
-
has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing', as:
|
7
|
+
has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing', as: :authorized
|
8
|
+
has_many :permissions, through: :authorizings, source: :permission
|
8
9
|
|
9
10
|
end
|
10
11
|
|
@@ -13,4 +13,19 @@ class Unidom::Authorization::Permission < ActiveRecord::Base
|
|
13
13
|
|
14
14
|
scope :path_is, ->(path) { where path: path }
|
15
15
|
|
16
|
+
def authorize!(authorized, by: nil, at: Time.now)
|
17
|
+
attributes = { authorized: authorized, opened_at: at }
|
18
|
+
if by.present?
|
19
|
+
attributes[:authorizer] = by
|
20
|
+
else
|
21
|
+
attributes[:authorizer_id] = Unidom::Common::NULL_UUID
|
22
|
+
attributes[:authorizer_type] = ''
|
23
|
+
end
|
24
|
+
authorizings.create! attributes
|
25
|
+
end
|
26
|
+
|
27
|
+
def authorized?(authorized, at: Time.now)
|
28
|
+
authorizings.authorized_is(authorized).valid_at(now: at).alive.exists?
|
29
|
+
end
|
30
|
+
|
16
31
|
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.
|
4
|
+
version: '1.1'
|
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-07-
|
11
|
+
date: 2016-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|