Fixes for api_controller

Changes the way that the controller prefix is being removed from the
controller name to determine permissions. This also adds authorize and
find_project_by_project_id to the v2 controller.
pull/1196/head
Martin Czuchra 12 years ago
parent ec6e2f62a4
commit 0071d7ad6b
  1. 16
      app/controllers/api/v1/api_controller.rb
  2. 20
      app/controllers/api/v2/api_controller.rb

@ -21,9 +21,13 @@ module Api
end end
end end
def api_version
@@api_version ||= /api\/v1\//
end
def check_if_deletion_allowed(*args, &block) def check_if_deletion_allowed(*args, &block)
original_controller = params[:controller] original_controller = params[:controller]
params[:controller] = original_controller.gsub(/api\/v1\//, "") params[:controller] = original_controller.gsub(api_version, "")
result = super(*args, &block) result = super(*args, &block)
params[:controller] = original_controller params[:controller] = original_controller
result result
@ -31,7 +35,7 @@ module Api
def find_project(*args, &block) def find_project(*args, &block)
original_controller = params[:controller] original_controller = params[:controller]
params[:controller] = original_controller.gsub(/api\/v1\//, "") params[:controller] = original_controller.gsub(api_version, "")
result = super(*args, &block) result = super(*args, &block)
params[:controller] = original_controller params[:controller] = original_controller
result result
@ -39,7 +43,7 @@ module Api
def find_time_entry(*args, &block) def find_time_entry(*args, &block)
original_controller = params[:controller] original_controller = params[:controller]
params[:controller] = original_controller.gsub(/api\/v1\//, "") params[:controller] = original_controller.gsub(api_version, "")
result = super(*args, &block) result = super(*args, &block)
params[:controller] = original_controller params[:controller] = original_controller
result result
@ -47,7 +51,7 @@ module Api
def find_optional_project(*args, &block) def find_optional_project(*args, &block)
original_controller = params[:controller] original_controller = params[:controller]
params[:controller] = original_controller.gsub(/api\/v1\//, "") params[:controller] = original_controller.gsub(api_version, "")
result = super(*args, &block) result = super(*args, &block)
params[:controller] = original_controller params[:controller] = original_controller
result result
@ -55,7 +59,7 @@ module Api
def authorize_for_user(*args, &block) def authorize_for_user(*args, &block)
original_controller = params[:controller] original_controller = params[:controller]
params[:controller] = original_controller.gsub(/api\/v1\//, "") params[:controller] = original_controller.gsub(api_version, "")
result = super(*args, &block) result = super(*args, &block)
params[:controller] = original_controller params[:controller] = original_controller
result result
@ -63,7 +67,7 @@ module Api
def authorize(*args, &block) def authorize(*args, &block)
original_controller = params[:controller] original_controller = params[:controller]
params[:controller] = original_controller.gsub(/api\/v1\//, "") params[:controller] = original_controller.gsub(api_version, "")
result = super(*args, &block) result = super(*args, &block)
params[:controller] = original_controller params[:controller] = original_controller
result result

@ -16,6 +16,26 @@ module Api
extend ::Api::V1::ApiController extend ::Api::V1::ApiController
def api_version
@@api_version ||= /api\/v2\//
end
def find_project_by_project_id(*args, &block)
original_controller = params[:controller]
params[:controller] = original_controller.gsub(api_version, "")
result = super(*args, &block)
params[:controller] = original_controller
result
end
def authorize(*args, &block)
original_controller = params[:controller]
params[:controller] = original_controller.gsub(api_version, "")
result = super(*args, &block)
params[:controller] = original_controller
result
end
end end
end end

Loading…
Cancel
Save