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 +4 -4
- data/README.md +8 -0
- data/app/assets/javascripts/unidom/authorization/application.js +1 -1
- data/app/assets/stylesheets/unidom/authorization/application.css +0 -1
- data/app/models/unidom/authorization/authorizing.rb +12 -1
- data/app/models/unidom/authorization/concerns/as_authorized.rb +11 -0
- data/app/models/unidom/authorization/permission.rb +2 -2
- data/app/views/layouts/unidom/authorization/application.html.erb +3 -2
- data/lib/unidom/authorization/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 858f8c984eb707ee753575de46356fe27455d1dc
|
4
|
+
data.tar.gz: 1bd878f287b1ad25081637204ef919587de9a8a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
```
|
@@ -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
|
-
|
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
|
@@ -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
|
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>
|
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.
|
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-
|
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.
|
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.
|
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
|
74
|
+
rubygems_version: 2.6.4
|
74
75
|
signing_key:
|
75
76
|
specification_version: 4
|
76
77
|
summary: Unidom Authorization Domain Model Engine 授权领域模型引擎
|