7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/kete_translatable_content/extensions/models/user.rb', line 7
def basket_permissions
select = "roles.id AS role_id, roles.name AS role_name, baskets.id AS basket_id, baskets.urlified_name AS basket_urlified_name, baskets.name AS basket_name"
join = "INNER JOIN baskets on roles.authorizable_id = baskets.id"
permissions = roles.find_all_by_authorizable_type('Basket', :select => select, :joins => join)
basket_ids = permissions.collect { |p| p.basket_id.to_i }
translations = Basket::Translation.all(:basket_id => basket_ids, :locale => I18n.locale.to_s)
logger.debug("what is locale: " + I18n.locale.inspect )
logger.debug("what are translations: " + translations.inspect )
permissions_hash = Hash.new
permissions.each do |permission|
p = permission.attributes
translation = translations.select { |t| t.basket_id == p['basket_id'].to_i }.first
p['basket_name'] = translation ? translation.name : p['basket_name']
permissions_hash[p['basket_urlified_name'].to_sym] = {
:id => p['basket_id'].to_i,
:role_id => p['role_id'].to_i,
:role_name => p['role_name'],
:basket_name => p['basket_name']
}
end
permissions_hash
end
|