-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4426 from sanger/Y24-190-fix-api-v2-transfers
Y24-190: Fix API v2 transfers
- Loading branch information
Showing
54 changed files
with
691 additions
and
877 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module Api | ||
module V2 | ||
# Provides a JSON API controller for Transfers. | ||
# See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation. | ||
class TransfersController < JSONAPI::ResourceController | ||
# By default JSONAPI::ResourceController provides most of the standard behaviour. | ||
# However in this case we want to redirect create and update operations to the correct polymorphic type. | ||
|
||
def process_operations(operations) | ||
# We need to determine the polymorphic type of the transfer to create based on any template provided. | ||
operations.each do |operation| | ||
# Neither data nor attributes are guaranteed among the operation options. | ||
attributes = operation.options.fetch(:data, {}).fetch(:attributes, {}) | ||
|
||
# Skip the operation if it does not contain a transfer template. | ||
next unless attributes.key?(:transfer_template_uuid) | ||
|
||
# Get the transfer template and use it to update the context and attributes. | ||
template = TransferTemplate.with_uuid(attributes[:transfer_template_uuid]).first | ||
operation.options[:context][:polymorphic_type] = template.transfer_class_name | ||
attributes[:transfers] = template.transfers if template.transfers.present? | ||
|
||
# Remove the UUID of the transfer template from the attributes. | ||
attributes.delete(:transfer_template_uuid) | ||
end | ||
|
||
super(operations) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.