burlesque 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/README.md +49 -0
- data/burlesque.gemspec +2 -2
- data/config/locales/burlesque.en.yml +32 -0
- data/config/locales/burlesque.es-CL.yml +2 -2
- data/lib/burlesque.rb +7 -4
- data/lib/burlesque/admin.rb +112 -0
- data/lib/burlesque/admin_group.rb +25 -0
- data/lib/burlesque/authorization.rb +13 -0
- data/lib/burlesque/group.rb +89 -0
- data/lib/burlesque/locale.rb +8 -0
- data/lib/burlesque/role.rb +80 -0
- data/lib/burlesque/role_group.rb +30 -0
- data/lib/burlesque/version.rb +1 -1
- data/lib/generators/burlesque/install_generator.rb +85 -0
- data/lib/generators/burlesque/templates/admin_group.rb +3 -0
- data/lib/generators/burlesque/templates/authorization.rb +3 -0
- data/lib/generators/burlesque/templates/create_admin_groups.rb +13 -0
- data/lib/generators/burlesque/templates/create_authorizations.rb +13 -0
- data/lib/generators/burlesque/templates/create_groups.rb +9 -0
- data/lib/generators/burlesque/templates/create_role_groups.rb +12 -0
- data/lib/generators/burlesque/templates/create_roles.rb +9 -0
- data/lib/generators/burlesque/templates/group.rb +3 -0
- data/lib/generators/burlesque/templates/role.rb +3 -0
- data/lib/generators/burlesque/templates/role_group.rb +3 -0
- metadata +26 -5
data/.gitignore
CHANGED
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
Burlesque
|
2
|
+
=========
|
3
|
+
|
4
|
+
Crea estructura de roles y grupos para cualquier modelo, considera además las 3 tablas de _join_ que pudiesen darse.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
Before you can use the generator, add the gem to your project's Gemfile as follows:
|
10
|
+
|
11
|
+
```
|
12
|
+
gem 'burlesque', :git => 'git@gitlab.acid.cl:burlesque.git'
|
13
|
+
```
|
14
|
+
|
15
|
+
Then install it by running:
|
16
|
+
|
17
|
+
```
|
18
|
+
bundle install
|
19
|
+
```
|
20
|
+
|
21
|
+
Finally, bootstrap your Rails app, for example:
|
22
|
+
|
23
|
+
```
|
24
|
+
rails generate burlesque:install
|
25
|
+
rake db:migrate
|
26
|
+
```
|
27
|
+
|
28
|
+
CanCan
|
29
|
+
------
|
30
|
+
|
31
|
+
Burlesque makes no assumption about how auhtorizations are handled in your application. However it integrates nicely with [CanCan][cancan]; all you have to do is define the `Ability` model as follows:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class Ability
|
35
|
+
include CanCan::Ability
|
36
|
+
|
37
|
+
def initialize(user)
|
38
|
+
if user
|
39
|
+
user.roles.each do |role|
|
40
|
+
action = role.name.split('_', 2).first
|
41
|
+
model = role.name.split('_', 2).last.pluralize.classify.constantize
|
42
|
+
can action.to_sym, model
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
[cancan]: https://github.com/ryanb/cancan
|
data/burlesque.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.authors = ["mespina"]
|
9
9
|
s.email = ["mespina.icc@gmail.com"]
|
10
10
|
s.homepage = ""
|
11
|
-
s.summary = "
|
12
|
-
s.description = "
|
11
|
+
s.summary = "Roles y Grupos"
|
12
|
+
s.description = "Crea estructura de roles y grupos para caulquier modelo, considera ademas las 3 tablas de join que pudiesen darse"
|
13
13
|
|
14
14
|
s.rubyforge_project = "burlesque"
|
15
15
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
en:
|
2
|
+
errors: &errors
|
3
|
+
messages:
|
4
|
+
role_taken: already assigned
|
5
|
+
group_taken: already assigned
|
6
|
+
invalid_param: '<%{param}> invalid, try with <Class>, <String> or <Symbol>'
|
7
|
+
access_denied: You are not authorized to perform this action.
|
8
|
+
activerecord:
|
9
|
+
models:
|
10
|
+
role:
|
11
|
+
one: Privilege
|
12
|
+
other: Privileges
|
13
|
+
group:
|
14
|
+
one: Group
|
15
|
+
other: Groups
|
16
|
+
attributes:
|
17
|
+
role:
|
18
|
+
name: Name
|
19
|
+
created_at: created
|
20
|
+
updated_at: updated
|
21
|
+
group:
|
22
|
+
name: Name
|
23
|
+
roles: Privileges
|
24
|
+
created_at: created
|
25
|
+
updated_at: updated
|
26
|
+
authorizations:
|
27
|
+
read: List
|
28
|
+
show: Show
|
29
|
+
create: Create
|
30
|
+
update: Update
|
31
|
+
destroy: Destroy
|
32
|
+
manage: Manage
|
@@ -23,10 +23,10 @@
|
|
23
23
|
roles: Privilegios
|
24
24
|
created_at: Creado
|
25
25
|
updated_at: Última actualización
|
26
|
-
internal: Uso exclusivo de Latamticket
|
27
26
|
authorizations:
|
28
27
|
read: Listar
|
29
28
|
show: Mostrar
|
30
29
|
create: Crear
|
31
30
|
update: Actualizar
|
32
|
-
destroy: Eliminar
|
31
|
+
destroy: Eliminar
|
32
|
+
manage: Administrar
|
data/lib/burlesque.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
require "burlesque/admin_group"
|
2
|
+
require "burlesque/authorization"
|
3
|
+
require "burlesque/group"
|
4
|
+
require "burlesque/role"
|
5
|
+
require "burlesque/role_group"
|
6
|
+
require "burlesque/locale"
|
7
|
+
require "burlesque/admin"
|
1
8
|
require "burlesque/version"
|
2
|
-
|
3
|
-
module Burlesque
|
4
|
-
# Your code goes here...
|
5
|
-
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Burlesque
|
4
|
+
module Admin
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
has_many :authorizations, as: :authorizable, dependent: :destroy
|
9
|
+
has_many :roles, through: :authorizations
|
10
|
+
|
11
|
+
has_many :admin_groups, as: :adminable, dependent: :destroy
|
12
|
+
has_many :groups, through: :admin_groups, after_remove: :remove_roles_from_admin
|
13
|
+
|
14
|
+
attr_accessible :group_ids,
|
15
|
+
:role_ids
|
16
|
+
end
|
17
|
+
|
18
|
+
module InstanceMethods
|
19
|
+
# Public: Indica si tiene un rol en particular.
|
20
|
+
#
|
21
|
+
# role - el rol que se quiere consultar, puede ser un Role o Role.name
|
22
|
+
#
|
23
|
+
# Returns Boolean.
|
24
|
+
def role? role
|
25
|
+
role_name = role.respond_to?(:name) ? role.name : role
|
26
|
+
self.roles.map(&:name).include?(role_name.to_s)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Public: Indica si tiene un grupo en particular.
|
30
|
+
#
|
31
|
+
# group - el grupo que se quiere consultar, puede ser un Group o Group.name
|
32
|
+
#
|
33
|
+
# Returns Boolean.
|
34
|
+
def group? group
|
35
|
+
group_name = group.respond_to?(:name) ? group.name : group
|
36
|
+
self.groups.map(&:name).include?(group_name.to_s)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Public: Indica si un rol en particular esta presente en los grupos que tiene asignados.
|
40
|
+
#
|
41
|
+
# role - el rol que se quiere consultar, puede ser un Role o Role.name
|
42
|
+
#
|
43
|
+
# Returns Boolean.
|
44
|
+
def role_in_groups? role
|
45
|
+
role_name = role.respond_to?(:name) ? role.name : role
|
46
|
+
groups.each do |group|
|
47
|
+
return true if group.role?(role_name)
|
48
|
+
end
|
49
|
+
false
|
50
|
+
end
|
51
|
+
|
52
|
+
# Public: Permite setear los grupos que se indican.
|
53
|
+
# Eliminando los grupos que no esten en la lista.
|
54
|
+
#
|
55
|
+
# ids - id's de los Roles que se desean asignar destructivamente.
|
56
|
+
#
|
57
|
+
# Returns nothing.
|
58
|
+
def group_ids=(ids)
|
59
|
+
ids.each do |group_id|
|
60
|
+
group = ::Group.find(group_id)
|
61
|
+
self.groups << group unless self.groups.include?(group)
|
62
|
+
end
|
63
|
+
|
64
|
+
to_deletes = []
|
65
|
+
self.groups.each do |group|
|
66
|
+
to_deletes << group unless ids.include?(group.id.to_s)# or ids.include?(group.id)
|
67
|
+
end
|
68
|
+
|
69
|
+
to_deletes.each do |group|
|
70
|
+
self.groups.delete(group) if self.group?(group)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Public: Permite setear los roles que se indican.
|
75
|
+
# Eliminando los roles que no esten en la lista,
|
76
|
+
# salvo en caso de estar presente por asignacion de un grupo.
|
77
|
+
#
|
78
|
+
# ids - id's de los Roles que se desean asignar destructivamente.
|
79
|
+
#
|
80
|
+
# Returns nothing.
|
81
|
+
def role_ids=(ids)
|
82
|
+
ids.each do |role_id|
|
83
|
+
role = ::Role.find(role_id)
|
84
|
+
self.roles << role unless self.role?(role)
|
85
|
+
end
|
86
|
+
|
87
|
+
to_deletes = []
|
88
|
+
self.roles.each do |role|
|
89
|
+
to_deletes << role unless ids.include?(role.id.to_s) or self.role_in_groups?(role)# or ids.include?(role.id)
|
90
|
+
end
|
91
|
+
|
92
|
+
to_deletes.each do |role|
|
93
|
+
self.roles.delete(role) if self.roles.include?(role)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
# Public: Permite eliminar los roles de un grupo eliminado.
|
99
|
+
#
|
100
|
+
# group - El grupo que se elimino.
|
101
|
+
#
|
102
|
+
# Returns nothing.
|
103
|
+
def remove_roles_from_admin group
|
104
|
+
group.roles.each do |role|
|
105
|
+
if authorizations.map(&:role).include?(role) and not role_in_groups?(role.name)
|
106
|
+
authorizations.find_by_role_id(role.id).destroy
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Burlesque
|
4
|
+
module AdminGroup
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
belongs_to :group
|
9
|
+
belongs_to :adminable, polymorphic: true
|
10
|
+
|
11
|
+
validates_uniqueness_of :group_id, scope: [:adminable_id, :adminable_type], message: I18n.t('errors.messages.group_taken')
|
12
|
+
|
13
|
+
after_create :add_new_roles_to_admin
|
14
|
+
end
|
15
|
+
|
16
|
+
module InstanceMethods
|
17
|
+
private
|
18
|
+
def add_new_roles_to_admin
|
19
|
+
group.roles.each do |role|
|
20
|
+
adminable.roles << role unless adminable.roles.include? role
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
module Burlesque
|
3
|
+
module Authorization
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
belongs_to :role
|
8
|
+
belongs_to :authorizable, polymorphic: true
|
9
|
+
|
10
|
+
validates_uniqueness_of :role_id, scope: [:authorizable_id, :authorizable_type], message: I18n.t('errors.messages.role_taken')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Burlesque
|
4
|
+
module Group
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
has_many :role_groups
|
9
|
+
has_many :roles, through: :role_groups, dependent: :destroy, after_remove: :remove_roles_from_admin
|
10
|
+
|
11
|
+
has_many :admin_groups, dependent: :destroy
|
12
|
+
# for has_many :admins relations see admins function
|
13
|
+
|
14
|
+
attr_accessible :name, :role_ids, :internal
|
15
|
+
|
16
|
+
validates :name, presence: true, uniqueness: true
|
17
|
+
end
|
18
|
+
|
19
|
+
module InstanceMethods
|
20
|
+
# Public: Relacion a muchos usuarios
|
21
|
+
#
|
22
|
+
# Se usa esta funcion dado que la tabla de administrador es polimorfica.
|
23
|
+
#
|
24
|
+
# Returns los administradores que tienen el rol en cuestion.
|
25
|
+
def admins
|
26
|
+
admin_groups.map &:adminable
|
27
|
+
end
|
28
|
+
|
29
|
+
# Public: Indica si el grupo tiene un rol en particular.
|
30
|
+
#
|
31
|
+
# role - el rol que se quiere consultar, puede ser un Role o Role.name
|
32
|
+
#
|
33
|
+
# Returns Boolean.
|
34
|
+
def role? role
|
35
|
+
role_name = role.respond_to?(:name) ? role.name : role
|
36
|
+
self.roles.map(&:name).include?(role_name.to_s)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Public: Setea los roles que se indican al grupo.
|
40
|
+
# Eliminando los roles que no esten en la lista.
|
41
|
+
#
|
42
|
+
# ids - id's de los Roles que se desean asignar destructivamente.
|
43
|
+
#
|
44
|
+
# Returns nothing.
|
45
|
+
def role_ids=(ids)
|
46
|
+
ids.each do |ri|
|
47
|
+
role = ::Role.find(ri)
|
48
|
+
self.roles << role unless self.roles.include? role
|
49
|
+
end
|
50
|
+
|
51
|
+
to_deletes = []
|
52
|
+
role_groups.each do |rg|
|
53
|
+
role = rg.role
|
54
|
+
to_deletes << role unless ids.include?(role.id.to_s) or ids.include?(role.id)
|
55
|
+
end
|
56
|
+
|
57
|
+
to_deletes.each do |role|
|
58
|
+
self.roles.delete(role) if self.roles.include?(role)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Public: Permite agregar un grupo de Roles al Grupo
|
63
|
+
# No elimina los roles que no esten en la lista, solo agrega los que no estan.
|
64
|
+
#
|
65
|
+
# new_roles - el arreglo de roles que se quiere agregar al grupo
|
66
|
+
#
|
67
|
+
# Returns nothing.
|
68
|
+
def push_roles new_roles
|
69
|
+
new_roles.each do |role|
|
70
|
+
self.roles << role unless self.roles.include? role
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
# Public: Permite que al eliminar un rol de un grupo, tambien se modifiquen los roles de los administradores asociados a ese grupo.
|
76
|
+
#
|
77
|
+
# role - el rol que se elimino del grupo.
|
78
|
+
#
|
79
|
+
# Returns nothing.
|
80
|
+
def remove_roles_from_admin role
|
81
|
+
admins.each do |admin|
|
82
|
+
if admin.authorizations.map(&:role_id).include?(role.id) and not admin.role_in_groups?(role.name)
|
83
|
+
admin.authorizations.find_by_role_id(role.id).destroy
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,80 @@
|
|
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 ? or name LIKE ?', "%_#{model.to_s.singularize}", "%_#{model.to_s.pluralize}") }
|
21
|
+
scope :not_resource, lambda { |model| where('name NOT LIKE ? AND name NOT LIKE ?', "%_#{model.to_s.singularize}", "%_#{model.to_s.pluralize}") }
|
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
|
+
|
47
|
+
action, model = name.split('_', 2)
|
48
|
+
|
49
|
+
count = (model == model.pluralize) ? 2 : 1
|
50
|
+
model = model.pluralize
|
51
|
+
|
52
|
+
translate = I18n.t(action.to_sym, scope: :authorizations) + ' ' + model.classify.constantize.model_name.human(count: count)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
module ClassMethods
|
57
|
+
# TODO
|
58
|
+
# Mejorar el retorno, para saber que paso, ej: si se agregaron los 5 roles o si ya existen
|
59
|
+
def for model
|
60
|
+
if model.class == String
|
61
|
+
resource = model.classify.constantize.model_name.underscore
|
62
|
+
elsif model.class == Symbol
|
63
|
+
resource = model.to_s.classify.constantize.model_name.underscore
|
64
|
+
elsif model.class == Class
|
65
|
+
resource = model.model_name.underscore
|
66
|
+
end
|
67
|
+
|
68
|
+
if resource
|
69
|
+
self.create(name: "read_#{resource.pluralize}") unless self.where(name: "read_#{resource.pluralize}").any?
|
70
|
+
self.create(name: "show_#{resource}") unless self.where(name: "show_#{resource}").any?
|
71
|
+
self.create(name: "create_#{resource}") unless self.where(name: "create_#{resource}").any?
|
72
|
+
self.create(name: "update_#{resource}") unless self.where(name: "update_#{resource}").any?
|
73
|
+
self.create(name: "destroy_#{resource}") unless self.where(name: "destroy_#{resource}").any?
|
74
|
+
else
|
75
|
+
raise I18n.t('errors.messages.invalid_param', param: model.class)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,30 @@
|
|
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
|
data/lib/burlesque/version.rb
CHANGED
@@ -0,0 +1,85 @@
|
|
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
|
@@ -0,0 +1,13 @@
|
|
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
|
@@ -0,0 +1,13 @@
|
|
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
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: burlesque
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,10 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-08-29 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description:
|
14
|
+
description: Crea estructura de roles y grupos para caulquier modelo, considera ademas
|
15
|
+
las 3 tablas de join que pudiesen darse
|
15
16
|
email:
|
16
17
|
- mespina.icc@gmail.com
|
17
18
|
executables: []
|
@@ -20,11 +21,31 @@ extra_rdoc_files: []
|
|
20
21
|
files:
|
21
22
|
- .gitignore
|
22
23
|
- Gemfile
|
24
|
+
- README.md
|
23
25
|
- Rakefile
|
24
26
|
- burlesque.gemspec
|
27
|
+
- config/locales/burlesque.en.yml
|
25
28
|
- config/locales/burlesque.es-CL.yml
|
26
29
|
- lib/burlesque.rb
|
30
|
+
- lib/burlesque/admin.rb
|
31
|
+
- lib/burlesque/admin_group.rb
|
32
|
+
- lib/burlesque/authorization.rb
|
33
|
+
- lib/burlesque/group.rb
|
34
|
+
- lib/burlesque/locale.rb
|
35
|
+
- lib/burlesque/role.rb
|
36
|
+
- lib/burlesque/role_group.rb
|
27
37
|
- lib/burlesque/version.rb
|
38
|
+
- lib/generators/burlesque/install_generator.rb
|
39
|
+
- lib/generators/burlesque/templates/admin_group.rb
|
40
|
+
- lib/generators/burlesque/templates/authorization.rb
|
41
|
+
- lib/generators/burlesque/templates/create_admin_groups.rb
|
42
|
+
- lib/generators/burlesque/templates/create_authorizations.rb
|
43
|
+
- lib/generators/burlesque/templates/create_groups.rb
|
44
|
+
- lib/generators/burlesque/templates/create_role_groups.rb
|
45
|
+
- lib/generators/burlesque/templates/create_roles.rb
|
46
|
+
- lib/generators/burlesque/templates/group.rb
|
47
|
+
- lib/generators/burlesque/templates/role.rb
|
48
|
+
- lib/generators/burlesque/templates/role_group.rb
|
28
49
|
homepage: ''
|
29
50
|
licenses: []
|
30
51
|
post_install_message:
|
@@ -45,8 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
66
|
version: '0'
|
46
67
|
requirements: []
|
47
68
|
rubyforge_project: burlesque
|
48
|
-
rubygems_version: 1.8.
|
69
|
+
rubygems_version: 1.8.25
|
49
70
|
signing_key:
|
50
71
|
specification_version: 3
|
51
|
-
summary:
|
72
|
+
summary: Roles y Grupos
|
52
73
|
test_files: []
|