unidom-authorization 1.2.1 → 1.2.2

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: 938d3c07af2bae2879119f6558021fb8b7c83c7d
4
- data.tar.gz: 986b54aa60dc82d89d5736b5436b2b7f0456e371
3
+ metadata.gz: dc7cb42df9b566ea577fad8bbfed1a42f397855f
4
+ data.tar.gz: 1d8969dddc67a104804172509b1daac0cbb885c6
5
5
  SHA512:
6
- metadata.gz: ae487dbf2298af1ac199aeeba40d53bccdcd393ab4b97ee7c44eb913f54c059b534511842db748b237a941b5b6346f0d41e297700296e583138d8c1ec90b06e7
7
- data.tar.gz: 8d775811160698c69ee5b7356f792b2c57c8b0bdfcb9e8673b2ea91823b5854fe338e396d792cc46941f964ebd6cb2d3347b714d5c222c6ecc6778bb80fefcf7
6
+ metadata.gz: 5d1ac5c39da3800449b37cf90b5c8f363347c3330bfb16b3cb166e13b45d35414d64c50cc545c0aa7b1e6cae44e5aad7b630cf792e9a0908fb947e30a0a00a42
7
+ data.tar.gz: e36afb6e5124a89df5ece889588bfb6df61e70e33d832c792326268208132e0586947b4f0d1beddc03e2a490bc23e15e07106e7f6aae385f8a2a44044b5917e4
data/README.md CHANGED
@@ -48,4 +48,4 @@ The As Authorized concern do the following tasks for the includer automatically:
48
48
  1. Define the has_many :authorizings macro as: ``has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing', as: :authorized``
49
49
  2. Define the has_many :permissions macro as: ``has_many :permissions, through: :authorizings, source: :permission``
50
50
  3. Define the #is_authorized! method as: ``def is_authorized!(permission: nil, by: nil, at: Time.now)``
51
- 4. Define the #is_authorized? method ``def is_authorized?(permission: nil, at: Time.now)``
51
+ 4. Define the #is_authorized? method as: ``def is_authorized?(permission: nil, at: Time.now)``
@@ -2,16 +2,21 @@ module Unidom::Authorization::Concerns::AsAuthorized
2
2
 
3
3
  extend ActiveSupport::Concern
4
4
 
5
- self.included do |includer|
5
+ included do |includer|
6
6
 
7
7
  has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing', as: :authorized
8
8
  has_many :permissions, through: :authorizings, source: :permission
9
9
 
10
10
  def is_authorized!(permission: nil, by: nil, at: Time.now)
11
+ raise ArgumentError.new('The permission argument is required.') if permission.blank?
12
+ raise ArgumentError.new('The by argument is required.' ) if by.blank?
13
+ raise ArgumentError.new('The at argument is required.' ) if at.blank?
11
14
  authorizings.create! permission: permission, authorizer: by, opened_at: at
12
15
  end
13
16
 
14
17
  def is_authorized?(permission: nil, at: Time.now)
18
+ raise ArgumentError.new('The permission argument is required.') if permission.blank?
19
+ raise ArgumentError.new('The at argument is required.' ) if at.blank?
15
20
  authorizings.permission_is(permission).valid_at(now: at).alive.exists?
16
21
  end
17
22
 
@@ -14,6 +14,11 @@ class Unidom::Authorization::Permission < ActiveRecord::Base
14
14
  scope :path_is, ->(path) { where path: path }
15
15
 
16
16
  def authorize!(authorized, by: nil, at: Time.now)
17
+
18
+ raise ArgumentError.new('The authorized argument is required.') if authorized.blank?
19
+ raise ArgumentError.new('The by argument is required.' ) if by.blank?
20
+ raise ArgumentError.new('The at argument is required.' ) if at.blank?
21
+
17
22
  attributes = { authorized: authorized, opened_at: at }
18
23
  if by.present?
19
24
  attributes[:authorizer] = by
@@ -22,9 +27,14 @@ class Unidom::Authorization::Permission < ActiveRecord::Base
22
27
  attributes[:authorizer_type] = ''
23
28
  end
24
29
  authorizings.create! attributes
30
+
25
31
  end
26
32
 
27
33
  def authorized?(authorized, at: Time.now)
34
+
35
+ raise ArgumentError.new('The authorized argument is required.') if authorized.blank?
36
+ raise ArgumentError.new('The at argument is required.' ) if at.blank?
37
+
28
38
  authorizings.authorized_is(authorized).valid_at(now: at).alive.exists?
29
39
  end
30
40
 
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Authorization
3
- VERSION = '1.2.1'.freeze
3
+ VERSION = '1.2.2'.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.2.1
4
+ version: 1.2.2
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-08-15 00:00:00.000000000 Z
11
+ date: 2016-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common