From 0071d7ad6b0f4c363d22d2cd75ad46fcf578acf7 Mon Sep 17 00:00:00 2001 From: Martin Czuchra Date: Fri, 14 Jun 2013 10:54:55 +0200 Subject: [PATCH] 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. --- app/controllers/api/v1/api_controller.rb | 16 ++++++++++------ app/controllers/api/v2/api_controller.rb | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/v1/api_controller.rb b/app/controllers/api/v1/api_controller.rb index e8ee918875..d5e4c43d2d 100644 --- a/app/controllers/api/v1/api_controller.rb +++ b/app/controllers/api/v1/api_controller.rb @@ -21,9 +21,13 @@ module Api end end + def api_version + @@api_version ||= /api\/v1\// + end + def check_if_deletion_allowed(*args, &block) original_controller = params[:controller] - params[:controller] = original_controller.gsub(/api\/v1\//, "") + params[:controller] = original_controller.gsub(api_version, "") result = super(*args, &block) params[:controller] = original_controller result @@ -31,7 +35,7 @@ module Api def find_project(*args, &block) original_controller = params[:controller] - params[:controller] = original_controller.gsub(/api\/v1\//, "") + params[:controller] = original_controller.gsub(api_version, "") result = super(*args, &block) params[:controller] = original_controller result @@ -39,7 +43,7 @@ module Api def find_time_entry(*args, &block) original_controller = params[:controller] - params[:controller] = original_controller.gsub(/api\/v1\//, "") + params[:controller] = original_controller.gsub(api_version, "") result = super(*args, &block) params[:controller] = original_controller result @@ -47,7 +51,7 @@ module Api def find_optional_project(*args, &block) original_controller = params[:controller] - params[:controller] = original_controller.gsub(/api\/v1\//, "") + params[:controller] = original_controller.gsub(api_version, "") result = super(*args, &block) params[:controller] = original_controller result @@ -55,7 +59,7 @@ module Api def authorize_for_user(*args, &block) original_controller = params[:controller] - params[:controller] = original_controller.gsub(/api\/v1\//, "") + params[:controller] = original_controller.gsub(api_version, "") result = super(*args, &block) params[:controller] = original_controller result @@ -63,7 +67,7 @@ module Api def authorize(*args, &block) original_controller = params[:controller] - params[:controller] = original_controller.gsub(/api\/v1\//, "") + params[:controller] = original_controller.gsub(api_version, "") result = super(*args, &block) params[:controller] = original_controller result diff --git a/app/controllers/api/v2/api_controller.rb b/app/controllers/api/v2/api_controller.rb index 759bc72582..0eac887939 100644 --- a/app/controllers/api/v2/api_controller.rb +++ b/app/controllers/api/v2/api_controller.rb @@ -16,6 +16,26 @@ module Api 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