From 8a88cb1511d8d0f0d812c776b8d7eaa9a5e97243 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Fri, 30 Apr 2021 02:18:14 +0200 Subject: [PATCH] allow updates of deleted providers --- app/controllers/providers_controller.rb | 24 +++++++++++++++------- app/controllers/v3/providers_controller.rb | 24 +++++++++++++++------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/app/controllers/providers_controller.rb b/app/controllers/providers_controller.rb index ceb78fd53..e97dc3371 100644 --- a/app/controllers/providers_controller.rb +++ b/app/controllers/providers_controller.rb @@ -383,13 +383,23 @@ def set_include end def set_provider - @provider = - Provider.unscoped.where( - "allocator.role_name IN ('ROLE_FOR_PROFIT_PROVIDER', 'ROLE_CONTRACTUAL_PROVIDER', 'ROLE_CONSORTIUM' , 'ROLE_CONSORTIUM_ORGANIZATION', 'ROLE_ALLOCATOR', 'ROLE_ADMIN', 'ROLE_MEMBER', 'ROLE_DEV')", - ). - where(deleted_at: nil). - where(symbol: params[:id]). - first + if params[:include_deleted] + @provider = + Provider.unscoped.where( + "allocator.role_name IN ('ROLE_FOR_PROFIT_PROVIDER', 'ROLE_CONTRACTUAL_PROVIDER', 'ROLE_CONSORTIUM' , 'ROLE_CONSORTIUM_ORGANIZATION', 'ROLE_ALLOCATOR', 'ROLE_ADMIN', 'ROLE_MEMBER', 'ROLE_DEV')", + ). + where(symbol: params[:id]). + first + else + @provider = + Provider.unscoped.where( + "allocator.role_name IN ('ROLE_FOR_PROFIT_PROVIDER', 'ROLE_CONTRACTUAL_PROVIDER', 'ROLE_CONSORTIUM' , 'ROLE_CONSORTIUM_ORGANIZATION', 'ROLE_ALLOCATOR', 'ROLE_ADMIN', 'ROLE_MEMBER', 'ROLE_DEV')", + ). + where(deleted_at: nil). + where(symbol: params[:id]). + first + end + fail ActiveRecord::RecordNotFound if @provider.blank? end diff --git a/app/controllers/v3/providers_controller.rb b/app/controllers/v3/providers_controller.rb index 9fcbdc097..8524c7d40 100644 --- a/app/controllers/v3/providers_controller.rb +++ b/app/controllers/v3/providers_controller.rb @@ -377,13 +377,23 @@ def set_include end def set_provider - @provider = - Provider.unscoped.where( - "allocator.role_name IN ('ROLE_FOR_PROFIT_PROVIDER', 'ROLE_CONTRACTUAL_PROVIDER', 'ROLE_CONSORTIUM' , 'ROLE_CONSORTIUM_ORGANIZATION', 'ROLE_ALLOCATOR', 'ROLE_ADMIN', 'ROLE_MEMBER', 'ROLE_DEV')", - ). - where(deleted_at: nil). - where(symbol: params[:id]). - first + if params[:include_deleted] + @provider = + Provider.unscoped.where( + "allocator.role_name IN ('ROLE_FOR_PROFIT_PROVIDER', 'ROLE_CONTRACTUAL_PROVIDER', 'ROLE_CONSORTIUM' , 'ROLE_CONSORTIUM_ORGANIZATION', 'ROLE_ALLOCATOR', 'ROLE_ADMIN', 'ROLE_MEMBER', 'ROLE_DEV')", + ). + where(symbol: params[:id]). + first + else + @provider = + Provider.unscoped.where( + "allocator.role_name IN ('ROLE_FOR_PROFIT_PROVIDER', 'ROLE_CONTRACTUAL_PROVIDER', 'ROLE_CONSORTIUM' , 'ROLE_CONSORTIUM_ORGANIZATION', 'ROLE_ALLOCATOR', 'ROLE_ADMIN', 'ROLE_MEMBER', 'ROLE_DEV')", + ). + where(deleted_at: nil). + where(symbol: params[:id]). + first + end + fail ActiveRecord::RecordNotFound if @provider.blank? end