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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91c5653118146a3dbd7da131ececfb0eb9797496
4
- data.tar.gz: de0fd5e0c2c745c729afba0e8556081a5b444683
3
+ metadata.gz: 47b951ac579a7447bedceda83c0963c990e5d3cd
4
+ data.tar.gz: d4f26614fbb5eeb7cbd88c9ca24a3c99ca2dbea9
5
5
  SHA512:
6
- metadata.gz: 1c945e41215385a5ff51f395910bd266a7f7a0aaf355e863795d91ef51f9a39f0c6ef978e075bc1fc411ca9f5d55f5308e5e08ecdb07835d66fd0463db897a05
7
- data.tar.gz: 699a27cec19d92c15b93b72e91a96b7da375263796f185174755f87d465bc9f34c116b18d7346d060764fc750ddac2ace661234063c73fbb476ae9a12ff1c823
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
- it_behaves_like 'Unidom::Authorization::Concerns::AsAuthorized', model_attribtues
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
- it_behaves_like 'Unidom::Authorization::Concerns::AsAuthorized', model_attribtues
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 ActiveSupport::Concern
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
- attributes[:authorizer] = by
23
- else
24
- attributes[:authorizer_id] = Unidom::Common::NULL_UUID
25
- attributes[:authorizer_type] = ''
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
- authorizing_1_attribtues = {
4
- permission_id: SecureRandom.uuid,
5
- authorizer_id: SecureRandom.uuid,
6
- authorizer_type: 'Unidom::Authorization::Authorizer::Mock'
7
- }
3
+ context do
8
4
 
9
- authorizing_2_attribtues = {
10
- permission_id: SecureRandom.uuid,
11
- authorizer_id: SecureRandom.uuid,
12
- authorizer_type: 'Unidom::Authorization::Authorizer::Mock'
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
- it_behaves_like 'has_many', model_attributes, :authorizings, Unidom::Authorization::Authorizing, [ authorizing_1_attribtues, authorizing_2_attribtues ]
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
- authorizing_1_attribtues = {
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
- authorizing_2_attribtues = {
11
- authorized_id: SecureRandom.uuid,
12
- authorized_type: 'Unidom::Authorization::Authorized::Mock',
13
- authorizer_id: SecureRandom.uuid,
14
- authorizer_type: 'Unidom::Authorization::Authorizer::Mock'
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
- it_behaves_like 'has_many', model_attributes, :authorizings, Unidom::Authorization::Authorizing, [ authorizing_1_attribtues, authorizing_2_attribtues ]
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
@@ -0,0 +1,9 @@
1
+ shared_examples 'Unidom::Authorization::Permission' do |model_attributes, authorized, authorizer|
2
+
3
+ context do
4
+
5
+ it_behaves_like 'Unidom::Authorization::Concerns::AsPermission', model_attributes, authorized, authorizer
6
+
7
+ end
8
+
9
+ 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
@@ -1,2 +1,3 @@
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/permission_shared_examples'
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Authorization
3
- VERSION = '1.6.5'.freeze
3
+ VERSION = '1.6.6'.freeze
4
4
  end
5
5
  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.5
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-23 00:00:00.000000000 Z
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