From 44fff3a27591b42406b0a0d6b71ee789c220563e Mon Sep 17 00:00:00 2001 From: Santiago Bartesaghi Date: Thu, 7 Mar 2024 13:02:17 -0300 Subject: [PATCH] Fix routes --- app/constraints/impersonation/enabled_constraint.rb | 9 +++++++++ config/routes.rb | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 app/constraints/impersonation/enabled_constraint.rb diff --git a/app/constraints/impersonation/enabled_constraint.rb b/app/constraints/impersonation/enabled_constraint.rb new file mode 100644 index 00000000..ba787646 --- /dev/null +++ b/app/constraints/impersonation/enabled_constraint.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module Impersonation + class EnabledConstraint + def matches?(_request) + Flipper[:impersonation_tool].enabled? || Rails.env.test? + end + end +end diff --git a/config/routes.rb b/config/routes.rb index 59e5e7e2..9c8efbf5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,7 +12,7 @@ namespace :api do namespace :v1, defaults: { format: :json } do get :status, to: 'health#status' - resources :impersonations, only: %i[create] if Flipper[:impersonation_tool].enabled? || Rails.env.test? + resources :impersonations, only: %i[create], constraints: Impersonation::EnabledConstraint.new devise_scope :user do resource :user, only: %i[update show] end