burlesque 1.0.0 → 2.0.0
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.
- data/MIT-LICENSE +20 -0
- data/README.md +22 -3
- data/Rakefile +40 -1
- data/app/assets/javascripts/burlesque/application.js +15 -0
- data/app/assets/stylesheets/burlesque/application.css +13 -0
- data/app/controllers/burlesque/application_controller.rb +4 -0
- data/app/helpers/burlesque/application_helper.rb +4 -0
- data/app/models/burlesque/admin_group.rb +22 -0
- data/app/models/burlesque/admin_role.rb +13 -0
- data/app/models/burlesque/group.rb +87 -0
- data/app/models/burlesque/role.rb +92 -0
- data/app/models/burlesque/role_group.rb +24 -0
- data/app/views/layouts/burlesque/application.html.erb +14 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20130725210208_create_burlesque_groups.rb +9 -0
- data/db/migrate/20130725210428_create_burlesque_roles.rb +9 -0
- data/db/migrate/20130725214806_create_burlesque_admin_groups.rb +15 -0
- data/db/migrate/20130725223204_create_burlesque_role_groups.rb +12 -0
- data/db/migrate/20130725223437_create_burlesque_admin_roles.rb +15 -0
- data/lib/burlesque.rb +5 -6
- data/lib/burlesque/admin.rb +14 -10
- data/lib/burlesque/engine.rb +5 -0
- data/lib/burlesque/version.rb +1 -1
- data/lib/tasks/burlesque_tasks.rake +4 -0
- data/test/burlesque_test.rb +7 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/fixtures/burlesque/admin_groups.yml +9 -0
- data/test/fixtures/burlesque/admin_roles.yml +9 -0
- data/test/fixtures/burlesque/groups.yml +7 -0
- data/test/fixtures/burlesque/role_groups.yml +9 -0
- data/test/fixtures/burlesque/roles.yml +7 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +15 -0
- data/test/unit/burlesque/admin_group_test.rb +9 -0
- data/test/unit/burlesque/admin_role_test.rb +9 -0
- data/test/unit/burlesque/group_test.rb +9 -0
- data/test/unit/burlesque/role_group_test.rb +9 -0
- data/test/unit/burlesque/role_test.rb +9 -0
- metadata +123 -25
- data/.gitignore +0 -7
- data/Gemfile +0 -4
- data/burlesque.gemspec +0 -24
- data/lib/burlesque/admin_group.rb +0 -25
- data/lib/burlesque/authorization.rb +0 -13
- data/lib/burlesque/group.rb +0 -91
- data/lib/burlesque/role.rb +0 -94
- data/lib/burlesque/role_group.rb +0 -30
- data/lib/generators/burlesque/install_generator.rb +0 -85
- data/lib/generators/burlesque/templates/admin_group.rb +0 -3
- data/lib/generators/burlesque/templates/authorization.rb +0 -3
- data/lib/generators/burlesque/templates/create_admin_groups.rb +0 -13
- data/lib/generators/burlesque/templates/create_authorizations.rb +0 -13
- data/lib/generators/burlesque/templates/create_groups.rb +0 -9
- data/lib/generators/burlesque/templates/create_role_groups.rb +0 -12
- data/lib/generators/burlesque/templates/create_roles.rb +0 -9
- data/lib/generators/burlesque/templates/group.rb +0 -3
- data/lib/generators/burlesque/templates/role.rb +0 -3
- data/lib/generators/burlesque/templates/role_group.rb +0 -3
data/lib/burlesque/role.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
|
3
|
-
module Burlesque
|
4
|
-
module Role
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
has_many :role_groups
|
9
|
-
has_many :groups, through: :role_groups, dependent: :destroy
|
10
|
-
|
11
|
-
has_many :authorizations, dependent: :destroy
|
12
|
-
# for has_many :admins relations see admins function
|
13
|
-
|
14
|
-
attr_accessible :name
|
15
|
-
validates :name, presence: true, uniqueness: true
|
16
|
-
|
17
|
-
|
18
|
-
scope :action, lambda { |action| where('name LIKE ?', "%##{action}") }
|
19
|
-
scope :not_action, lambda { |action| where('name NOT LIKE ?', "%##{action}") }
|
20
|
-
scope :resource, lambda { |model| where('name LIKE ?', "#{model.to_s}#%") }
|
21
|
-
scope :not_resource, lambda { |model| where('name NOT LIKE ?', "#{model.to_s}#%") }
|
22
|
-
end
|
23
|
-
|
24
|
-
module InstanceMethods
|
25
|
-
# Public: Relacion a muchos usuarios
|
26
|
-
#
|
27
|
-
# Se usa esta funcion dado que la tabla de administrador es polimorfica.
|
28
|
-
#
|
29
|
-
# Returns los administradores que tienen el rol en cuestion.
|
30
|
-
def admins
|
31
|
-
authorizations.map &:authorizable
|
32
|
-
end
|
33
|
-
|
34
|
-
# Public: Traduce el nombre de un rol.
|
35
|
-
#
|
36
|
-
# Primero revisa si existe una traducción para el rol bajo el scope de autorizaciones,
|
37
|
-
# luego si el no existe una traducción intenta traducir el nombre del rol usando la
|
38
|
-
# traduccion de Burleque, que traduce la acción por defecto e intenta usar las traducciones
|
39
|
-
# definidas para cada modelo
|
40
|
-
#
|
41
|
-
# Returns el nombre del rol ya traducido.
|
42
|
-
def translate_name
|
43
|
-
translate = I18n.t(name.to_sym, scope: :authorizations)
|
44
|
-
return translate unless translate.include?('translation missing:')
|
45
|
-
|
46
|
-
translate = I18n.t(action_sym, scope: :authorizations) + ' ' + resource_class.model_name.human
|
47
|
-
end
|
48
|
-
|
49
|
-
# Public: Entrega el recurso asociado al rol.
|
50
|
-
#
|
51
|
-
# Returns Constant.
|
52
|
-
def resource_class
|
53
|
-
name.split('#', 2).first.pluralize.classify.constantize
|
54
|
-
end
|
55
|
-
|
56
|
-
# Public: Entrega la accion asociada al rol.
|
57
|
-
#
|
58
|
-
# Returns Symbol.
|
59
|
-
def action_sym
|
60
|
-
name.split('#', 2).last.to_sym
|
61
|
-
end
|
62
|
-
|
63
|
-
# Public: Entrega la accion y modelo asociado al rol.
|
64
|
-
#
|
65
|
-
# Returns Symbol.
|
66
|
-
def get_action_and_model
|
67
|
-
[action_sym, resource_class]
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
module ClassMethods
|
72
|
-
# TODO
|
73
|
-
# Mejorar el retorno, para saber que paso, ej: si se agregaron los 5 roles o si ya existen
|
74
|
-
def for model
|
75
|
-
if model.class == String
|
76
|
-
resource = model.classify.constantize.model_name.underscore
|
77
|
-
elsif model.class == Symbol
|
78
|
-
resource = model.to_s.classify.constantize.model_name.underscore
|
79
|
-
elsif model.class == Class
|
80
|
-
resource = model.model_name.underscore
|
81
|
-
end
|
82
|
-
|
83
|
-
if resource
|
84
|
-
self.create(name: "#{resource}#read") unless self.where(name: "#{resource}#read" ).any?
|
85
|
-
self.create(name: "#{resource}#create") unless self.where(name: "#{resource}#create" ).any?
|
86
|
-
self.create(name: "#{resource}#update") unless self.where(name: "#{resource}#update" ).any?
|
87
|
-
self.create(name: "#{resource}#destroy") unless self.where(name: "#{resource}#destroy").any?
|
88
|
-
else
|
89
|
-
raise I18n.t('errors.messages.invalid_param', param: model.class)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
data/lib/burlesque/role_group.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
|
3
|
-
module Burlesque
|
4
|
-
module RoleGroup
|
5
|
-
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
included do
|
8
|
-
belongs_to :role
|
9
|
-
belongs_to :group
|
10
|
-
|
11
|
-
validates_uniqueness_of :role_id, scope: :group_id, message: I18n.t('errors.messages.role_taken')
|
12
|
-
|
13
|
-
after_save :add_new_roles_to_admin
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
module InstanceMethods
|
18
|
-
private
|
19
|
-
|
20
|
-
# Public: Actualiza los roles de los administradores luego de haber actualizado el grupo de roles.
|
21
|
-
#
|
22
|
-
# Returns nothing.
|
23
|
-
def add_new_roles_to_admin
|
24
|
-
group.admins.each do |admin|
|
25
|
-
admin.roles << self.role unless admin.roles.include?(self.role)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'rails/generators/migration'
|
2
|
-
require 'thor/shell/basic.rb'
|
3
|
-
|
4
|
-
module Burlesque
|
5
|
-
module Generators
|
6
|
-
class InstallGenerator < Rails::Generators::Base
|
7
|
-
include Rails::Generators::Migration
|
8
|
-
source_root File.expand_path('../templates', __FILE__)
|
9
|
-
|
10
|
-
def copy_model_and_migration
|
11
|
-
######## Role #######
|
12
|
-
# Crea el modelo Role
|
13
|
-
copy_file "role.rb", "app/models/role.rb"
|
14
|
-
|
15
|
-
# Crea la tabla del modelo
|
16
|
-
if not role = Dir.glob("db/migrate/[0-9]*_*.rb").grep(/\d+_create_roles.rb$/).first
|
17
|
-
migration_template "create_roles.rb", "db/migrate/create_roles.rb"
|
18
|
-
else
|
19
|
-
Thor::Shell::Basic.new.say_status :exist, role, :blue
|
20
|
-
end
|
21
|
-
|
22
|
-
######## Authorization #######
|
23
|
-
# Crea el modelo Authorization
|
24
|
-
copy_file "authorization.rb", "app/models/authorization.rb"
|
25
|
-
|
26
|
-
# Crea la tabla del modelo
|
27
|
-
if not authorization = Dir.glob("db/migrate/[0-9]*_*.rb").grep(/\d+_create_authorizations.rb$/).first
|
28
|
-
migration_template "create_authorizations.rb", "db/migrate/create_authorizations.rb"
|
29
|
-
else
|
30
|
-
Thor::Shell::Basic.new.say_status :exist, authorization, :blue
|
31
|
-
end
|
32
|
-
|
33
|
-
######## Group #######
|
34
|
-
# Crea el modelo Group
|
35
|
-
copy_file "group.rb", "app/models/group.rb"
|
36
|
-
|
37
|
-
# Crea la tabla del modelo
|
38
|
-
if not group = Dir.glob("db/migrate/[0-9]*_*.rb").grep(/\d+_create_groups.rb$/).first
|
39
|
-
migration_template "create_groups.rb", "db/migrate/create_groups.rb"
|
40
|
-
else
|
41
|
-
Thor::Shell::Basic.new.say_status :exist, group, :blue
|
42
|
-
end
|
43
|
-
|
44
|
-
######## Role-Group #######
|
45
|
-
# Crea el modelo Role-Group
|
46
|
-
copy_file "role_group.rb", "app/models/role_group.rb"
|
47
|
-
|
48
|
-
# Crea la tabla del modelo
|
49
|
-
if not role_group = Dir.glob("db/migrate/[0-9]*_*.rb").grep(/\d+_create_role_groups.rb$/).first
|
50
|
-
migration_template "create_role_groups.rb", "db/migrate/create_role_groups.rb"
|
51
|
-
else
|
52
|
-
Thor::Shell::Basic.new.say_status :exist, role_group, :blue
|
53
|
-
end
|
54
|
-
|
55
|
-
######## Admin-Group #######
|
56
|
-
# Crea el modelo Admin-Group
|
57
|
-
copy_file "admin_group.rb", "app/models/admin_group.rb"
|
58
|
-
|
59
|
-
# Crea la tabla del modelo
|
60
|
-
if not admin_group = Dir.glob("db/migrate/[0-9]*_*.rb").grep(/\d+_create_admin_groups.rb$/).first
|
61
|
-
migration_template "create_admin_groups.rb", "db/migrate/create_admin_groups.rb"
|
62
|
-
else
|
63
|
-
Thor::Shell::Basic.new.say_status :exist, admin_group, :blue
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
def self.next_migration_number path
|
69
|
-
# unless @prev_migration_nr
|
70
|
-
# @prev_migration_nr = Dir.glob("#{Rails.root}/db/migrate/[0-9]*_*.rb").inject(0) do |max, file_path|
|
71
|
-
# n = File.basename(file_path).split('_', 2).first.to_i
|
72
|
-
# if n > max then n else max end
|
73
|
-
# end
|
74
|
-
# else
|
75
|
-
# @prev_migration_nr += 1
|
76
|
-
# end
|
77
|
-
|
78
|
-
# ActiveRecord::Migration.new.next_migration_number(@prev_migration_nr.to_s)
|
79
|
-
|
80
|
-
next_migration_number = current_migration_number(path) + 1
|
81
|
-
ActiveRecord::Migration.next_migration_number(next_migration_number)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class CreateAdminGroups < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :admin_groups do |t|
|
4
|
-
t.references :group
|
5
|
-
t.integer :adminable_id
|
6
|
-
t.string :adminable_type
|
7
|
-
|
8
|
-
t.timestamps
|
9
|
-
end
|
10
|
-
add_index :admin_groups, :group_id
|
11
|
-
add_index :admin_groups, [:adminable_id, :adminable_type], name: 'by_adminable'
|
12
|
-
end
|
13
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
class CreateAuthorizations < ActiveRecord::Migration
|
2
|
-
def change
|
3
|
-
create_table :authorizations do |t|
|
4
|
-
t.references :role
|
5
|
-
t.integer :authorizable_id
|
6
|
-
t.string :authorizable_type
|
7
|
-
|
8
|
-
t.timestamps
|
9
|
-
end
|
10
|
-
add_index :authorizations, :role_id
|
11
|
-
add_index :authorizations, [:authorizable_id, :authorizable_type], name: 'by_authorizable'
|
12
|
-
end
|
13
|
-
end
|