lib/kit/controller/authorized.rb in rad_kit-0.0.8 vs lib/kit/controller/authorized.rb in rad_kit-0.0.9

- old
+ new

@@ -1,30 +1,31 @@ module Rad::Controller::Authorized inherited do helper_method :can?, :owner? end - + module ClassMethods def require_permission operation, *args, &object_proc - operation = operation.must_be.a(String, Symbol).to_s - + operation.must_be.a Symbol + options = args.extract_options! # object_proc = args.size > 0 ? args.first : lambda{} object_proc ||= lambda{|controller|} - - method = "require_permission_#{operation}" + + method = "require_permission_#{operation}".to_sym define_method method do require_permission operation, instance_eval(&object_proc) end + before method, options end end protected def can? *args rad.user.can? *args - end + end def owner? *args rad.user.owner? *args end @@ -35,17 +36,17 @@ def login_not_required raise_user_error t(:login_not_required) if rad.user.registered? end def require_permission operation, object = nil - operation = operation.must_be.a(String, Symbol).to_s + operation.must_be.a Symbol unless rad.user.can? operation, object rad.logger.warn "RAD access denied, #{rad.user.name} hasn't rights to #{operation}!" access_denied! end end - def access_denied! + def access_denied! raise_user_error t(:access_denied) end end \ No newline at end of file