burlesque 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/config/locales/burlesque.es-CL.yml +1 -1
- data/lib/burlesque/admin.rb +9 -5
- data/lib/burlesque/group.rb +4 -2
- data/lib/burlesque/role.rb +27 -13
- data/lib/burlesque/version.rb +3 -3
- metadata +2 -2
data/README.md
CHANGED
@@ -37,9 +37,9 @@ class Ability
|
|
37
37
|
def initialize(user)
|
38
38
|
if user
|
39
39
|
user.roles.each do |role|
|
40
|
-
action = role.
|
41
|
-
model = role.
|
42
|
-
can action
|
40
|
+
action = role.action_sym
|
41
|
+
model = role.resource_class
|
42
|
+
can action, model
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
data/lib/burlesque/admin.rb
CHANGED
@@ -52,13 +52,15 @@ module Burlesque
|
|
52
52
|
# Public: Permite setear los grupos que se indican.
|
53
53
|
# Eliminando los grupos que no esten en la lista.
|
54
54
|
#
|
55
|
-
# ids - id's de los
|
55
|
+
# ids - id's de los Grupos que se desean asignar destructivamente.
|
56
56
|
#
|
57
57
|
# Returns nothing.
|
58
58
|
def group_ids=(ids)
|
59
59
|
ids.each do |group_id|
|
60
|
-
|
61
|
-
|
60
|
+
if group_id.presence
|
61
|
+
group = ::Group.find(group_id)
|
62
|
+
self.groups << group unless self.groups.include?(group)
|
63
|
+
end
|
62
64
|
end
|
63
65
|
|
64
66
|
to_deletes = []
|
@@ -80,8 +82,10 @@ module Burlesque
|
|
80
82
|
# Returns nothing.
|
81
83
|
def role_ids=(ids)
|
82
84
|
ids.each do |role_id|
|
83
|
-
|
84
|
-
|
85
|
+
if role_id.presence
|
86
|
+
role = ::Role.find(role_id)
|
87
|
+
self.roles << role unless self.role?(role)
|
88
|
+
end
|
85
89
|
end
|
86
90
|
|
87
91
|
to_deletes = []
|
data/lib/burlesque/group.rb
CHANGED
@@ -44,8 +44,10 @@ module Burlesque
|
|
44
44
|
# Returns nothing.
|
45
45
|
def role_ids=(ids)
|
46
46
|
ids.each do |ri|
|
47
|
-
|
48
|
-
|
47
|
+
if ri.presence
|
48
|
+
role = ::Role.find(ri)
|
49
|
+
self.roles << role unless self.roles.include? role
|
50
|
+
end
|
49
51
|
end
|
50
52
|
|
51
53
|
to_deletes = []
|
data/lib/burlesque/role.rb
CHANGED
@@ -15,10 +15,10 @@ module Burlesque
|
|
15
15
|
validates :name, presence: true, uniqueness: true
|
16
16
|
|
17
17
|
|
18
|
-
scope :action, lambda { |action| where('name LIKE ?',
|
19
|
-
scope :not_action, lambda { |action| where('name NOT LIKE ?',
|
20
|
-
scope :resource, lambda { |model| where('name LIKE ?
|
21
|
-
scope :not_resource, lambda { |model| where('name NOT LIKE ?
|
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
22
|
end
|
23
23
|
|
24
24
|
module InstanceMethods
|
@@ -43,13 +43,28 @@ module Burlesque
|
|
43
43
|
translate = I18n.t(name.to_sym, scope: :authorizations)
|
44
44
|
return translate unless translate.include?('translation missing:')
|
45
45
|
|
46
|
+
translate = I18n.t(action_sym, scope: :authorizations) + ' ' + resource_class.model_name.human
|
47
|
+
end
|
46
48
|
|
47
|
-
|
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
|
48
55
|
|
49
|
-
|
50
|
-
|
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
|
51
62
|
|
52
|
-
|
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]
|
53
68
|
end
|
54
69
|
end
|
55
70
|
|
@@ -66,11 +81,10 @@ module Burlesque
|
|
66
81
|
end
|
67
82
|
|
68
83
|
if resource
|
69
|
-
self.create(name:
|
70
|
-
self.create(name:
|
71
|
-
self.create(name:
|
72
|
-
self.create(name:
|
73
|
-
self.create(name: "destroy_#{resource}") unless self.where(name: "destroy_#{resource}").any?
|
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?
|
74
88
|
else
|
75
89
|
raise I18n.t('errors.messages.invalid_param', param: model.class)
|
76
90
|
end
|
data/lib/burlesque/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Burlesque
|
2
|
-
VERSION = "0.0
|
3
|
-
end
|
1
|
+
module Burlesque
|
2
|
+
VERSION = "1.0.0"
|
3
|
+
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: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-25 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Crea estructura de roles y grupos para caulquier modelo, considera ademas
|
15
15
|
las 3 tablas de join que pudiesen darse
|