Merge pull request #9098 from mkllnk/toggle-api

Feature-toggle API also per API key
This commit is contained in:
Filipe
2022-04-15 16:14:48 +01:00
committed by GitHub
2 changed files with 6 additions and 1 deletions

View File

@@ -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

View File

@@ -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