Permalink
Browse files

add allowed? method to the guard

  • Loading branch information...
1 parent 3aec29f commit 5152237cd35e24e7c8ef904fdb3bb396ab583185 @mkristian committed Feb 19, 2012
Showing with 10 additions and 6 deletions.
  1. +10 −6 lib/ixtlan/guard/guard_rails.rb
@@ -35,13 +35,17 @@ def guard
Rails.application.config.guard
end
- def check(association = nil, &block)
+ def allowed?(action, association = nil, &block)
group_method = respond_to?(:current_user_groups) ? :current_user_groups : :groups_for_current_user
- unless guard.allowed?(params[:controller],
- params[:action],
- send(group_method),
- association,
- &block)
+ guard.allowed?(params[:controller],
+ action,
+ send(group_method) || []
+ association,
+ &block)
+ end
+
+ def check(association = nil, &block)
+ unless allowed?(params[:action], association, &block)
if association
raise ::Ixtlan::Guard::PermissionDenied.new("permission denied for '#{params[:controller]}##{params[:action]}##{association.class}(#{association.id})'")
else

0 comments on commit 5152237

Please sign in to comment.