unidom-authorization 0.1 → 0.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: e93f7debd3786fd42b3e1a2dd4df29287f2b5214
4
- data.tar.gz: 15e5841fdd32ddfdf452f33b74674bbb11eb0692
3
+ metadata.gz: 858f8c984eb707ee753575de46356fe27455d1dc
4
+ data.tar.gz: 1bd878f287b1ad25081637204ef919587de9a8a1
5
5
  SHA512:
6
- metadata.gz: 60ad21687bd4e0a4ed9cae7f6c63b1ad1694a2bc97ca77675d4d3c870bd9b69dc7bce91a87899d7e9a8f2a40d8f5e03a87cf0e8301340ba0357b3007e224dc72
7
- data.tar.gz: ae7b2328b63ecefb88ae52aaa0efaef0166fca3cec1b9301a4988b4bc5d174978905cd096843168603dc1b359fac961684c270445bfa2dff1d71842c19958ad3
6
+ metadata.gz: 546fcf647a44bc377faaea9593b7994b6378d801378bf5afbfb632d13066a6948f062086e33e49b4c3c495c4c61b4fe27d192a9b8e202cae74939dab381a5884
7
+ data.tar.gz: fc6b336949e154478e30aba6da6a7aae183c61823210e778f4b3a7324f5bfd2d9ef68b8b3a77caa22681ca645befc25a1e5b2d23e6d36cd5aae61afc21243474
data/README.md CHANGED
@@ -6,6 +6,10 @@
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
+ ## Recent Update
10
+ Check out the [Road Map](ROADMAP.md) to find out what's the next.
11
+ Check out the [Change Log](CHANGELOG.md) to find out what's new.
12
+
9
13
  ## Usage in Gemfile
10
14
  ```ruby
11
15
  gem 'unidom-authorization'
@@ -15,9 +19,13 @@ gem 'unidom-authorization'
15
19
  ```shell
16
20
  rake db:migrate
17
21
  ```
22
+ The migration versions start with 200004.
18
23
 
19
24
  ## Call the Model
20
25
  ```ruby
21
26
  Unidom::Authorization::Permission.valid_at.alive
22
27
  Unidom::Authorization::Authorizing.valid_at.alive
28
+
29
+ permission = Unidom::Authorization::Permission.valid_at.alive.first
30
+ Unidom::Authorization::Authorizing.authorize! permission, user
23
31
  ```
@@ -10,4 +10,4 @@
10
10
  // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
- //= require_tree .
13
+ //= require_self
@@ -10,6 +10,5 @@
10
10
  * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
11
  * file per style scope.
12
12
  *
13
- *= require_tree .
14
13
  *= require_self
15
14
  */
@@ -4,6 +4,8 @@ class Unidom::Authorization::Authorizing < ActiveRecord::Base
4
4
 
5
5
  self.table_name = 'unidom_authorizings'
6
6
 
7
+ include Unidom::Common::Concerns::ModelExtension
8
+
7
9
  belongs_to :permission, class_name: 'Unidom::Authorization::Permission'
8
10
  belongs_to :authorizer, polymorphic: true
9
11
  belongs_to :authorized, polymorphic: true
@@ -12,6 +14,15 @@ class Unidom::Authorization::Authorizing < ActiveRecord::Base
12
14
  scope :authorized_is, ->(authorized) { where authorized: authorized }
13
15
  scope :authorized_by, ->(authorizer) { where authorizer: authorizer }
14
16
 
15
- include Unidom::Common::Concerns::ModelExtension
17
+ def self.authorize!(permission, authorized, authorizer = nil, opened_at = Time.now)
18
+ attributes = { opened_at: opened_at }
19
+ if authorizer.present?
20
+ attributes[:authorizer] = authorizer
21
+ else
22
+ attributes[:authorizer_id] = Unidom::Common::NULL_UUID
23
+ attributes[:authorizer_type] = ''
24
+ end
25
+ self.authorized_is(authorized).permission_is(permission).valid_at.alive.first_or_create! attributes
26
+ end
16
27
 
17
28
  end
@@ -0,0 +1,11 @@
1
+ module Unidom::Authorization::Concerns::AsAuthorized
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ self.included do |includer|
6
+
7
+ has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing', as: :authorized
8
+
9
+ end
10
+
11
+ end
@@ -4,6 +4,8 @@ class Unidom::Authorization::Permission < ActiveRecord::Base
4
4
 
5
5
  self.table_name = 'unidom_permissions'
6
6
 
7
+ include Unidom::Common::Concerns::ModelExtension
8
+
7
9
  has_many :authorizings, class_name: 'Unidom::Authorization::Authorizing'
8
10
 
9
11
  validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit }
@@ -11,6 +13,4 @@ class Unidom::Authorization::Permission < ActiveRecord::Base
11
13
 
12
14
  scope :path_is, ->(path) { where path: path }
13
15
 
14
- include Unidom::Common::Concerns::ModelExtension
15
-
16
16
  end
@@ -2,13 +2,14 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>Unidom Authorization</title>
5
- <%= stylesheet_link_tag 'unidom/authorization/application', media: 'all' %>
6
- <%= javascript_include_tag 'unidom/authorization/application' %>
5
+ <%= stylesheet_link_tag 'unidom/authorization/application', media: 'all' %>
7
6
  <%= csrf_meta_tags %>
8
7
  </head>
9
8
  <body>
10
9
 
11
10
  <%= yield %>
12
11
 
12
+ <%= javascript_include_tag 'unidom/authorization/application' %>
13
+
13
14
  </body>
14
15
  </html>
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Authorization
3
- VERSION = '0.1'.freeze
3
+ VERSION = '0.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: '0.1'
4
+ version: '0.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-02-25 00:00:00.000000000 Z
11
+ date: 2016-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.2'
19
+ version: '0.9'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.2'
26
+ version: '0.9'
27
27
  description: Unidom (UNIfied Domain Object Model) is a series of domain model engines.
28
28
  The Authorization domain model engine includes the Permission and Authorizing models.
29
29
  Unidom (统一领域对象模型)是一系列的领域模型引擎。授权领域模型引擎包括权限、授权的模型。
@@ -41,6 +41,7 @@ files:
41
41
  - app/controllers/unidom/authorization/application_controller.rb
42
42
  - app/helpers/unidom/authorization/application_helper.rb
43
43
  - app/models/unidom/authorization/authorizing.rb
44
+ - app/models/unidom/authorization/concerns/as_authorized.rb
44
45
  - app/models/unidom/authorization/permission.rb
45
46
  - app/views/layouts/unidom/authorization/application.html.erb
46
47
  - config/routes.rb
@@ -70,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
71
  version: '0'
71
72
  requirements: []
72
73
  rubyforge_project:
73
- rubygems_version: 2.4.5.1
74
+ rubygems_version: 2.6.4
74
75
  signing_key:
75
76
  specification_version: 4
76
77
  summary: Unidom Authorization Domain Model Engine 授权领域模型引擎