From 53b8d6bd9e2839bd0a55f9f5fbcbdfd653378df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Hal=C3=A1sz?= Date: Mon, 13 Nov 2023 12:53:47 +0100 Subject: [PATCH] feat(APIv2): optionally allow the selection of additional fields --- app/controllers/v2/application_controller.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/controllers/v2/application_controller.rb b/app/controllers/v2/application_controller.rb index 0f8798cba..a996d2666 100644 --- a/app/controllers/v2/application_controller.rb +++ b/app/controllers/v2/application_controller.rb @@ -60,6 +60,8 @@ def rbac_allowed? def expand_resource # Get the list of fields to be selected from the serializer fields = serializer.fields(permitted_params[:parents], resource.one_to_one) + # Append a list of additional fields required to render the response, usually RBAC related + fields[nil] += extra_fields # Join with the parents assumed from the route scope = join_parents(pundit_scope, permitted_params[:parents]) @@ -107,5 +109,10 @@ def select_fields(fields) end end end + + # Default list of additional fields to be passed to the list of selected fields + def extra_fields + [] + end end end