lockdown 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/lockdown/helper.rb +12 -0
- data/lib/lockdown/rules.rb +12 -6
- data/lib/lockdown.rb +1 -1
- metadata +1 -1
data/lib/lockdown/helper.rb
CHANGED
@@ -18,6 +18,18 @@ module Lockdown
|
|
18
18
|
underscore(Lockdown::System.fetch(:user_group_model).to_s).pluralize.to_sym
|
19
19
|
end
|
20
20
|
|
21
|
+
def user_group_id_reference
|
22
|
+
underscore(Lockdown::System.fetch(:user_group_model).to_s)
|
23
|
+
end
|
24
|
+
|
25
|
+
def users_hbtm_reference
|
26
|
+
underscore(Lockdown::System.fetch(:user_model).to_s).pluralize.to_sym
|
27
|
+
end
|
28
|
+
|
29
|
+
def user_id_reference
|
30
|
+
underscore(Lockdown::System.fetch(:user_model).to_s)
|
31
|
+
end
|
32
|
+
|
21
33
|
def get_string(value)
|
22
34
|
if value.respond_to?(:name)
|
23
35
|
string_name(value.name)
|
data/lib/lockdown/rules.rb
CHANGED
@@ -209,17 +209,23 @@ module Lockdown
|
|
209
209
|
# him/her self.
|
210
210
|
def user_groups_assignable_for_user(usr)
|
211
211
|
return [] if usr.nil?
|
212
|
-
|
212
|
+
ug_table = Lockdown.user_groups_hbtm_reference.to_s
|
213
213
|
if administrator?(usr)
|
214
214
|
Lockdown::System.fetch(:user_group_model).find_by_sql <<-SQL
|
215
|
-
select
|
215
|
+
select #{ug_table}.* from #{ug_table} order by #{ug_table}.name
|
216
216
|
SQL
|
217
217
|
else
|
218
|
+
usr_table = Lockdown.users_hbtm_reference.to_s
|
219
|
+
if usr_table < ug_table
|
220
|
+
join_table = "#{usr_table}_#{ug_table}"
|
221
|
+
else
|
222
|
+
join_table = "#{ug_table}_#{usr_table}"
|
223
|
+
end
|
218
224
|
Lockdown::System.fetch(:user_group_model).find_by_sql <<-SQL
|
219
|
-
select
|
220
|
-
where
|
221
|
-
and
|
222
|
-
order by
|
225
|
+
select #{ug_table}.* from #{ug_table}, #{join_table}
|
226
|
+
where #{ug_table}.id = #{join_table}.#{Lockdown.user_group_id_reference}
|
227
|
+
and #{join_table}.#{Lockdown.user_id_reference} = #{usr.id}
|
228
|
+
order by #{ug_table}.name
|
223
229
|
SQL
|
224
230
|
end
|
225
231
|
end
|
data/lib/lockdown.rb
CHANGED