-
Notifications
You must be signed in to change notification settings - Fork 2
Final right on clean #13
Changes from all commits
fadfa70
8f7ff3f
fd943d9
20b5a0f
dfffb64
e3f019d
c493e1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
module RightOn | ||
module ControllerAdditions | ||
def self.included(base) | ||
base.module_eval do | ||
class_attribute :rights_from | ||
class_attribute :permission_denied_layout | ||
end | ||
end | ||
|
||
private | ||
|
||
def authorize_action! | ||
controller = (self.rights_from || params[:controller]).to_s | ||
action = params[:action].to_s | ||
|
@@ -10,14 +19,34 @@ def authorize_action! | |
end | ||
|
||
def can_access_controller_action?(controller, action) | ||
(can?(:access, controller) && !Right.where(subject: controller + '#' + action).exists?) || | ||
(can?(:access, controller) && !Right.where(ccr_subject: controller + '#' + action).exists?) || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [100/80] |
||
can?(:access, controller + '#' + action) | ||
end | ||
end | ||
end | ||
|
||
if defined? ActionController::Base | ||
ActionController::Base.class_eval do | ||
include RightOn::ControllerAdditions | ||
def access_granted? | ||
can? :access, [params[:controller], params[:action]].join('#') | ||
end | ||
|
||
def rescue_access_denied(exception) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lint/UnusedMethodArgument: Unused method argument - exception. If it's necessary, use _ or _exception as an argument name to indicate that it won't be used. You can also write as rescue_access_denied(*) if you want the method to accept any arguments but don't care about them. |
||
@permission_denied_response = RightOn::PermissionDeniedResponse.new(params, controller_action_options) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [108/80] |
||
|
||
respond_to do |format| | ||
format.html do | ||
render status: :unauthorized, | ||
template: 'permission_denied', | ||
layout: ( permission_denied_layout || false ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout/SpaceInsideParens: Space inside parentheses detected. |
||
end | ||
|
||
format.json do | ||
render status: :unauthorized, json: @permission_denied_response.to_json | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [81/80] |
||
end | ||
end | ||
end | ||
|
||
def controller_action_options | ||
opts = params.slice(:controller, :action) | ||
opts[:controller] = rights_from.to_s if rights_from | ||
opts | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
require 'right_on/role_model' | ||
require 'right_on/ability' | ||
require 'right_on/rule' | ||
require 'right_on/error' | ||
require 'right_on/right' | ||
require 'right_on/role' | ||
require 'right_on/right_allowed' | ||
require 'right_on/by_group' | ||
require 'right_on/action_controller_extensions' | ||
require 'cancan/exceptions' | ||
require 'right_on/controller_additions' | ||
require 'right_on/permission_denied_response' |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
require 'simplecov-rcov' | ||
require 'coveralls' | ||
require 'coverage/kit' | ||
Coverage::Kit.setup(minimum_coverage: 92.2) | ||
Coverage::Kit.setup(minimum_coverage: 92.8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/AndOr: Use || instead of or.