unidom-authorization 1.6.5 → 1.6.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +50 -2
- data/app/models/unidom/authorization/concerns/as_permission.rb +10 -8
- data/lib/rspec/models/unidom/authorization/concerns/as_authorized_shared_examples.rb +21 -12
- data/lib/rspec/models/unidom/authorization/concerns/as_permission_shared_examples.rb +23 -14
- data/lib/rspec/models/unidom/authorization/permission_shared_examples.rb +9 -0
- data/lib/rspec/models/unidom/authorization/permission_spec.rb +0 -2
- 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: 47b951ac579a7447bedceda83c0963c990e5d3cd
|
4
|
+
data.tar.gz: d4f26614fbb5eeb7cbd88c9ca24a3c99ca2dbea9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d594bfc5375eac418e8be9135e63f8bf26872f9e87f485ebe52142ef60829d0f33bd9fb091e72a86af5ca459a87b916700f04f395bdd433a850b07d3946988fc
|
7
|
+
data.tar.gz: 077d878af12750832c752e3ea4d9e50a6822cae74c33f5ceaa68b202dc3f4c450f204e3b90a28e49f3f12fdf3daf7bc21bc60ae74bccf8562112602aca905cf3
|
data/README.md
CHANGED
@@ -154,7 +154,17 @@ describe Unidom::Party::Person do
|
|
154
154
|
name: 'Tim'
|
155
155
|
}
|
156
156
|
|
157
|
-
|
157
|
+
permission_attributes = {
|
158
|
+
path: 'administration/government_agency/create',
|
159
|
+
name: 'Create Government Agency',
|
160
|
+
opened_at: Time.now
|
161
|
+
}
|
162
|
+
permission = Unidom::Authorization::Permission.create! permission_attributes
|
163
|
+
|
164
|
+
authorizer_attributes = {}
|
165
|
+
authorizer = described_class.create! authorizer_attributes
|
166
|
+
|
167
|
+
it_behaves_like 'Unidom::Authorization::Concerns::AsAuthorized', model_attribtues, permission, authorizer
|
158
168
|
|
159
169
|
end
|
160
170
|
|
@@ -168,7 +178,45 @@ describe Unidom::Position::Post do
|
|
168
178
|
position_id: SecureRandom.uuid
|
169
179
|
}
|
170
180
|
|
171
|
-
|
181
|
+
permission_attributes = {
|
182
|
+
path: 'administration/government_agency/create',
|
183
|
+
name: 'Create Government Agency',
|
184
|
+
opened_at: Time.now
|
185
|
+
}
|
186
|
+
permission = Unidom::Authorization::Permission.create! permission_attributes
|
187
|
+
|
188
|
+
authorizer_attributes = {}
|
189
|
+
authorizer = described_class.create! authorizer_attributes
|
190
|
+
|
191
|
+
it_behaves_like 'Unidom::Authorization::Concerns::AsAuthorized', model_attribtues, permission, authorizer
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
# spec/models/unidom/authorization/permission_spec.rb
|
196
|
+
describe Unidom::Authorization::Permission, type: :model do
|
197
|
+
|
198
|
+
before :each do
|
199
|
+
end
|
200
|
+
|
201
|
+
after :each do
|
202
|
+
end
|
203
|
+
|
204
|
+
context do
|
205
|
+
|
206
|
+
model_attributes = {
|
207
|
+
name: 'User Management',
|
208
|
+
path: 'users'
|
209
|
+
}
|
210
|
+
|
211
|
+
authorized_attributes = {}
|
212
|
+
authorized = Unidom::Visitor::User.create! authorized_attributes
|
213
|
+
|
214
|
+
authorizer_attributes = {}
|
215
|
+
authorizer = Unidom::Visitor::User.create! authorizer_attributes
|
216
|
+
|
217
|
+
it_behaves_like 'Unidom::Authorization::Permission', model_attributes, authorized, authorizer
|
218
|
+
|
219
|
+
end
|
172
220
|
|
173
221
|
end
|
174
222
|
```
|
@@ -3,7 +3,8 @@
|
|
3
3
|
|
4
4
|
module Unidom::Authorization::Concerns::AsPermission
|
5
5
|
|
6
|
-
extend
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
include Unidom::Common::Concerns::ArgumentValidation
|
7
8
|
|
8
9
|
included do |includer|
|
9
10
|
|
@@ -15,15 +16,16 @@ module Unidom::Authorization::Concerns::AsPermission
|
|
15
16
|
def authorize!(authorized, by: nil, at: Time.now)
|
16
17
|
|
17
18
|
assert_present! :authorized, authorized
|
19
|
+
assert_present! :by, by
|
18
20
|
assert_present! :at, at
|
19
21
|
|
20
|
-
attributes = { authorized: authorized, opened_at: at }
|
21
|
-
if by.present?
|
22
|
-
|
23
|
-
else
|
24
|
-
|
25
|
-
|
26
|
-
end
|
22
|
+
attributes = { authorized: authorized, authorizer: by, opened_at: at }
|
23
|
+
#if by.present?
|
24
|
+
# attributes[:authorizer] = by
|
25
|
+
#else
|
26
|
+
# attributes[:authorizer_id] = Unidom::Common::NULL_UUID
|
27
|
+
# attributes[:authorizer_type] = ''
|
28
|
+
#end
|
27
29
|
authorizings.create! attributes
|
28
30
|
|
29
31
|
end
|
@@ -1,17 +1,26 @@
|
|
1
|
-
shared_examples 'Unidom::Authorization::Concerns::AsAuthorized' do |model_attributes|
|
1
|
+
shared_examples 'Unidom::Authorization::Concerns::AsAuthorized' do |model_attributes, permission, authorizer|
|
2
2
|
|
3
|
-
|
4
|
-
permission_id: SecureRandom.uuid,
|
5
|
-
authorizer_id: SecureRandom.uuid,
|
6
|
-
authorizer_type: 'Unidom::Authorization::Authorizer::Mock'
|
7
|
-
}
|
3
|
+
context do
|
8
4
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
authorizing_1_attribtues = {
|
6
|
+
permission_id: SecureRandom.uuid,
|
7
|
+
authorizer_id: SecureRandom.uuid,
|
8
|
+
authorizer_type: 'Unidom::Authorization::Authorizer::Mock'
|
9
|
+
}
|
14
10
|
|
15
|
-
|
11
|
+
authorizing_2_attribtues = {
|
12
|
+
permission_id: SecureRandom.uuid,
|
13
|
+
authorizer_id: SecureRandom.uuid,
|
14
|
+
authorizer_type: 'Unidom::Authorization::Authorizer::Mock'
|
15
|
+
}
|
16
|
+
|
17
|
+
it_behaves_like 'has_many', model_attributes, :authorizings, Unidom::Authorization::Authorizing, [ authorizing_1_attribtues, authorizing_2_attribtues ]
|
18
|
+
|
19
|
+
authorized = described_class.create! model_attributes
|
20
|
+
it_behaves_like 'assert_present!', authorized, :is_authorized!, [ { permission: permission, by: authorizer, at: Time.now } ], [ :permission, :by, :at ]
|
21
|
+
it_behaves_like 'assert_present!', authorized, :is_authorized?, [ { permission: permission, at: Time.now } ], [ :permission, :at ]
|
22
|
+
it_behaves_like 'assert_present!', authorized, :is_prohibited!, [ { permission: permission, at: Time.now } ], [ :permission, :at ]
|
23
|
+
|
24
|
+
end
|
16
25
|
|
17
26
|
end
|
@@ -1,19 +1,28 @@
|
|
1
|
-
shared_examples 'Unidom::Authorization::Concerns::AsPermission' do |model_attributes|
|
1
|
+
shared_examples 'Unidom::Authorization::Concerns::AsPermission' do |model_attributes, authorized, authorizer|
|
2
2
|
|
3
|
-
|
4
|
-
authorized_id: SecureRandom.uuid,
|
5
|
-
authorized_type: 'Unidom::Authorization::Authorized::Mock',
|
6
|
-
authorizer_id: SecureRandom.uuid,
|
7
|
-
authorizer_type: 'Unidom::Authorization::Authorizer::Mock'
|
8
|
-
}
|
3
|
+
context do
|
9
4
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
authorizing_1_attribtues = {
|
6
|
+
authorized_id: SecureRandom.uuid,
|
7
|
+
authorized_type: 'Unidom::Authorization::Authorized::Mock',
|
8
|
+
authorizer_id: SecureRandom.uuid,
|
9
|
+
authorizer_type: 'Unidom::Authorization::Authorizer::Mock'
|
10
|
+
}
|
16
11
|
|
17
|
-
|
12
|
+
authorizing_2_attribtues = {
|
13
|
+
authorized_id: SecureRandom.uuid,
|
14
|
+
authorized_type: 'Unidom::Authorization::Authorized::Mock',
|
15
|
+
authorizer_id: SecureRandom.uuid,
|
16
|
+
authorizer_type: 'Unidom::Authorization::Authorizer::Mock'
|
17
|
+
}
|
18
|
+
|
19
|
+
it_behaves_like 'has_many', model_attributes, :authorizings, Unidom::Authorization::Authorizing, [ authorizing_1_attribtues, authorizing_2_attribtues ]
|
20
|
+
|
21
|
+
permission = described_class.create! model_attributes
|
22
|
+
it_behaves_like 'assert_present!', permission, :authorize!, [ authorized, { by: authorizer, at: Time.now } ], [ { 0 => :authorized }, :by, :at ]
|
23
|
+
it_behaves_like 'assert_present!', permission, :authorize?, [ authorized, { at: Time.now } ], [ { 0 => :authorized }, :at ]
|
24
|
+
it_behaves_like 'assert_present!', permission, :prohibit!, [ authorized, { at: Time.now } ], [ { 0 => :authorized }, :at ]
|
25
|
+
|
26
|
+
end
|
18
27
|
|
19
28
|
end
|
@@ -25,8 +25,6 @@ describe Unidom::Authorization::Permission, type: :model do
|
|
25
25
|
{ attributes_collection: [ model_attributes ], count_diff: 0, args: [ "/#{model_attributes[:path]}" ] },
|
26
26
|
{ attributes_collection: [ model_attributes ], count_diff: 0, args: [ "#{model_attributes[:path]}.html" ] } ]
|
27
27
|
|
28
|
-
it_behaves_like 'Unidom::Authorization::Concerns::AsPermission', model_attributes
|
29
|
-
|
30
28
|
end
|
31
29
|
|
32
30
|
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.6.
|
4
|
+
version: 1.6.6
|
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-03
|
11
|
+
date: 2017-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/rspec/models/unidom/authorization/authorizing_spec.rb
|
56
56
|
- lib/rspec/models/unidom/authorization/concerns/as_authorized_shared_examples.rb
|
57
57
|
- lib/rspec/models/unidom/authorization/concerns/as_permission_shared_examples.rb
|
58
|
+
- lib/rspec/models/unidom/authorization/permission_shared_examples.rb
|
58
59
|
- lib/rspec/models/unidom/authorization/permission_spec.rb
|
59
60
|
- lib/tasks/data_tasks.rake
|
60
61
|
- lib/unidom/authorization.rb
|