Skip to content

Commit

Permalink
feat(APIv2): optionally allow the selection of additional fields
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman committed Nov 13, 2023
1 parent 49da51c commit 53b8d6b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/v2/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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

0 comments on commit 53b8d6b

Please sign in to comment.