unidom-authorization 1.6.8 → 1.6.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -0
- data/app/models/unidom/authorization/concerns/as_authorized.rb +8 -0
- data/app/models/unidom/authorization/concerns/as_permission.rb +6 -0
- data/lib/rspec/models/unidom/authorization/authorizing_shared_examples.rb +19 -0
- data/lib/rspec/models/unidom/authorization/permission_spec.rb +2 -1
- data/lib/unidom/authorization/rspec_shared_examples.rb +1 -0
- data/lib/unidom/authorization/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 994100e1608a14874fe229bd1e7fc01d14a3a3ea
|
4
|
+
data.tar.gz: 1f61900ac12296b2b0ea670e4ac6b8b1db0fb369
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6ccc25c14df6fea53f8ab442e4f5bc95fcb50f1e45d561252929bfddfb9f7092912559eb60be58398b069f93a913c097dca4de3573c7019b32fd16792a161a4
|
7
|
+
data.tar.gz: fc678376a6f47aca5449b3ed0841fe64d3019ff25ea66b6ede20144ab07f1a3a5899e4ea23a6931a91b1c8ba764b3fdb4226d7343c668e26662bebaa2d9f6616
|
data/README.md
CHANGED
@@ -218,5 +218,31 @@ describe Unidom::Authorization::Permission, type: :model do
|
|
218
218
|
|
219
219
|
end
|
220
220
|
|
221
|
+
end
|
222
|
+
|
223
|
+
# spec/models/unidom/authorization/authorizing_spec.rb
|
224
|
+
describe Unidom::Authorization::Authorizing, type: :model do
|
225
|
+
|
226
|
+
before :each do
|
227
|
+
end
|
228
|
+
|
229
|
+
after :each do
|
230
|
+
end
|
231
|
+
|
232
|
+
context do
|
233
|
+
|
234
|
+
model_attributes = {
|
235
|
+
authorizer_id: SecureRandom.uuid,
|
236
|
+
authorizer_type: 'Unidom::Authorization::Authorizer::Mock',
|
237
|
+
authorized_id: SecureRandom.uuid,
|
238
|
+
authorized_type: 'Unidom::Authorization::Authorized::Mock',
|
239
|
+
permission_id: SecureRandom.uuid
|
240
|
+
}
|
241
|
+
authorizer_class_list = [ Unidom::Visitor::User, Unidom::Party::Person ]
|
242
|
+
|
243
|
+
it_behaves_like 'Unidom::Authorization::Authorizing', model_attributes, authorizer_class_list, [ {}, { name: 'Tim' } ]
|
244
|
+
|
245
|
+
end
|
246
|
+
|
221
247
|
end
|
222
248
|
```
|
@@ -14,6 +14,8 @@ module Unidom::Authorization::Concerns::AsAuthorized
|
|
14
14
|
# 将本参与者或访问者,授予指定的权限 permission , by 是授权者, at 是授权时间,缺省为当前时间。如:
|
15
15
|
# 假设 selected_person 对应的类已经 include Unidom::Authorization::Concerns::AsAuthorized 。
|
16
16
|
# selected_person.is_authorized! permission, by: current_person
|
17
|
+
# # or
|
18
|
+
# selected_person.is_authorized! permission, by: current_person, at: Time.now
|
17
19
|
def is_authorized!(permission: nil, by: nil, at: Time.now)
|
18
20
|
|
19
21
|
assert_present! :permission, permission
|
@@ -24,6 +26,12 @@ module Unidom::Authorization::Concerns::AsAuthorized
|
|
24
26
|
|
25
27
|
end
|
26
28
|
|
29
|
+
##
|
30
|
+
# 判断本参与者或访问者,在给定的时间 at 是否拥有给定的权限 permission 。如:
|
31
|
+
# 假设 selected_person 对应的类已经 include Unidom::Authorization::Concerns::AsAuthorized 。
|
32
|
+
# selected_person.is_authorized? permission
|
33
|
+
# # or
|
34
|
+
# selected_person.is_authorized? permission, at: Time.now
|
27
35
|
def is_authorized?(permission: nil, at: Time.now)
|
28
36
|
|
29
37
|
assert_present! :permission, permission
|
@@ -30,6 +30,12 @@ module Unidom::Authorization::Concerns::AsPermission
|
|
30
30
|
|
31
31
|
end
|
32
32
|
|
33
|
+
##
|
34
|
+
# 判断当前权限,在给定的时间 at 是否授权给指定的参与者或访问者 authorized 。如:
|
35
|
+
# 假设 selected_person 对应的类已经 include Unidom::Authorization::Concerns::AsAuthorized 。
|
36
|
+
# permission.authorize? selected_person
|
37
|
+
# # or
|
38
|
+
# permission.authorize? selected_person, at: Time.now
|
33
39
|
def authorize?(authorized, at: Time.now)
|
34
40
|
|
35
41
|
assert_present! :authorized, authorized
|
@@ -0,0 +1,19 @@
|
|
1
|
+
shared_examples 'Unidom::Authorization::Authorizing' do |model_attributes, authorizer_class_list, authorizer_attributes_list|
|
2
|
+
|
3
|
+
before :each do
|
4
|
+
end
|
5
|
+
|
6
|
+
after :each do
|
7
|
+
end
|
8
|
+
|
9
|
+
context do
|
10
|
+
|
11
|
+
authorizer_class_list.each_with_index do |authorizer_class, index|
|
12
|
+
it_behaves_like 'belongs_to', model_attributes, :authorizer, authorizer_class, authorizer_attributes_list[index]
|
13
|
+
end
|
14
|
+
|
15
|
+
it_behaves_like 'polymorphic scope', model_attributes, :authorized_by, :authorizer, authorizer_class_list
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -23,7 +23,8 @@ describe Unidom::Authorization::Permission, type: :model do
|
|
23
23
|
it_behaves_like 'scope', :path_is, [
|
24
24
|
{ attributes_collection: [ model_attributes ], count_diff: 1, args: [ model_attributes[:path] ] },
|
25
25
|
{ attributes_collection: [ model_attributes ], count_diff: 0, args: [ "/#{model_attributes[:path]}" ] },
|
26
|
-
{ attributes_collection: [ model_attributes ], count_diff: 0, args: [ "#{model_attributes[:path]}.html" ] }
|
26
|
+
{ attributes_collection: [ model_attributes ], count_diff: 0, args: [ "#{model_attributes[:path]}.html" ] }
|
27
|
+
]
|
27
28
|
|
28
29
|
end
|
29
30
|
|
@@ -1,3 +1,4 @@
|
|
1
1
|
require 'rspec/models/unidom/authorization/concerns/as_authorized_shared_examples'
|
2
2
|
require 'rspec/models/unidom/authorization/concerns/as_permission_shared_examples'
|
3
|
+
require 'rspec/models/unidom/authorization/authorizing_shared_examples'
|
3
4
|
require 'rspec/models/unidom/authorization/permission_shared_examples'
|
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.6.
|
4
|
+
version: 1.6.9
|
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-04-
|
11
|
+
date: 2017-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- config/routes.rb
|
53
53
|
- db/migrate/20000401000000_create_unidom_permissions.rb
|
54
54
|
- db/migrate/20000402000000_create_unidom_authorizings.rb
|
55
|
+
- lib/rspec/models/unidom/authorization/authorizing_shared_examples.rb
|
55
56
|
- lib/rspec/models/unidom/authorization/authorizing_spec.rb
|
56
57
|
- lib/rspec/models/unidom/authorization/concerns/as_authorized_shared_examples.rb
|
57
58
|
- lib/rspec/models/unidom/authorization/concerns/as_permission_shared_examples.rb
|