unidom-authorization 1.2.2 → 1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc7cb42df9b566ea577fad8bbfed1a42f397855f
4
- data.tar.gz: 1d8969dddc67a104804172509b1daac0cbb885c6
3
+ metadata.gz: e92ebc01f042c72654ae42e148df2a1f6def842d
4
+ data.tar.gz: 4a69e629d0b8d1a3ac2b81573ec095826d2349b0
5
5
  SHA512:
6
- metadata.gz: 5d1ac5c39da3800449b37cf90b5c8f363347c3330bfb16b3cb166e13b45d35414d64c50cc545c0aa7b1e6cae44e5aad7b630cf792e9a0908fb947e30a0a00a42
7
- data.tar.gz: e36afb6e5124a89df5ece889588bfb6df61e70e33d832c792326268208132e0586947b4f0d1beddc03e2a490bc23e15e07106e7f6aae385f8a2a44044b5917e4
6
+ metadata.gz: 6e7741f794d5b0109029db0077a912b5fcd6cadafa3e2dfdf3cf419b65fa5b09ec4a78aa72f06107f472dafe858e1b73f5e707227d218eb19a2096157cea2ead
7
+ data.tar.gz: f62ea63e6380558dfb33bd4e31a957a2d7c28f4493bf7d65f1c483d866b5fa1407817a1d5582201450979299db33ae6663257a896faecb5380d4d6e5269fa681
data/README.md CHANGED
@@ -6,21 +6,29 @@
6
6
  Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Authorization domain model engine includes the Permission and Authorizing models.
7
7
  Unidom (统一领域对象模型)是一系列的领域模型引擎。授权领域模型引擎包括权限、授权的模型。
8
8
 
9
+
10
+
9
11
  ## Recent Update
10
12
  Check out the [Road Map](ROADMAP.md) to find out what's the next.
11
13
  Check out the [Change Log](CHANGELOG.md) to find out what's new.
12
14
 
15
+
16
+
13
17
  ## Usage in Gemfile
14
18
  ```ruby
15
19
  gem 'unidom-authorization'
16
20
  ```
17
21
 
22
+
23
+
18
24
  ## Run the Database Migration
19
25
  ```shell
20
26
  rake db:migrate
21
27
  ```
22
28
  The migration versions start with 200004.
23
29
 
30
+
31
+
24
32
  ## Call the Model
25
33
  ```ruby
26
34
  Unidom::Authorization::Permission.valid_at.alive
@@ -32,20 +40,29 @@ permission.authorized? user, at: Time.now # false
32
40
  Unidom::Authorization::Authorizing.authorize! permission: permission, authorized: user
33
41
  # or
34
42
  permission.authorize! user, by: current_user, at: Time.now
35
- permission.authorized? user, at: Time.now # true
43
+ permission.authorize? user, at: Time.now # true
36
44
 
37
45
  user.is_authorized! permission: permission, by: administrator, at: Time.now
38
46
  user.is_authorized? permission: permission, at: Time.now # true
39
47
  ```
40
48
 
49
+
50
+
41
51
  ## Include the Concerns
42
52
  ```ruby
43
53
  include Unidom::Authorization::Concerns::AsAuthorized
54
+ include Unidom::Authorization::Concerns::AsPermission
44
55
  ```
45
56
 
46
57
  ### As Authorized concern
47
58
  The As Authorized concern do the following tasks for the includer automatically:
48
59
  1. Define the has_many :authorizings macro as: ``has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing', as: :authorized``
49
60
  2. Define the has_many :permissions macro as: ``has_many :permissions, through: :authorizings, source: :permission``
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 as: ``def is_authorized?(permission: nil, at: Time.now)``
61
+ 3. Define the #is_authorized! method as: ``is_authorized!(permission: nil, by: nil, at: Time.now)``
62
+ 4. Define the #is_authorized? method as: ``is_authorized?(permission: nil, at: Time.now)``
63
+
64
+ ### As Permission concern
65
+ The As Permission 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'``
67
+ 2. Define the #authorize! method as: ``authorize!(authorized, by: nil, at: Time.now)``
68
+ 3. Define the #authorize? method as: ``authorize?(authorized, at: Time.now)``
@@ -22,4 +22,7 @@ module Unidom::Authorization::Concerns::AsAuthorized
22
22
 
23
23
  end
24
24
 
25
+ module ClassMethods
26
+ end
27
+
25
28
  end
@@ -0,0 +1,47 @@
1
+ module Unidom::Authorization::Concerns::AsPermission
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ included do |includer|
6
+
7
+ has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing'
8
+
9
+ def authorize!(authorized, by: nil, at: Time.now)
10
+
11
+ raise ArgumentError.new('The authorized argument is required.') if authorized.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?
14
+
15
+ attributes = { authorized: authorized, opened_at: at }
16
+ if by.present?
17
+ attributes[:authorizer] = by
18
+ else
19
+ attributes[:authorizer_id] = Unidom::Common::NULL_UUID
20
+ attributes[:authorizer_type] = ''
21
+ end
22
+ authorizings.create! attributes
23
+
24
+ end
25
+
26
+ def authorize?(authorized, at: Time.now)
27
+
28
+ raise ArgumentError.new('The authorized argument is required.') if authorized.blank?
29
+ raise ArgumentError.new('The at argument is required.' ) if at.blank?
30
+
31
+ authorizings.authorized_is(authorized).valid_at(now: at).alive.exists?
32
+
33
+ end
34
+
35
+ def authorized?(authorized, at: Time.now)
36
+
37
+ warn 'The #authorized? method is deprecated. It will be removed in the v2.0. Please use the #authorize? method instead.'
38
+ authorize? authorized, at: at
39
+
40
+ end
41
+
42
+ end
43
+
44
+ module ClassMethods
45
+ end
46
+
47
+ end
@@ -5,37 +5,11 @@ class Unidom::Authorization::Permission < ActiveRecord::Base
5
5
  self.table_name = 'unidom_permissions'
6
6
 
7
7
  include Unidom::Common::Concerns::ModelExtension
8
-
9
- has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing'
8
+ include Unidom::Authorization::Concerns::AsPermission
10
9
 
11
10
  validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit }
12
11
  validates :path, allow_blank: true, length: { in: 2..self.columns_hash['path'].limit }
13
12
 
14
13
  scope :path_is, ->(path) { where path: path }
15
14
 
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
-
22
- attributes = { authorized: authorized, 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
29
- authorizings.create! attributes
30
-
31
- end
32
-
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
-
38
- authorizings.authorized_is(authorized).valid_at(now: at).alive.exists?
39
- end
40
-
41
15
  end
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Authorization
3
- VERSION = '1.2.2'.freeze
3
+ VERSION = '1.3'.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.2
4
+ version: '1.3'
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-09-05 00:00:00.000000000 Z
11
+ date: 2016-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common
@@ -42,6 +42,7 @@ files:
42
42
  - app/helpers/unidom/authorization/application_helper.rb
43
43
  - app/models/unidom/authorization/authorizing.rb
44
44
  - app/models/unidom/authorization/concerns/as_authorized.rb
45
+ - app/models/unidom/authorization/concerns/as_permission.rb
45
46
  - app/models/unidom/authorization/permission.rb
46
47
  - app/views/layouts/unidom/authorization/application.html.erb
47
48
  - config/routes.rb