lib/ixtlan/guard/guard_rails.rb in ixtlan-guard-0.7.0 vs lib/ixtlan/guard/guard_rails.rb in ixtlan-guard-0.7.2

- old
+ new

@@ -10,13 +10,11 @@ protected def groups_for_current_user if respond_to?(:current_user) && current_user - current_user.groups.collect do |group| - group.name - end + current_user.groups else [] end end end @@ -35,26 +33,28 @@ def guard Rails.application.config.guard end - def check(flavor = nil, &block) - group_method = respond_to?(:current_user_group_names) ? :current_user_group_names : :groups_for_current_user + def check(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), - flavor, + association, &block) - if flavor - raise ::Ixtlan::Guard::PermissionDenied.new("permission denied for '#{params[:controller]}##{params[:action]}##{flavor}'") + if association + raise ::Ixtlan::Guard::PermissionDenied.new("permission denied for '#{params[:controller]}##{params[:action]}##{association.class}(#{association.id})'") else raise ::Ixtlan::Guard::PermissionDenied.new("permission denied for '#{params[:controller]}##{params[:action]}'") end end true end + alias :authorize :check def authorization + warn "DEPRECATED: use 'authorize' instead" check end end end end