lib/drillbit/authorizers/parameters/resource.rb in drillbit-2.7.0 vs lib/drillbit/authorizers/parameters/resource.rb in drillbit-2.8.0

- old
+ new

@@ -49,22 +49,40 @@ names.each do |name| add_authorized_attribute(name) end end - def add_authorized_relationship(name) - param = params. - fetch(:data, {}). - fetch(:relationships, {}). - fetch(name, {}). - fetch(:data, nil) + # rubocop:disable Metrics/AbcSize + def add_authorized_relationship(name, embedded_attributes: {}) + param = params. + fetch(:data, {}). + fetch(:relationships, {}). + fetch(name, {}). + fetch(:data, nil) + first = params. + fetch(:data, {}). + fetch(:relationships, {}). + fetch(name, {}). + fetch(:data, []). + first || {} + embedded = first.fetch(:attributes, nil) if param.nil? authorized_params[6][:data][2][:relationships][name] = [:data] + elsif embedded + authorized_params[6][:data][2][:relationships][name] = { + data: [ + :type, + { + attributes: %i{__id__} + embedded_attributes, + }, + ], + } else authorized_params[6][:data][2][:relationships][name] = { data: %i{type id} } end end + # rubocop:enable Metrics/AbcSize def add_authorized_relationships(*names) names.each do |name| add_authorized_relationship(name) end