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