app/models/permission.rb in gb_mapfish_appserver-0.0.3 vs app/models/permission.rb in gb_mapfish_appserver-0.0.4

- old
+ new

@@ -43,17 +43,19 @@ def compare(resource_object, resource_name) resource_name == '*' || resource_object.name == resource_name end def role_can?(role_id, action, resource) - can = if has_resource_list? - permitted_resources(role_id, action).include?(resource) - else - permitted?(resource, permissions(role_id, action)) + ActiveRecord::Base.silence do + can = if has_resource_list? + permitted_resources(role_id, action).include?(resource) + else + permitted?(resource, permissions(role_id, action)) + end + #Rails.logger.debug ">>>>>>>>>>>>>>>>>> role_can? role_id: #{role_id}, action: #{action}, resource: #{resource.name} -> #{can}" + can end - Rails.logger.debug ">>>>>>>>>>>>>>>>>> role_can? role_id: #{role_id}, action: #{action}, resource: #{resource.name} -> #{can}" - can end def roles_permissions(roles, action, resource = nil) p = [] roles.each do |role| @@ -67,21 +69,23 @@ def roles_can?(roles, action, resource) roles.find { |role| role_can?(role.id, action, resource) } end def add_ability(ability, roles) - actions.each do |action| - if has_resource_list? - ids = Rails.cache.fetch("permitted_resource_ids-#{action}-#{@resource_type_name}-roles-#{roles.collect(&:id).join(',')}") do - permitted_resource_ids(roles, action) + ActiveRecord::Base.silence do + actions.each do |action| + if has_resource_list? + ids = Rails.cache.fetch("permitted_resource_ids-#{action}-#{@resource_type_name}-roles-#{roles.collect(&:id).join(',')}") do + permitted_resource_ids(roles, action) + end + #Rails.logger.debug ">>>>>>>>>>>> permitted_resource_ids with roles #{roles.collect(&:name).join(',')} can? #{action} #{@resource_type_name}: #{ids.inspect}" + ability.can(action, @klass, :id => ids) unless ids.empty? + else + ability.can(action, @klass) do |attr| + roles_can?(roles, action, attr) + end end - Rails.logger.debug ">>>>>>>>>>>> permitted_resource_ids with roles #{roles.collect(&:name).join(',')} can? #{action} #{@resource_type_name}: #{ids.inspect}" - ability.can(action, @klass, :id => ids) unless ids.empty? - else - ability.can(action, @klass) do |attr| - roles_can?(roles, action, attr) - end end end end protected @@ -99,11 +103,11 @@ end #All resource permissionsfor a given role_id + action def permitted_resources(role_id, action) permissions = permissions(role_id, action) - resources.select do - |r| permitted?(r, permissions) + resources.select do |r| + permitted?(r, permissions) end end #All permitted resources (ids) for given roles and a action def permitted_resource_ids(roles, action)