Method: Moonrope::Action#check_access
- Defined in:
- lib/moonrope/action.rb
#check_access(request = nil) ⇒ Boolean
Check whether the authenticated user has access to this request. Accepts a Request or an EvalEnvironment.
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/moonrope/action.rb', line 196 def check_access(request = nil) if request.is_a?(EvalEnvironment) eval_environment = request else eval_environment = EvalEnvironment.new(@controller.base, request, self) end if authenticator_to_use.is_a?(Moonrope::Authenticator) if rule = authenticator_to_use.rules[access_rule_to_use] eval_environment.instance_exec(self, &rule[:block]) == true else if access_rule_to_use == :default # The default rule on any authenticator will allow everything so we # don't need to worry about this not being defined. true else # If an access rule that doesn't exist has been requested, we will # raise an internal error. raise Moonrope::Errors::MissingAccessRule, "The rule '#{access_rule_to_use}' was not found on '#{authenticator_to_use.name}' authenticator" end end else true end end |