Feature-toggle API also per API key

We looked only at logged in users (session cookie) before.
This commit is contained in:
Maikel Linke
2022-04-15 12:34:57 +10:00
parent c001463f8a
commit ba1e21ad75
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