Created
January 26, 2009 15:42
-
-
Save aka47/52846 to your computer and use it in GitHub Desktop.
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
# add support for custom access-validation-functions | |
module Jovoto | |
module AccessControlExtended | |
class RightsHandler < Caboose::AccessHandler | |
def initialize(klass) | |
@klass = klass | |
end | |
# main method which evaluates who has access or not | |
# | |
# context / context[:user] is the current user | |
# | |
# key can be: | |
# a role, this will evaluate context[:user].role? | |
# a method_name, this expects a method with this name in the controller | |
# for example :is_owner would call the method is_owner in the controller, | |
# the return value of the method can be true/false or a user object. If it is a user-object, | |
# it will be compared to the current_user | |
def check(key, context) | |
if !key.blank? && (@klass.respond_to? key) | |
result = @klass.send(key) | |
result.is_a?(User) ? context[:user] == result : result | |
else | |
context[:user].send((key + "?").to_sym) if User.flags.include?(key) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment