Skip to content

Instantly share code, notes, and snippets.

@aka47
Created January 26, 2009 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aka47/52846 to your computer and use it in GitHub Desktop.
Save aka47/52846 to your computer and use it in GitHub Desktop.
# 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