voltex 0.0.1
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +23 -0
- data/app/assets/javascripts/voltex/application.js +13 -0
- data/app/assets/stylesheets/voltex/application.css +15 -0
- data/app/controllers/voltex/application_controller.rb +4 -0
- data/app/controllers/voltex/roles_controller.rb +49 -0
- data/app/helpers/voltex/application_helper.rb +4 -0
- data/app/views/layouts/voltex/application.html.erb +14 -0
- data/app/views/voltex/roles/edit.html.erb +15 -0
- data/config/routes.rb +3 -0
- data/lib/generators/active_record/templates/permission/migration.rb +12 -0
- data/lib/generators/active_record/templates/permission/migration_existing.rb +11 -0
- data/lib/generators/active_record/templates/permissions_role/migration.rb +8 -0
- data/lib/generators/active_record/templates/permissions_role/migration_existing.rb +8 -0
- data/lib/generators/active_record/templates/role/migration.rb +11 -0
- data/lib/generators/active_record/templates/role/migration_existing.rb +10 -0
- data/lib/generators/active_record/templates/user/migration.rb +14 -0
- data/lib/generators/active_record/templates/user/migration_existing.rb +13 -0
- data/lib/generators/active_record/voltex_generator.rb +59 -0
- data/lib/generators/active_record/voltex_permission_generator.rb +23 -0
- data/lib/generators/active_record/voltex_permissions_role_generator.rb +29 -0
- data/lib/generators/active_record/voltex_role_generator.rb +28 -0
- data/lib/generators/active_record/voltex_user_generator.rb +28 -0
- data/lib/generators/voltex/install_generator.rb +12 -0
- data/lib/generators/voltex/resources_generator.rb +20 -0
- data/lib/generators/voltex/templates/voltex.rb +16 -0
- data/lib/generators/voltex/views_generator.rb +12 -0
- data/lib/tasks/voltex_tasks.rake +21 -0
- data/lib/voltex.rb +7 -0
- data/lib/voltex/cancan/ability.rb +17 -0
- data/lib/voltex/engine.rb +5 -0
- data/lib/voltex/pundit.rb +16 -0
- data/lib/voltex/setup.rb +30 -0
- data/lib/voltex/version.rb +3 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b2662de53c4bdb68b6551de510cbe7aabd7b2b31
|
4
|
+
data.tar.gz: 394b5c36b582d0c2ca17d25ecd4d4ac1eb0297f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8d4085d5e02ec158ae6606067461c1ec35c98f8fd9dad4fd93f52537d69a19246e76e70f0e6ad3b739b556d926605521e60d6c68455164687d8f50f1dfd89c24
|
7
|
+
data.tar.gz: 2c8a32ddd6155ec95b0ff99cb5ecaf4e244a32c8a307e88be13ad5c3495ba7b880394adf837f3fc7872c119dfaed221a7c38bebea0658adb5e1c9337f5cb03f6
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Voltex'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
load 'rails/tasks/statistics.rake'
|
18
|
+
Bundler::GemHelper.install_tasks
|
19
|
+
|
20
|
+
require 'cucumber/rake/task'
|
21
|
+
Cucumber::Rake::Task.new(:cucumber)
|
22
|
+
|
23
|
+
task default: :cucumber
|
@@ -0,0 +1,13 @@
|
|
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 .
|
@@ -0,0 +1,15 @@
|
|
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
|
+
*/
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_dependency 'voltex/application_controller'
|
2
|
+
|
3
|
+
module Voltex
|
4
|
+
class RolesController < ApplicationController
|
5
|
+
before_action :set_resource
|
6
|
+
helper_method :resource_name, :permission_resource_name
|
7
|
+
|
8
|
+
# GET /voltex/roles/1/edit
|
9
|
+
def edit
|
10
|
+
end
|
11
|
+
|
12
|
+
# PUT /voltex/roles/1
|
13
|
+
def update
|
14
|
+
if @resource.update(resource_params)
|
15
|
+
redirect_to @resource, notice: t('.notice', default: update_message)
|
16
|
+
else
|
17
|
+
render :edit
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
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
|
+
private
|
32
|
+
|
33
|
+
def set_resource
|
34
|
+
@resource = Voltex.role_class.constantize.find(params[:id])
|
35
|
+
end
|
36
|
+
|
37
|
+
def resource_params
|
38
|
+
params.require(resource_name.to_sym).permit(*permitted_attributes)
|
39
|
+
end
|
40
|
+
|
41
|
+
def permitted_attributes
|
42
|
+
[{:"#{permission_resource_name}_ids" => []}]
|
43
|
+
end
|
44
|
+
|
45
|
+
def update_message
|
46
|
+
'Permissions were updated successfully.'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,14 @@
|
|
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>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<h2>Defining Role Permissions</h2>
|
2
|
+
|
3
|
+
<%= form_for @resource, as: resource_name, url: role_path(@resource) do |f| %>
|
4
|
+
<% Voltex.permission_class.constantize.select(:resource).group(:resource).each do |permission| %>
|
5
|
+
<h5><%= permission.resource.pluralize %></h5>
|
6
|
+
<%= f.collection_check_boxes(
|
7
|
+
"#{permission_resource_name}_ids",
|
8
|
+
Voltex.permission_class.constantize.where(resource: permission.resource),
|
9
|
+
:id, :action) %>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<div class='actions'>
|
13
|
+
<%= f.submit %>
|
14
|
+
</div>
|
15
|
+
<% end %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
class VoltexCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table(:<%= table_name %>) do |t|
|
4
|
+
t.string :resource
|
5
|
+
t.string :action
|
6
|
+
<% attributes.each do |attribute| -%>
|
7
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
8
|
+
<% end -%>
|
9
|
+
t.timestamps null: false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class AddVoltexTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
change_table(:<%= table_name %>) do |t|
|
4
|
+
t.string :resource
|
5
|
+
t.string :action
|
6
|
+
<% attributes.each do |attribute| -%>
|
7
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
8
|
+
<% end -%>
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class VoltexCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table(:<%= table_name %>) do |t|
|
4
|
+
t.string :name
|
5
|
+
<% attributes.each do |attribute| -%>
|
6
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
7
|
+
<% end -%>
|
8
|
+
t.timestamps null: false
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class VoltexCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table(:<%= table_name %>) do |t|
|
4
|
+
t.string :name
|
5
|
+
t.integer :<%= role %>_id
|
6
|
+
<% attributes.each do |attribute| -%>
|
7
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
8
|
+
<% end -%>
|
9
|
+
t.timestamps null: false
|
10
|
+
end
|
11
|
+
|
12
|
+
add_index :<%= table_name %>, :<%= role %>_id
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class AddVoltexTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
change_table(:<%= table_name %>) do |t|
|
4
|
+
t.string :name
|
5
|
+
t.integer :<%= role %>_id
|
6
|
+
<% attributes.each do |attribute| -%>
|
7
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
8
|
+
<% end -%>
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index :<%= table_name %>, :<%= role %>_id
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Generators
|
3
|
+
module VoltexGenerator
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
argument :attributes, type: :array, default: []
|
8
|
+
|
9
|
+
def copy_migration
|
10
|
+
table_exists? ? existing_migration : new_migration
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate_model
|
14
|
+
unless model_exists?
|
15
|
+
invoke 'active_record:model', [name], migration: false, skip_namespace: true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_model_content
|
20
|
+
inject_into_class(model_path, name, sanitized_content) if model_exists?
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def new_migration
|
26
|
+
migration_template 'migration.rb', "db/migrate/voltex_create_#{table_name}.rb"
|
27
|
+
end
|
28
|
+
|
29
|
+
def existing_migration
|
30
|
+
migration_template 'migration_existing.rb', "db/migrate/add_voltex_to_#{table_name}.rb"
|
31
|
+
end
|
32
|
+
|
33
|
+
def model_exists?
|
34
|
+
File.exists?(File.join(destination_root, model_path))
|
35
|
+
end
|
36
|
+
|
37
|
+
def model_path
|
38
|
+
File.join('app', 'models', "#{full_file_path}.rb")
|
39
|
+
end
|
40
|
+
|
41
|
+
def sanitized_content
|
42
|
+
model_content.split("\n").map { |line| ' ' + line.strip }.join("\n") << "\n"
|
43
|
+
end
|
44
|
+
|
45
|
+
def namespaced?
|
46
|
+
false
|
47
|
+
end
|
48
|
+
|
49
|
+
def table_exists?
|
50
|
+
ActiveRecord::Base.connection.table_exists? table_name
|
51
|
+
end
|
52
|
+
|
53
|
+
def full_file_path
|
54
|
+
class_name.split('::').join('/').underscore.downcase
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
require 'generators/active_record/voltex_generator'
|
3
|
+
|
4
|
+
module ActiveRecord
|
5
|
+
module Generators
|
6
|
+
class VoltexPermissionGenerator < ActiveRecord::Generators::Base
|
7
|
+
include VoltexGenerator
|
8
|
+
source_root File.expand_path('../templates/permission', __FILE__)
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def model_content
|
13
|
+
"# Voltex.
|
14
|
+
# Please review the following content.
|
15
|
+
has_and_belongs_to_many :#{roles}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def roles
|
19
|
+
Voltex.role_class.underscore.parameterize('_').pluralize
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
require 'generators/active_record/voltex_generator'
|
3
|
+
|
4
|
+
module ActiveRecord
|
5
|
+
module Generators
|
6
|
+
class VoltexPermissionsRoleGenerator < ActiveRecord::Generators::Base
|
7
|
+
include VoltexGenerator
|
8
|
+
source_root File.expand_path('../templates/permissions_role', __FILE__)
|
9
|
+
|
10
|
+
def generate_model
|
11
|
+
# There wont be a model.
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_model_content
|
15
|
+
# There wont be a model.
|
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
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
require 'generators/active_record/voltex_generator'
|
3
|
+
|
4
|
+
module ActiveRecord
|
5
|
+
module Generators
|
6
|
+
class VoltexRoleGenerator < ActiveRecord::Generators::Base
|
7
|
+
include VoltexGenerator
|
8
|
+
source_root File.expand_path('../templates/role', __FILE__)
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def model_content
|
13
|
+
"# Voltex.
|
14
|
+
# Please review the following content.
|
15
|
+
has_many :#{users}
|
16
|
+
has_and_belongs_to_many :#{permissions}"
|
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
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
require 'generators/active_record/voltex_generator'
|
3
|
+
|
4
|
+
module ActiveRecord
|
5
|
+
module Generators
|
6
|
+
class VoltexUserGenerator < ActiveRecord::Generators::Base
|
7
|
+
include VoltexGenerator
|
8
|
+
source_root File.expand_path('../templates/user', __FILE__)
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def model_content
|
13
|
+
"# Voltex.
|
14
|
+
# Please review the following content.
|
15
|
+
belongs_to :#{role}
|
16
|
+
has_many :#{permissions}, through: :#{role}"
|
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
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Voltex
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
desc 'Creates a voltex initializer.'
|
6
|
+
|
7
|
+
def create_initializer
|
8
|
+
template 'voltex.rb', 'config/initializers/voltex.rb'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Voltex
|
2
|
+
module Generators
|
3
|
+
class ResourcesGenerator < Rails::Generators::Base
|
4
|
+
desc 'Creates voltex resources.'
|
5
|
+
|
6
|
+
def create_resources
|
7
|
+
Rails::Generators.invoke "#{orm}:voltex_user", [Voltex.user_class]
|
8
|
+
Rails::Generators.invoke "#{orm}:voltex_role", [Voltex.role_class]
|
9
|
+
Rails::Generators.invoke "#{orm}:voltex_permission", [Voltex.permission_class]
|
10
|
+
Rails::Generators.invoke "#{orm}:voltex_permissions_role", [Voltex.permissions_role_class]
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def orm
|
16
|
+
Rails.configuration.generators.options[:rails][:orm]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Voltex.setup do |config|
|
2
|
+
# Voltex classes configuration.
|
3
|
+
# config.user_class = 'User'
|
4
|
+
# config.role_class = 'Role'
|
5
|
+
# config.permission_class = 'Permission'
|
6
|
+
#
|
7
|
+
# Excluding default permissions.
|
8
|
+
# config.exclude = [
|
9
|
+
# { resource: 'User', action: 'destroy' },
|
10
|
+
# ]
|
11
|
+
#
|
12
|
+
# Including other permissions.
|
13
|
+
# config.include = [
|
14
|
+
# { resource: 'User', action: 'report' },
|
15
|
+
# ]
|
16
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Voltex
|
2
|
+
module Generators
|
3
|
+
class ViewsGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path('../../../../app/views/voltex', __FILE__)
|
5
|
+
desc 'Creates voltex views.'
|
6
|
+
|
7
|
+
def create_views
|
8
|
+
directory 'roles', 'app/views/voltex/roles'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
desc 'Creates default permissions'
|
2
|
+
task voltex: :environment do
|
3
|
+
Rails.application.eager_load!
|
4
|
+
permission = Voltex.permission_class.constantize
|
5
|
+
|
6
|
+
ActiveRecord::Base.descendants.each do |descendant|
|
7
|
+
Voltex.actions.each do |action|
|
8
|
+
permission.where(
|
9
|
+
resource: descendant.name,
|
10
|
+
action: action).first_or_create
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Voltex.exclude.each do |attrs|
|
15
|
+
permission.where(attrs).delete_all
|
16
|
+
end
|
17
|
+
|
18
|
+
Voltex.include.each do |attrs|
|
19
|
+
permission.where(attrs).first_or_create
|
20
|
+
end
|
21
|
+
end
|
data/lib/voltex.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Voltex
|
2
|
+
module CanCan
|
3
|
+
module Ability
|
4
|
+
def define_voltex_abilities(user)
|
5
|
+
user.send(permissions).each do |permission|
|
6
|
+
can permission.action.to_sym, permission.resource.constantize
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def permissions
|
13
|
+
Voltex.permission_class.underscore.parameterize('_').pluralize
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Voltex
|
2
|
+
module Pundit
|
3
|
+
def permission?(resource, action)
|
4
|
+
user.send(permissions).where(
|
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
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/voltex/setup.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Voltex
|
2
|
+
module Setup
|
3
|
+
mattr_accessor :actions
|
4
|
+
@@actions = %w(index show create update destroy)
|
5
|
+
|
6
|
+
mattr_accessor :user_class
|
7
|
+
@@user_class = 'User'
|
8
|
+
|
9
|
+
mattr_accessor :role_class
|
10
|
+
@@role_class = 'Role'
|
11
|
+
|
12
|
+
mattr_accessor :permission_class
|
13
|
+
@@permission_class = 'Permission'
|
14
|
+
|
15
|
+
def permissions_role_class
|
16
|
+
[permission_class.pluralize,
|
17
|
+
role_class.pluralize].sort.join.singularize
|
18
|
+
end
|
19
|
+
|
20
|
+
mattr_accessor :exclude
|
21
|
+
@@exclude = []
|
22
|
+
|
23
|
+
mattr_accessor :include
|
24
|
+
@@include = []
|
25
|
+
|
26
|
+
def setup
|
27
|
+
yield(self) if block_given?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: voltex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Erick Fabian
|
8
|
+
- Alejandro Gutiérrez
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-06-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 4.2.1
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 4.2.1
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: sqlite3
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec-rails
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.2'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.2'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: cucumber
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.0.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.0.0
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: aruba
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.6.2
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 0.6.2
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: cancan
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.6.10
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 1.6.10
|
98
|
+
description: This engine aims to provide an easy way to work with dynamic permissions.
|
99
|
+
email:
|
100
|
+
- fabianerickalfonso@gmail.com
|
101
|
+
- alejandrodevs@gmail.com
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- MIT-LICENSE
|
107
|
+
- Rakefile
|
108
|
+
- app/assets/javascripts/voltex/application.js
|
109
|
+
- app/assets/stylesheets/voltex/application.css
|
110
|
+
- app/controllers/voltex/application_controller.rb
|
111
|
+
- app/controllers/voltex/roles_controller.rb
|
112
|
+
- app/helpers/voltex/application_helper.rb
|
113
|
+
- app/views/layouts/voltex/application.html.erb
|
114
|
+
- app/views/voltex/roles/edit.html.erb
|
115
|
+
- config/routes.rb
|
116
|
+
- lib/generators/active_record/templates/permission/migration.rb
|
117
|
+
- lib/generators/active_record/templates/permission/migration_existing.rb
|
118
|
+
- lib/generators/active_record/templates/permissions_role/migration.rb
|
119
|
+
- lib/generators/active_record/templates/permissions_role/migration_existing.rb
|
120
|
+
- lib/generators/active_record/templates/role/migration.rb
|
121
|
+
- lib/generators/active_record/templates/role/migration_existing.rb
|
122
|
+
- lib/generators/active_record/templates/user/migration.rb
|
123
|
+
- lib/generators/active_record/templates/user/migration_existing.rb
|
124
|
+
- lib/generators/active_record/voltex_generator.rb
|
125
|
+
- lib/generators/active_record/voltex_permission_generator.rb
|
126
|
+
- lib/generators/active_record/voltex_permissions_role_generator.rb
|
127
|
+
- lib/generators/active_record/voltex_role_generator.rb
|
128
|
+
- lib/generators/active_record/voltex_user_generator.rb
|
129
|
+
- lib/generators/voltex/install_generator.rb
|
130
|
+
- lib/generators/voltex/resources_generator.rb
|
131
|
+
- lib/generators/voltex/templates/voltex.rb
|
132
|
+
- lib/generators/voltex/views_generator.rb
|
133
|
+
- lib/tasks/voltex_tasks.rake
|
134
|
+
- lib/voltex.rb
|
135
|
+
- lib/voltex/cancan/ability.rb
|
136
|
+
- lib/voltex/engine.rb
|
137
|
+
- lib/voltex/pundit.rb
|
138
|
+
- lib/voltex/setup.rb
|
139
|
+
- lib/voltex/version.rb
|
140
|
+
homepage: ''
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.4.5
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: Dynamic permissions authorization.
|
164
|
+
test_files: []
|