voltex 0.0.1 → 0.0.2
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/app/controllers/voltex/roles_controller.rb +3 -14
- data/app/views/voltex/roles/edit.html.erb +4 -6
- data/lib/generators/active_record/templates/permission/migration.rb +0 -3
- data/lib/generators/active_record/templates/permission/migration_existing.rb +0 -3
- data/lib/generators/active_record/templates/permissions_role/migration.rb +2 -2
- data/lib/generators/active_record/templates/permissions_role/migration_existing.rb +2 -2
- data/lib/generators/active_record/templates/role/migration.rb +0 -3
- data/lib/generators/active_record/templates/user/migration.rb +1 -6
- data/lib/generators/active_record/templates/user/migration_existing.rb +1 -7
- data/lib/generators/active_record/voltex_generator.rb +1 -5
- data/lib/generators/active_record/voltex_permission_generator.rb +1 -5
- data/lib/generators/active_record/voltex_permissions_role_generator.rb +0 -10
- data/lib/generators/active_record/voltex_role_generator.rb +6 -10
- data/lib/generators/active_record/voltex_user_generator.rb +2 -10
- data/lib/generators/voltex/templates/voltex.rb +3 -0
- data/lib/tasks/voltex_tasks.rake +4 -5
- data/lib/voltex/cancan/ability.rb +1 -7
- data/lib/voltex/pundit.rb +2 -9
- data/lib/voltex/setup.rb +20 -7
- data/lib/voltex/version.rb +1 -1
- metadata +2 -6
- data/app/assets/javascripts/voltex/application.js +0 -13
- data/app/assets/stylesheets/voltex/application.css +0 -15
- data/app/views/layouts/voltex/application.html.erb +0 -14
- data/lib/generators/active_record/templates/role/migration_existing.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b667e3175a6e0df18ab07406fdade6626a077664
|
4
|
+
data.tar.gz: 42c84a396d9a1cbe91e8603ced0f67257ef86aa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6512979371b63cc2a6976fcbc0071f76e7e7943cf288975476cbbdf0d5db9e63991237c945a2efd046a0939f609286c473e2d51c95019d9252c341be15096d0
|
7
|
+
data.tar.gz: 801504b7221ca12d4c319255325840aaa57ded5759fa70927c5e7c7e2f111595ab9c0ed943237a0d0e12b6d280d2a5375a76056502ee3f53345fe28bf20fa4b0
|
@@ -3,7 +3,6 @@ require_dependency 'voltex/application_controller'
|
|
3
3
|
module Voltex
|
4
4
|
class RolesController < ApplicationController
|
5
5
|
before_action :set_resource
|
6
|
-
helper_method :resource_name, :permission_resource_name
|
7
6
|
|
8
7
|
# GET /voltex/roles/1/edit
|
9
8
|
def edit
|
@@ -18,28 +17,18 @@ module Voltex
|
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
|
-
protected
|
22
|
-
|
23
|
-
def resource_name
|
24
|
-
Voltex.role_class.underscore.parameterize('_')
|
25
|
-
end
|
26
|
-
|
27
|
-
def permission_resource_name
|
28
|
-
Voltex.permission_class.underscore.parameterize('_')
|
29
|
-
end
|
30
|
-
|
31
20
|
private
|
32
21
|
|
33
22
|
def set_resource
|
34
|
-
@resource = Voltex.
|
23
|
+
@resource = Voltex.role_model.find(params[:id])
|
35
24
|
end
|
36
25
|
|
37
26
|
def resource_params
|
38
|
-
params.require(
|
27
|
+
params.require(Voltex.role_name).permit(*permitted_attributes)
|
39
28
|
end
|
40
29
|
|
41
30
|
def permitted_attributes
|
42
|
-
[{:"#{
|
31
|
+
[{:"#{Voltex.permission_name}_ids" => []}]
|
43
32
|
end
|
44
33
|
|
45
34
|
def update_message
|
@@ -1,12 +1,10 @@
|
|
1
1
|
<h2>Defining Role Permissions</h2>
|
2
2
|
|
3
|
-
<%= form_for @resource, as:
|
4
|
-
<% Voltex.
|
3
|
+
<%= form_for @resource, as: Voltex.role_name, url: role_path(@resource) do |f| %>
|
4
|
+
<% Voltex.permission_model.select(:resource).group(:resource).each do |permission| %>
|
5
5
|
<h5><%= permission.resource.pluralize %></h5>
|
6
|
-
<%= f.collection_check_boxes(
|
7
|
-
|
8
|
-
Voltex.permission_class.constantize.where(resource: permission.resource),
|
9
|
-
:id, :action) %>
|
6
|
+
<%= f.collection_check_boxes("#{Voltex.permission_name}_ids",
|
7
|
+
Voltex.permission_model.where(resource: permission.resource), :id, :action) %>
|
10
8
|
<% end %>
|
11
9
|
|
12
10
|
<div class='actions'>
|
@@ -3,9 +3,6 @@ class VoltexCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
|
3
3
|
create_table(:<%= table_name %>) do |t|
|
4
4
|
t.string :resource
|
5
5
|
t.string :action
|
6
|
-
<% attributes.each do |attribute| -%>
|
7
|
-
t.<%= attribute.type %> :<%= attribute.name %>
|
8
|
-
<% end -%>
|
9
6
|
t.timestamps null: false
|
10
7
|
end
|
11
8
|
end
|
@@ -3,9 +3,6 @@ class AddVoltexTo<%= table_name.camelize %> < ActiveRecord::Migration
|
|
3
3
|
change_table(:<%= table_name %>) do |t|
|
4
4
|
t.string :resource
|
5
5
|
t.string :action
|
6
|
-
<% attributes.each do |attribute| -%>
|
7
|
-
t.<%= attribute.type %> :<%= attribute.name %>
|
8
|
-
<% end -%>
|
9
6
|
end
|
10
7
|
end
|
11
8
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class VoltexCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
create_table(:<%= table_name %>) do |t|
|
4
|
-
t.references :<%=
|
5
|
-
t.references :<%=
|
4
|
+
t.references :<%= Voltex.permission_name %>
|
5
|
+
t.references :<%= Voltex.role_name %>
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class AddVoltexTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
change_table(:<%= table_name %>) do |t|
|
4
|
-
t.references :<%=
|
5
|
-
t.references :<%=
|
4
|
+
t.references :<%= Voltex.permission_name %>
|
5
|
+
t.references :<%= Voltex.role_name %>
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -2,9 +2,6 @@ class VoltexCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
|
2
2
|
def change
|
3
3
|
create_table(:<%= table_name %>) do |t|
|
4
4
|
t.string :name
|
5
|
-
<% attributes.each do |attribute| -%>
|
6
|
-
t.<%= attribute.type %> :<%= attribute.name %>
|
7
|
-
<% end -%>
|
8
5
|
t.timestamps null: false
|
9
6
|
end
|
10
7
|
end
|
@@ -2,13 +2,8 @@ class VoltexCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
|
2
2
|
def change
|
3
3
|
create_table(:<%= table_name %>) do |t|
|
4
4
|
t.string :name
|
5
|
-
t.
|
6
|
-
<% attributes.each do |attribute| -%>
|
7
|
-
t.<%= attribute.type %> :<%= attribute.name %>
|
8
|
-
<% end -%>
|
5
|
+
t.references :<%= Voltex.role_name %>
|
9
6
|
t.timestamps null: false
|
10
7
|
end
|
11
|
-
|
12
|
-
add_index :<%= table_name %>, :<%= role %>_id
|
13
8
|
end
|
14
9
|
end
|
@@ -1,13 +1,7 @@
|
|
1
1
|
class AddVoltexTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
change_table(:<%= table_name %>) do |t|
|
4
|
-
t.
|
5
|
-
t.integer :<%= role %>_id
|
6
|
-
<% attributes.each do |attribute| -%>
|
7
|
-
t.<%= attribute.type %> :<%= attribute.name %>
|
8
|
-
<% end -%>
|
4
|
+
t.references :<%= Voltex.role_name %>
|
9
5
|
end
|
10
|
-
|
11
|
-
add_index :<%= table_name %>, :<%= role %>_id
|
12
6
|
end
|
13
7
|
end
|
@@ -35,7 +35,7 @@ module ActiveRecord
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def model_path
|
38
|
-
File.join('app', 'models', "#{
|
38
|
+
File.join('app', 'models', "#{class_name.underscore}.rb")
|
39
39
|
end
|
40
40
|
|
41
41
|
def sanitized_content
|
@@ -49,10 +49,6 @@ module ActiveRecord
|
|
49
49
|
def table_exists?
|
50
50
|
ActiveRecord::Base.connection.table_exists? table_name
|
51
51
|
end
|
52
|
-
|
53
|
-
def full_file_path
|
54
|
-
class_name.split('::').join('/').underscore.downcase
|
55
|
-
end
|
56
52
|
end
|
57
53
|
end
|
58
54
|
end
|
@@ -12,11 +12,7 @@ module ActiveRecord
|
|
12
12
|
def model_content
|
13
13
|
"# Voltex.
|
14
14
|
# Please review the following content.
|
15
|
-
has_and_belongs_to_many :#{
|
16
|
-
end
|
17
|
-
|
18
|
-
def roles
|
19
|
-
Voltex.role_class.underscore.parameterize('_').pluralize
|
15
|
+
has_and_belongs_to_many :#{Voltex.roles_name}"
|
20
16
|
end
|
21
17
|
end
|
22
18
|
end
|
@@ -14,16 +14,6 @@ module ActiveRecord
|
|
14
14
|
def add_model_content
|
15
15
|
# There wont be a model.
|
16
16
|
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def permission
|
21
|
-
Voltex.permission_class.underscore.parameterize('_')
|
22
|
-
end
|
23
|
-
|
24
|
-
def role
|
25
|
-
Voltex.role_class.underscore.parameterize('_')
|
26
|
-
end
|
27
17
|
end
|
28
18
|
end
|
29
19
|
end
|
@@ -9,19 +9,15 @@ module ActiveRecord
|
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
|
+
def existing_migration
|
13
|
+
# There won't be a existing migration.
|
14
|
+
end
|
15
|
+
|
12
16
|
def model_content
|
13
17
|
"# Voltex.
|
14
18
|
# Please review the following content.
|
15
|
-
has_many :#{
|
16
|
-
has_and_belongs_to_many :#{
|
17
|
-
end
|
18
|
-
|
19
|
-
def users
|
20
|
-
Voltex.user_class.underscore.parameterize('_').pluralize
|
21
|
-
end
|
22
|
-
|
23
|
-
def permissions
|
24
|
-
Voltex.permission_class.underscore.parameterize('_').pluralize
|
19
|
+
has_many :#{Voltex.users_name}
|
20
|
+
has_and_belongs_to_many :#{Voltex.permissions_name}"
|
25
21
|
end
|
26
22
|
end
|
27
23
|
end
|
@@ -12,16 +12,8 @@ module ActiveRecord
|
|
12
12
|
def model_content
|
13
13
|
"# Voltex.
|
14
14
|
# Please review the following content.
|
15
|
-
belongs_to :#{
|
16
|
-
has_many :#{
|
17
|
-
end
|
18
|
-
|
19
|
-
def role
|
20
|
-
Voltex.role_class.underscore.parameterize('_')
|
21
|
-
end
|
22
|
-
|
23
|
-
def permissions
|
24
|
-
Voltex.permission_class.underscore.parameterize('_').pluralize
|
15
|
+
belongs_to :#{Voltex.role_name}
|
16
|
+
has_many :#{Voltex.permissions_name}, through: :#{Voltex.role_name}"
|
25
17
|
end
|
26
18
|
end
|
27
19
|
end
|
@@ -4,6 +4,9 @@ Voltex.setup do |config|
|
|
4
4
|
# config.role_class = 'Role'
|
5
5
|
# config.permission_class = 'Permission'
|
6
6
|
#
|
7
|
+
# Default actions.
|
8
|
+
# config.default_actions = %w(index show create update destroy)
|
9
|
+
#
|
7
10
|
# Excluding default permissions.
|
8
11
|
# config.exclude = [
|
9
12
|
# { resource: 'User', action: 'destroy' },
|
data/lib/tasks/voltex_tasks.rake
CHANGED
@@ -1,21 +1,20 @@
|
|
1
1
|
desc 'Creates default permissions'
|
2
2
|
task voltex: :environment do
|
3
3
|
Rails.application.eager_load!
|
4
|
-
permission = Voltex.permission_class.constantize
|
5
4
|
|
6
5
|
ActiveRecord::Base.descendants.each do |descendant|
|
7
|
-
Voltex.
|
8
|
-
|
6
|
+
Voltex.default_actions.each do |action|
|
7
|
+
Voltex.permission_model.where(
|
9
8
|
resource: descendant.name,
|
10
9
|
action: action).first_or_create
|
11
10
|
end
|
12
11
|
end
|
13
12
|
|
14
13
|
Voltex.exclude.each do |attrs|
|
15
|
-
|
14
|
+
Voltex.permission_model.where(attrs).delete_all
|
16
15
|
end
|
17
16
|
|
18
17
|
Voltex.include.each do |attrs|
|
19
|
-
|
18
|
+
Voltex.permission_model.where(attrs).first_or_create
|
20
19
|
end
|
21
20
|
end
|
@@ -2,16 +2,10 @@ module Voltex
|
|
2
2
|
module CanCan
|
3
3
|
module Ability
|
4
4
|
def define_voltex_abilities(user)
|
5
|
-
user.send(
|
5
|
+
user.send(Voltex.permissions_name).each do |permission|
|
6
6
|
can permission.action.to_sym, permission.resource.constantize
|
7
7
|
end
|
8
8
|
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def permissions
|
13
|
-
Voltex.permission_class.underscore.parameterize('_').pluralize
|
14
|
-
end
|
15
9
|
end
|
16
10
|
end
|
17
11
|
end
|
data/lib/voltex/pundit.rb
CHANGED
@@ -1,16 +1,9 @@
|
|
1
1
|
module Voltex
|
2
2
|
module Pundit
|
3
3
|
def permission?(resource, action)
|
4
|
-
user.send(
|
4
|
+
user.send(Voltex.permissions_name).where(
|
5
5
|
resource: resource.to_s,
|
6
|
-
action: action
|
7
|
-
).exists?
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def permissions
|
13
|
-
Voltex.permission_class.underscore.parameterize('_').pluralize
|
6
|
+
action: action).exists?
|
14
7
|
end
|
15
8
|
end
|
16
9
|
end
|
data/lib/voltex/setup.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Voltex
|
2
2
|
module Setup
|
3
|
-
mattr_accessor :
|
4
|
-
@@
|
3
|
+
mattr_accessor :default_actions
|
4
|
+
@@default_actions = %w(index show create update destroy)
|
5
5
|
|
6
6
|
mattr_accessor :user_class
|
7
7
|
@@user_class = 'User'
|
@@ -12,17 +12,30 @@ module Voltex
|
|
12
12
|
mattr_accessor :permission_class
|
13
13
|
@@permission_class = 'Permission'
|
14
14
|
|
15
|
-
def permissions_role_class
|
16
|
-
[permission_class.pluralize,
|
17
|
-
role_class.pluralize].sort.join.singularize
|
18
|
-
end
|
19
|
-
|
20
15
|
mattr_accessor :exclude
|
21
16
|
@@exclude = []
|
22
17
|
|
23
18
|
mattr_accessor :include
|
24
19
|
@@include = []
|
25
20
|
|
21
|
+
def permissions_role_class
|
22
|
+
[permission_class, role_class].map(&:pluralize).sort.join.singularize
|
23
|
+
end
|
24
|
+
|
25
|
+
%w(user role permission).each do |resource|
|
26
|
+
define_method "#{resource}_model" do
|
27
|
+
send("#{resource}_class").constantize
|
28
|
+
end
|
29
|
+
|
30
|
+
define_method "#{resource}_name" do
|
31
|
+
send("#{resource}_class").underscore.parameterize('_')
|
32
|
+
end
|
33
|
+
|
34
|
+
define_method "#{resource.pluralize}_name" do
|
35
|
+
send("#{resource}_name").pluralize
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
26
39
|
def setup
|
27
40
|
yield(self) if block_given?
|
28
41
|
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.2
|
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: 2015-06-
|
12
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -105,12 +105,9 @@ extra_rdoc_files: []
|
|
105
105
|
files:
|
106
106
|
- MIT-LICENSE
|
107
107
|
- Rakefile
|
108
|
-
- app/assets/javascripts/voltex/application.js
|
109
|
-
- app/assets/stylesheets/voltex/application.css
|
110
108
|
- app/controllers/voltex/application_controller.rb
|
111
109
|
- app/controllers/voltex/roles_controller.rb
|
112
110
|
- app/helpers/voltex/application_helper.rb
|
113
|
-
- app/views/layouts/voltex/application.html.erb
|
114
111
|
- app/views/voltex/roles/edit.html.erb
|
115
112
|
- config/routes.rb
|
116
113
|
- lib/generators/active_record/templates/permission/migration.rb
|
@@ -118,7 +115,6 @@ files:
|
|
118
115
|
- lib/generators/active_record/templates/permissions_role/migration.rb
|
119
116
|
- lib/generators/active_record/templates/permissions_role/migration_existing.rb
|
120
117
|
- lib/generators/active_record/templates/role/migration.rb
|
121
|
-
- lib/generators/active_record/templates/role/migration_existing.rb
|
122
118
|
- lib/generators/active_record/templates/user/migration.rb
|
123
119
|
- lib/generators/active_record/templates/user/migration_existing.rb
|
124
120
|
- lib/generators/active_record/voltex_generator.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
-
// listed below.
|
3
|
-
//
|
4
|
-
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
-
//
|
7
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file.
|
9
|
-
//
|
10
|
-
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
-
// about supported directives.
|
12
|
-
//
|
13
|
-
//= require_tree .
|
@@ -1,15 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
-
* listed below.
|
4
|
-
*
|
5
|
-
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
-
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
-
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
-
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
-
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
-
* file per style scope.
|
12
|
-
*
|
13
|
-
*= require_tree .
|
14
|
-
*= require_self
|
15
|
-
*/
|
@@ -1,14 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>Voltex</title>
|
5
|
-
<%= stylesheet_link_tag "voltex/application", media: "all" %>
|
6
|
-
<%= javascript_include_tag "voltex/application" %>
|
7
|
-
<%= csrf_meta_tags %>
|
8
|
-
</head>
|
9
|
-
<body>
|
10
|
-
|
11
|
-
<%= yield %>
|
12
|
-
|
13
|
-
</body>
|
14
|
-
</html>
|
@@ -1,10 +0,0 @@
|
|
1
|
-
class AddVoltexTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
change_table(:<%= table_name %>) do |t|
|
4
|
-
t.string :name
|
5
|
-
<% attributes.each do |attribute| -%>
|
6
|
-
t.<%= attribute.type %> :<%= attribute.name %>
|
7
|
-
<% end -%>
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|