Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for permission attached to groups + validation in rails contr…
…ollers
- Loading branch information
1 parent
9417cf3
commit 0c29a99
Showing
10 changed files
with
188 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
require File.dirname(__FILE__) + "/lib/grizzly" | ||
require 'grizzly' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
module Grizzly #nodoc | ||
class PermissionNotDefinedButSetAsDefault < StandardError; end | ||
class PermissionNotDefined < StandardError; end | ||
class AuthorizationFailureNoUser < StandardError; end | ||
class AuthorizationFailureDenyPermission < StandardError; end | ||
class AuthorizationFailureMissedPermission < StandardError; end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require 'action_controller' | ||
|
||
module Grizzly #nodoc | ||
module ActionControllerExtensions | ||
|
||
def self.included(base) | ||
base.extend(ClassMethods) | ||
base.send(:include, InstanceMethods) | ||
base.class_eval do | ||
before_filter "authorized?" | ||
end | ||
end | ||
|
||
module InstanceMethods | ||
def authorized? | ||
begin | ||
name = "#{controller_path.gsub('/', '__')}_controller".to_sym | ||
if Grizzly::Permissions.for_controller.has_key?(name) | ||
perm_info = Grizzly::Permissions.for_controller[name] | ||
action = perm_info.has_key?(action_name.to_sym) ? action_name.to_sym : :all | ||
user = current_user | ||
if perm_info[:action].present? | ||
perm_info[action][:deny].each do |deny_perm| | ||
raise Grizzly::AuthorizationFailureNoUser if user.nil? | ||
raise Grizzly::AuthorizationFailureDenyPermission if user.can?(deny_perm) | ||
end | ||
perm_info[action][:allow].each do |allow_perm| | ||
raise Grizzly::AuthorizationFailureNoUser if user.nil? | ||
raise Grizzly::AuthorizationFailureMissedPermission unless user.can?(allow_perm) | ||
end | ||
end | ||
end | ||
rescue Grizzly::AuthorizationFailureNoUser | ||
logger.debug "GRIZZLY makes WRRRRRRRRRRAU! => Authorization Failure :: No valid User found" | ||
redirect_to root_path | ||
rescue Grizzly::AuthorizationFailureDenyPermission | ||
logger.debug "GRIZZLY makes WRRRRRRRRRRAU! => Authorization Failure :: User #{current_user.id} has deny permission" | ||
redirect_to root_path | ||
rescue Grizzly::AuthorizationFailureMissedPermission | ||
logger.debug "GRIZZLY makes WRRRRRRRRRRAU! => Authorization Failure :: User #{current_user.id} hasn't got required permission" | ||
redirect_to root_path | ||
end | ||
return true | ||
end | ||
end | ||
|
||
module ClassMethods | ||
|
||
end | ||
end | ||
end | ||
|
||
if defined? ActionController::Base | ||
ActionController::Base.send(:include, Grizzly::ActionControllerExtensions) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters