unidom-authorization 1.4.4 → 1.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -7
- data/app/controllers/unidom/authorization/application_controller.rb +3 -0
- data/app/jobs/unidom/authorization/application_job.rb +3 -0
- data/app/mailers/unidom/authorization/application_mailer.rb +3 -0
- data/app/models/unidom/authorization/application_record.rb +3 -0
- data/app/models/unidom/authorization/authorizing.rb +5 -1
- data/app/models/unidom/authorization/concerns/as_authorized.rb +7 -0
- data/app/models/unidom/authorization/concerns/as_permission.rb +6 -0
- data/app/models/unidom/authorization/permission.rb +1 -1
- data/lib/unidom/authorization/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0452e5f8f9c8d59d999f1d6ec3b3a3fd336d0077
|
4
|
+
data.tar.gz: 28558f7b515d8028f6e7e68735a740d65d2856fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5c900343d6233b7f173ac002b677aaf036474a6bf15e618249f1c09a6663949b2c99d881210ec3c0ad2e1a03b9bbed7a2df3e53a1d10f0e9c72cd29dec93460
|
7
|
+
data.tar.gz: 932228df055c759573f05607146c2c890f5f0c41b9fc933cd3cd27dfb5e7b8c800765f2ef0fc943415c5eb865cc5831b2d30cfd984a0af9a6d2309b25b669e9f
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Unidom Authorization 授权领域模型引擎
|
2
2
|
|
3
|
+
[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/unidom-authorization/frames)
|
3
4
|
[![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
|
5
|
+
|
4
6
|
[![Gem Version](https://badge.fury.io/rb/unidom-authorization.svg)](https://badge.fury.io/rb/unidom-authorization)
|
5
7
|
[![Dependency Status](https://gemnasium.com/badges/github.com/topbitdu/unidom-authorization.svg)](https://gemnasium.com/github.com/topbitdu/unidom-authorization)
|
6
8
|
|
@@ -62,15 +64,36 @@ include Unidom::Authorization::Concerns::AsPermission
|
|
62
64
|
|
63
65
|
### As Authorized concern
|
64
66
|
|
65
|
-
The As Authorized 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', as: :authorized``
|
67
|
-
|
68
|
-
|
67
|
+
The As Authorized concern do the following tasks for the includer automatically:
|
68
|
+
1. Define the has_many :authorizings macro as: ``has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing', as: :authorized``
|
69
|
+
|
70
|
+
2. Define the has_many :permissions macro as: ``has_many :permissions, through: :authorizings, source: :permission``
|
71
|
+
|
72
|
+
3. Define the #is_authorized! method as: ``is_authorized!(permission: nil, by: nil, at: Time.now)``
|
73
|
+
|
69
74
|
4. Define the #is_authorized? method as: ``is_authorized?(permission: nil, at: Time.now)``
|
70
75
|
|
71
76
|
### As Permission concern
|
72
77
|
|
73
|
-
The As Permission concern do the following tasks for the includer automatically:
|
74
|
-
1. Define the has_many :authorizings macro as: ``has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing'``
|
75
|
-
|
78
|
+
The As Permission concern do the following tasks for the includer automatically:
|
79
|
+
1. Define the has_many :authorizings macro as: ``has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing'``
|
80
|
+
|
81
|
+
2. Define the #authorize! method as: ``authorize!(authorized, by: nil, at: Time.now)``
|
82
|
+
|
76
83
|
3. Define the #authorize? method as: ``authorize?(authorized, at: Time.now)``
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
## Disable the Model & Migration
|
88
|
+
|
89
|
+
If you only need the app components other than models, the migrations should be neglected, and the models should not be loaded.
|
90
|
+
```ruby
|
91
|
+
# config/initializers/unidom.rb
|
92
|
+
Unidom::Common.configure do |options|
|
93
|
+
|
94
|
+
options[:neglected_namespaces] = %w{
|
95
|
+
Unidom::Authorization
|
96
|
+
}
|
97
|
+
|
98
|
+
end
|
99
|
+
```
|
@@ -15,6 +15,10 @@ class Unidom::Authorization::Authorizing < Unidom::Authorization::ApplicationRec
|
|
15
15
|
scope :authorized_is, ->(authorized) { where authorized: authorized }
|
16
16
|
scope :authorized_by, ->(authorizer) { where authorizer: authorizer }
|
17
17
|
|
18
|
+
##
|
19
|
+
# 授予 authorized 权限 permission ,授权者是 authorizer ,授权时间是 opened_at。如:
|
20
|
+
# Unidom::Authorization::Authorizing.authorize! permission: permission,
|
21
|
+
# authorized: selected_person, authorizer: current_person
|
18
22
|
def self.authorize!(permission: nil, authorized: nil, authorizer: nil, opened_at: Time.now)
|
19
23
|
|
20
24
|
assert_present! :permission, permission
|
@@ -33,4 +37,4 @@ class Unidom::Authorization::Authorizing < Unidom::Authorization::ApplicationRec
|
|
33
37
|
|
34
38
|
end
|
35
39
|
|
36
|
-
end
|
40
|
+
end unless Unidom::Common::Neglection.namespace_neglected? 'Unidom::Authorization::Authorizing'
|
@@ -1,3 +1,6 @@
|
|
1
|
+
##
|
2
|
+
# As Authorized 是被授权的参与者或访问者的领域逻辑关注点。
|
3
|
+
|
1
4
|
module Unidom::Authorization::Concerns::AsAuthorized
|
2
5
|
|
3
6
|
extend ActiveSupport::Concern
|
@@ -7,6 +10,10 @@ module Unidom::Authorization::Concerns::AsAuthorized
|
|
7
10
|
has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing', as: :authorized
|
8
11
|
has_many :permissions, through: :authorizings, source: :permission
|
9
12
|
|
13
|
+
##
|
14
|
+
# 将本参与者或访问者,授予指定的权限 permission , by 是授权者, at 是授权时间,缺省为当前时间。如:
|
15
|
+
# 假设 selected_person 对应的类已经 include Unidom::Authorization::Concerns::AsAuthorized 。
|
16
|
+
# selected_person.is_authorized! permission, by: current_person
|
10
17
|
def is_authorized!(permission: nil, by: nil, at: Time.now)
|
11
18
|
|
12
19
|
assert_present! :permission, permission
|
@@ -1,3 +1,6 @@
|
|
1
|
+
##
|
2
|
+
# As Permission 是权限的领域逻辑关注点。
|
3
|
+
|
1
4
|
module Unidom::Authorization::Concerns::AsPermission
|
2
5
|
|
3
6
|
extend ActiveSupport::Concern
|
@@ -6,6 +9,9 @@ module Unidom::Authorization::Concerns::AsPermission
|
|
6
9
|
|
7
10
|
has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing'
|
8
11
|
|
12
|
+
##
|
13
|
+
# 将本权限授予指定的参与者或访问者 authorized , by 是授权者, at 是授权时间,缺省为当前时间。如:
|
14
|
+
# permission.authorize! selected_person, by: current_person
|
9
15
|
def authorize!(authorized, by: nil, at: Time.now)
|
10
16
|
|
11
17
|
assert_present! :authorized, authorized
|
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.
|
4
|
+
version: 1.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Topbit Du
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.9'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.9'
|
27
27
|
description: Unidom (UNIfied Domain Object Model) is a series of domain model engines.
|
28
28
|
The Authorization domain model engine includes the Permission and Authorizing models.
|
29
29
|
Unidom (统一领域对象模型)是一系列的领域模型引擎。授权领域模型引擎包括权限、授权的模型。
|