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.
Files changed (85) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +22 -3
  3. data/Rakefile +40 -1
  4. data/app/assets/javascripts/burlesque/application.js +15 -0
  5. data/app/assets/stylesheets/burlesque/application.css +13 -0
  6. data/app/controllers/burlesque/application_controller.rb +4 -0
  7. data/app/helpers/burlesque/application_helper.rb +4 -0
  8. data/app/models/burlesque/admin_group.rb +22 -0
  9. data/app/models/burlesque/admin_role.rb +13 -0
  10. data/app/models/burlesque/group.rb +87 -0
  11. data/app/models/burlesque/role.rb +92 -0
  12. data/app/models/burlesque/role_group.rb +24 -0
  13. data/app/views/layouts/burlesque/application.html.erb +14 -0
  14. data/config/routes.rb +2 -0
  15. data/db/migrate/20130725210208_create_burlesque_groups.rb +9 -0
  16. data/db/migrate/20130725210428_create_burlesque_roles.rb +9 -0
  17. data/db/migrate/20130725214806_create_burlesque_admin_groups.rb +15 -0
  18. data/db/migrate/20130725223204_create_burlesque_role_groups.rb +12 -0
  19. data/db/migrate/20130725223437_create_burlesque_admin_roles.rb +15 -0
  20. data/lib/burlesque.rb +5 -6
  21. data/lib/burlesque/admin.rb +14 -10
  22. data/lib/burlesque/engine.rb +5 -0
  23. data/lib/burlesque/version.rb +1 -1
  24. data/lib/tasks/burlesque_tasks.rake +4 -0
  25. data/test/burlesque_test.rb +7 -0
  26. data/test/dummy/README.rdoc +261 -0
  27. data/test/dummy/Rakefile +7 -0
  28. data/test/dummy/app/assets/javascripts/application.js +15 -0
  29. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  30. data/test/dummy/app/controllers/application_controller.rb +3 -0
  31. data/test/dummy/app/helpers/application_helper.rb +2 -0
  32. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  33. data/test/dummy/config.ru +4 -0
  34. data/test/dummy/config/application.rb +59 -0
  35. data/test/dummy/config/boot.rb +10 -0
  36. data/test/dummy/config/database.yml +25 -0
  37. data/test/dummy/config/environment.rb +5 -0
  38. data/test/dummy/config/environments/development.rb +37 -0
  39. data/test/dummy/config/environments/production.rb +67 -0
  40. data/test/dummy/config/environments/test.rb +37 -0
  41. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  42. data/test/dummy/config/initializers/inflections.rb +15 -0
  43. data/test/dummy/config/initializers/mime_types.rb +5 -0
  44. data/test/dummy/config/initializers/secret_token.rb +7 -0
  45. data/test/dummy/config/initializers/session_store.rb +8 -0
  46. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  47. data/test/dummy/config/locales/en.yml +5 -0
  48. data/test/dummy/config/routes.rb +4 -0
  49. data/test/dummy/public/404.html +26 -0
  50. data/test/dummy/public/422.html +26 -0
  51. data/test/dummy/public/500.html +25 -0
  52. data/test/dummy/public/favicon.ico +0 -0
  53. data/test/dummy/script/rails +6 -0
  54. data/test/fixtures/burlesque/admin_groups.yml +9 -0
  55. data/test/fixtures/burlesque/admin_roles.yml +9 -0
  56. data/test/fixtures/burlesque/groups.yml +7 -0
  57. data/test/fixtures/burlesque/role_groups.yml +9 -0
  58. data/test/fixtures/burlesque/roles.yml +7 -0
  59. data/test/integration/navigation_test.rb +10 -0
  60. data/test/test_helper.rb +15 -0
  61. data/test/unit/burlesque/admin_group_test.rb +9 -0
  62. data/test/unit/burlesque/admin_role_test.rb +9 -0
  63. data/test/unit/burlesque/group_test.rb +9 -0
  64. data/test/unit/burlesque/role_group_test.rb +9 -0
  65. data/test/unit/burlesque/role_test.rb +9 -0
  66. metadata +123 -25
  67. data/.gitignore +0 -7
  68. data/Gemfile +0 -4
  69. data/burlesque.gemspec +0 -24
  70. data/lib/burlesque/admin_group.rb +0 -25
  71. data/lib/burlesque/authorization.rb +0 -13
  72. data/lib/burlesque/group.rb +0 -91
  73. data/lib/burlesque/role.rb +0 -94
  74. data/lib/burlesque/role_group.rb +0 -30
  75. data/lib/generators/burlesque/install_generator.rb +0 -85
  76. data/lib/generators/burlesque/templates/admin_group.rb +0 -3
  77. data/lib/generators/burlesque/templates/authorization.rb +0 -3
  78. data/lib/generators/burlesque/templates/create_admin_groups.rb +0 -13
  79. data/lib/generators/burlesque/templates/create_authorizations.rb +0 -13
  80. data/lib/generators/burlesque/templates/create_groups.rb +0 -9
  81. data/lib/generators/burlesque/templates/create_role_groups.rb +0 -12
  82. data/lib/generators/burlesque/templates/create_roles.rb +0 -9
  83. data/lib/generators/burlesque/templates/group.rb +0 -3
  84. data/lib/generators/burlesque/templates/role.rb +0 -3
  85. data/lib/generators/burlesque/templates/role_group.rb +0 -3
@@ -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
@@ -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,3 +0,0 @@
1
- class AdminGroup < ActiveRecord::Base
2
- include Burlesque::AdminGroup
3
- end
@@ -1,3 +0,0 @@
1
- class Authorization < ActiveRecord::Base
2
- include Burlesque::Authorization
3
- 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
@@ -1,9 +0,0 @@
1
- class CreateGroups < ActiveRecord::Migration
2
- def change
3
- create_table :groups do |t|
4
- t.string :name
5
-
6
- t.timestamps
7
- end
8
- end
9
- end
@@ -1,12 +0,0 @@
1
- class CreateRoleGroups < ActiveRecord::Migration
2
- def change
3
- create_table :role_groups do |t|
4
- t.references :role
5
- t.references :group
6
-
7
- t.timestamps
8
- end
9
- add_index :role_groups, :role_id
10
- add_index :role_groups, :group_id
11
- end
12
- end
@@ -1,9 +0,0 @@
1
- class CreateRoles < ActiveRecord::Migration
2
- def change
3
- create_table :roles do |t|
4
- t.string :name
5
-
6
- t.timestamps
7
- end
8
- end
9
- end
@@ -1,3 +0,0 @@
1
- class Group < ActiveRecord::Base
2
- include Burlesque::Group
3
- end
@@ -1,3 +0,0 @@
1
- class Role < ActiveRecord::Base
2
- include Burlesque::Role
3
- end
@@ -1,3 +0,0 @@
1
- class RoleGroup < ActiveRecord::Base
2
- include Burlesque::RoleGroup
3
- end