voltex 0.0.7 → 0.0.8
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 +4 -4
- data/README.md +46 -40
- data/lib/generators/active_record/templates/permission/migration.rb +1 -1
- data/lib/generators/active_record/templates/permission/migration_existing.rb +1 -1
- data/lib/generators/active_record/templates/permissions_role/migration.rb +1 -1
- data/lib/generators/active_record/templates/permissions_role/migration_existing.rb +1 -1
- data/lib/generators/active_record/templates/role/migration.rb +1 -1
- data/lib/generators/active_record/templates/user/migration.rb +1 -1
- data/lib/generators/active_record/templates/user/migration_existing.rb +1 -1
- data/lib/generators/active_record/voltex_generator.rb +6 -0
- data/lib/generators/active_record/voltex_permission_generator.rb +1 -0
- data/lib/generators/active_record/voltex_permissions_role_generator.rb +1 -0
- data/lib/generators/active_record/voltex_role_generator.rb +1 -0
- data/lib/generators/active_record/voltex_user_generator.rb +1 -0
- data/lib/voltex/cancan.rb +9 -0
- data/lib/voltex/version.rb +1 -1
- metadata +8 -8
- data/lib/voltex/cancan/ability.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b282a966aaaf962ee73b61a7058797997d190260
|
4
|
+
data.tar.gz: 3512c2339b07c25d1327fb9c98222f5a363401b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6f0ce0d777f8e1fe2e16a76c7adb43befaa0d37ad32185f8cf0d35cab8a6e6683ef7cc3fd9a8f270a268915f4bdc1fff63904d5fbc37b94c14b39b7e34ada88
|
7
|
+
data.tar.gz: 0d6ba883b3fa46241662b83169b4b4da6fe3fc20fad48362cbeee4465457b808deb9ccefe9a067b4f30c18a19432ac5604332efb498c466f6c071c69595275c1
|
data/README.md
CHANGED
@@ -2,69 +2,64 @@
|
|
2
2
|
This engine aims to provide an easy way to work with dynamic permissions.
|
3
3
|
|
4
4
|
|
5
|
-
## Compatibility
|
6
|
-
* Rails 4+
|
7
|
-
* ActiveRecord 4+
|
8
|
-
* Ruby 2+
|
9
|
-
|
10
|
-
|
11
5
|
## Installation
|
12
6
|
1. Add Voltex to your Gemfile.
|
13
7
|
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
```ruby
|
9
|
+
gem 'voltex'
|
10
|
+
```
|
17
11
|
|
18
12
|
2. Generate voltex initializer.
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
```
|
15
|
+
rails g voltex:install
|
16
|
+
```
|
23
17
|
|
24
18
|
3. Update initializer according your needs.
|
25
19
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
20
|
+
```ruby
|
21
|
+
Voltex.setup do |config|
|
22
|
+
# Voltex classes configuration.
|
23
|
+
# config.user_class = 'User'
|
24
|
+
# config.role_class = 'Role'
|
25
|
+
# config.permission_class = 'Permission'
|
26
|
+
...
|
27
|
+
end
|
28
|
+
```
|
35
29
|
|
36
30
|
4. Generate voltex resources.
|
37
31
|
|
38
|
-
|
39
|
-
|
40
|
-
|
32
|
+
```
|
33
|
+
rails g voltex:resources
|
34
|
+
```
|
41
35
|
|
42
36
|
5. Migrate your database.
|
43
37
|
|
44
|
-
|
45
|
-
|
46
|
-
|
38
|
+
```
|
39
|
+
rails db:migrate
|
40
|
+
```
|
47
41
|
|
48
42
|
6. Create default permissions.
|
49
43
|
|
50
|
-
|
51
|
-
|
52
|
-
|
44
|
+
```
|
45
|
+
rake voltex
|
46
|
+
```
|
53
47
|
|
54
48
|
7. Load current user permissions in your application controller.
|
55
49
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
50
|
+
```ruby
|
51
|
+
class ApplicationController < ActionController::Base
|
52
|
+
...
|
53
|
+
before_action :set_current_permissions
|
54
|
+
end
|
55
|
+
```
|
62
56
|
|
63
57
|
By default this callback preloads permissions for `current_user` if this
|
64
58
|
is defined. If you need that this callback preloads permission for
|
65
59
|
another user just overwrite `voltex_user` method.
|
66
60
|
|
67
61
|
Example:
|
62
|
+
|
68
63
|
```ruby
|
69
64
|
class ApplicationController < ActionController::Base
|
70
65
|
...
|
@@ -78,6 +73,7 @@ end
|
|
78
73
|
|
79
74
|
## Using Voltex with Pundit
|
80
75
|
Include voltex in your application policy.
|
76
|
+
|
81
77
|
```ruby
|
82
78
|
require 'voltex/pundit'
|
83
79
|
|
@@ -85,7 +81,9 @@ class ApplicationPolicy
|
|
85
81
|
include Voltex::Pundit
|
86
82
|
end
|
87
83
|
```
|
84
|
+
|
88
85
|
Now a new helper is available in your policies.
|
86
|
+
|
89
87
|
```ruby
|
90
88
|
class PostPolicy
|
91
89
|
def index?
|
@@ -97,12 +95,13 @@ end
|
|
97
95
|
|
98
96
|
## Using Voltex with CanCan
|
99
97
|
Include voltex in your ability class.
|
98
|
+
|
100
99
|
```ruby
|
101
|
-
require 'voltex/cancan
|
100
|
+
require 'voltex/cancan'
|
102
101
|
|
103
102
|
class Ability
|
104
103
|
include CanCan::Ability
|
105
|
-
include Voltex::CanCan
|
104
|
+
include Voltex::CanCan
|
106
105
|
|
107
106
|
def initialize(user)
|
108
107
|
define_voltex_abilities(user)
|
@@ -113,6 +112,7 @@ end
|
|
113
112
|
|
114
113
|
## Including and Excluding permissions
|
115
114
|
Update your voltex initializer:
|
115
|
+
|
116
116
|
```ruby
|
117
117
|
Voltex.setup do |config|
|
118
118
|
# Voltex classes configuration.
|
@@ -133,22 +133,28 @@ Voltex.setup do |config|
|
|
133
133
|
]
|
134
134
|
end
|
135
135
|
```
|
136
|
+
|
136
137
|
And run voltex rake task again:
|
138
|
+
|
137
139
|
```
|
138
|
-
|
140
|
+
rake voltex
|
139
141
|
```
|
140
142
|
|
141
143
|
|
142
144
|
## Defining role permissions
|
143
145
|
Mount voltex engine in your application:
|
146
|
+
|
144
147
|
```ruby
|
145
148
|
Rails.application.routes.draw do
|
146
149
|
mount Voltex::Engine => '/voltex'
|
147
150
|
end
|
148
151
|
```
|
152
|
+
|
149
153
|
Run voltex views generator:
|
154
|
+
|
150
155
|
```
|
151
|
-
|
156
|
+
rails g voltex:views
|
152
157
|
```
|
158
|
+
|
153
159
|
This will define a route `/voltex/roles/:id/edit` where
|
154
160
|
permissions can be defined for each role.
|
@@ -49,6 +49,12 @@ module ActiveRecord
|
|
49
49
|
def table_exists?
|
50
50
|
ActiveRecord::Base.connection.table_exists? table_name
|
51
51
|
end
|
52
|
+
|
53
|
+
def migration_class_name
|
54
|
+
Rails.version.to_i == 5 ?
|
55
|
+
"ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]":
|
56
|
+
'ActiveRecord::Migration'
|
57
|
+
end
|
52
58
|
end
|
53
59
|
end
|
54
60
|
end
|
data/lib/voltex/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: voltex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erick Fabian
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-01-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -59,28 +59,28 @@ dependencies:
|
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '3.
|
62
|
+
version: '3.7'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '3.
|
69
|
+
version: '3.7'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: cucumber
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: '
|
76
|
+
version: '3.1'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version: '
|
83
|
+
version: '3.1'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: aruba
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,7 +143,7 @@ files:
|
|
143
143
|
- lib/generators/voltex/views_generator.rb
|
144
144
|
- lib/tasks/voltex_tasks.rake
|
145
145
|
- lib/voltex.rb
|
146
|
-
- lib/voltex/cancan
|
146
|
+
- lib/voltex/cancan.rb
|
147
147
|
- lib/voltex/engine.rb
|
148
148
|
- lib/voltex/pundit.rb
|
149
149
|
- lib/voltex/scope.rb
|
@@ -169,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
169
|
version: '0'
|
170
170
|
requirements: []
|
171
171
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.6.
|
172
|
+
rubygems_version: 2.6.14
|
173
173
|
signing_key:
|
174
174
|
specification_version: 4
|
175
175
|
summary: Dynamic permissions authorization.
|