Used named params in AuthorizationService constructor

pull/1484/head
Marek Takac 11 years ago
parent bb8aa422b1
commit 1ca62def08
  1. 2
      app/controllers/application_controller.rb
  2. 12
      app/services/authorization_service.rb
  3. 2
      lib/api/root.rb

@ -289,7 +289,7 @@ class ApplicationController < ActionController::Base
# Authorize the user for the requested action
def authorize(ctrl = params[:controller], action = params[:action], global = false)
context = @project || @projects
is_authorized = AuthorizationService.new(ctrl, action, context, global: global).call
is_authorized = AuthorizationService.new(ctrl, action, context: context, global: global).call
unless is_authorized
if @project && @project.archived?

@ -30,19 +30,19 @@
# project, projects, global, user = nil
class AuthorizationService
# @params
# ctrl - controller
# action - action
# @named params
# context - single project or array of projects - default nil
# options[:global] - global - default false
# options[:user] - user - default current user
def initialize(ctrl, action, context = nil, options = {})
# global - global - default false
# user - user - default current user
def initialize(ctrl, action, context: nil , global: false, user: User.current)
@ctrl = ctrl
@action = action
@context = context
@global = !!options[:global]
@user = options[:user] || User.current
@global = global
@user = user
end
def call

@ -53,7 +53,7 @@ module API
if current_user.nil? || current_user.anonymous?
raise API::Errors::Unauthenticated.new
end
is_authorized = AuthorizationService.new(api, endpoint, context, global: global).call
is_authorized = AuthorizationService.new(api, endpoint, context: context, global: global).call
unless is_authorized
raise API::Errors::Unauthorized.new(current_user)
end

Loading…
Cancel
Save