diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb index 39f9e1684b..a0fbfad70d 100644 --- a/app/controllers/api/v1/base_controller.rb +++ b/app/controllers/api/v1/base_controller.rb @@ -14,6 +14,7 @@ module Api attr_accessor :current_api_user before_action :authenticate_user + before_action :restrict_feature rescue_from StandardError, with: :error_during_processing rescue_from CanCan::AccessDenied, with: :unauthorized @@ -38,6 +39,10 @@ module Api invalid_api_key end + def restrict_feature + not_found unless Flipper.enabled?(:api_v1, @current_api_user) + end + def current_ability Spree::Ability.new(current_api_user) end diff --git a/config/routes/api.rb b/config/routes/api.rb index 2a72d60155..748c4ac563 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -87,7 +87,7 @@ Openfoodnetwork::Application.routes.draw do constraints: lambda { |_| Flipper.enabled?(:api_reports) } end - namespace :v1, constraints: ->(request) { Flipper.enabled?(:api_v1, request.env["warden"].user) } do + namespace :v1 do resources :customers resources :enterprises do