class RightOn::PermissionDeniedResponse
Attributes
controller_name[R]
right_allowed[R]
roles_allowed[R]
Public Class Methods
new(params, controller_action_options)
click to toggle source
# File lib/right_on/permission_denied_response.rb, line 5 def initialize(params, controller_action_options) @params = params allower = RightAllowed.new(controller_action_options[:controller], controller_action_options[:action]) @right_allowed = RightOn::Right.all.detect { |right| allower.allowed?(right) } @roles_allowed = @right_allowed.roles if @right_allowed @controller_name = @params[:controller] unless @right_allowed end
Public Instance Methods
text_message()
click to toggle source
# File lib/right_on/permission_denied_response.rb, line 13 def text_message if @right_allowed <<-MESSAGE You are not authorised to perform the requested operation. Right required: #{@right_allowed} This right is given to the following roles: #{@roles_allowed.map(&:title).join(", ")}. Contact your system manager to be given this right. MESSAGE else no_right_for_page end end
to_json()
click to toggle source
# File lib/right_on/permission_denied_response.rb, line 26 def to_json { error: 'Permission Denied', right_allowed: (@right_allowed ? @right_allowed.name : no_right_for_page), roles_for_right: (@roles_allowed ? @roles_allowed.map(&:title) : no_roles_for_page) } end
Private Instance Methods
no_right_for_page()
click to toggle source
# File lib/right_on/permission_denied_response.rb, line 36 def no_right_for_page "No right is defined for this page: #{@controller_name}. Contact your system manager to notify this problem." end
no_roles_for_page()
click to toggle source
# File lib/right_on/permission_denied_response.rb, line 40 def no_roles_for_page 'N/A (as no right is assigned for this action)' end