From 5dbddfba6e27a9422f8e36877d81e5706b20a9a5 Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Thu, 12 Dec 2024 11:33:32 +0000 Subject: [PATCH 1/7] Make TagLayoutProcessor use callbacks instead of overriding create_resource --- .../api/v2/tag_layouts_controller.rb | 76 +++++++++---------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/app/controllers/api/v2/tag_layouts_controller.rb b/app/controllers/api/v2/tag_layouts_controller.rb index bc2472640e..6e76e1d20c 100644 --- a/app/controllers/api/v2/tag_layouts_controller.rb +++ b/app/controllers/api/v2/tag_layouts_controller.rb @@ -10,25 +10,38 @@ class TagLayoutsController < JSONAPI::ResourceController end class TagLayoutProcessor < JSONAPI::Processor + around_create_resource :apply_template + + private + + # We need to check whether a template UUID was given, and, if so, copy its data into this + # new TagLayoutResource. The creation will be prevented if any data from the template is also + # included in the create request as additional values. e.g. a request has a template UUID and + # also specifies a direction or a tag_group. In this case, the error will indicate that the + # template UUID was not an allowed attribute. + def apply_template + template = merge_template_data + yield + record_template_use(template) unless template.nil? + end + def find_template template_uuid = params[:data][:attributes][:tag_layout_template_uuid] return nil if template_uuid.nil? # No errors -- we just don't have a template. template = TagLayoutTemplate.with_uuid(template_uuid).first - if template.nil? - yield JSONAPI::Exceptions::InvalidFieldValue.new(:tag_layout_template_uuid, template_uuid).errors - end + raise JSONAPI::Exceptions::InvalidFieldValue.new(:tag_layout_template_uuid, template_uuid) if template.nil? template end - def errors_if_key_present(data, key) - return [] if data[key.to_sym].blank? - - JSONAPI::Exceptions::BadRequest.new( - "Cannot provide '#{key}' while also providing 'tag_layout_template_uuid'." - ).errors + def raise_if_key_present(data, key) + unless data[key.to_sym].blank? + raise JSONAPI::Exceptions::BadRequest.new( + "Cannot provide '#{key}' while also providing 'tag_layout_template_uuid'." + ) + end end def merge_template_attributes(template) @@ -37,7 +50,7 @@ def merge_template_attributes(template) %i[walking_by direction].each do |attr_key| next if template.send(attr_key).blank? - yield errors_if_key_present(data[:attributes], attr_key) + raise_if_key_present(data[:attributes], attr_key) data[:attributes][attr_key] = template.send(attr_key) end @@ -49,16 +62,22 @@ def merge_template_to_one_relationships(template) %i[tag_group tag2_group].each do |rel_key| next if template.send(rel_key).blank? - yield errors_if_key_present(data[:attributes], "#{rel_key}_uuid") - yield errors_if_key_present(data[:to_one], rel_key) + raise_if_key_present(data[:attributes], "#{rel_key}_uuid") + raise_if_key_present(data[:to_one], rel_key) data[:to_one][rel_key] = template.send(rel_key).id end end - def merge_template_data(template, &) - merge_template_attributes(template, &) - merge_template_to_one_relationships(template, &) + def merge_template_data + template = find_template + + unless template.nil? + merge_template_attributes(template) + merge_template_to_one_relationships(template) + end + + template end def enforce_uniqueness? @@ -69,30 +88,9 @@ def enforce_uniqueness? attributes.fetch(:enforce_uniqueness, tag2_group_present) end - def record_template_use(template, resource) - template&.record_template_use(TagLayout.find(resource.id).plate, enforce_uniqueness?) - end - - # Override the default behaviour for a JSONAPI::Processor when creating a new resource. - # We need to check whether a template UUID was given, and, if so, copy its data into this - # new TagLayoutResource. The creation will be prevented if any data from the template is also - # included in the create request as additional values. e.g. a request has a template UUID and - # also specifies a direction or a tag_group. In this case, the error will indicate that the - # template UUID was not an allowed attribute. - def create_resource - errors = [] - template = find_template { |new_errors| errors += new_errors } - merge_template_data(template) { |new_errors| errors += new_errors } unless template.nil? - - return JSONAPI::ErrorsOperationResult.new(JSONAPI::BAD_REQUEST, errors) unless errors.empty? - - # Perform the usual create actions. - resource = TagLayoutResource.create(context) - result = resource.replace_fields(params[:data]) - - record_template_use(template, resource) - - JSONAPI::ResourceOperationResult.new((result == :completed ? :created : :accepted), resource) + def record_template_use(template) + plate = Plate.with_uuid(params.dig(:data, :attributes, :plate_uuid)).first + template.record_template_use(plate, enforce_uniqueness?) end end end From e06ecce912adfe0966d274c715e9050c2dc591c2 Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Mon, 16 Dec 2024 10:36:32 +0000 Subject: [PATCH 2/7] Reduce the complexity of TransferProcessor Make some of the logic exist in the resource and don't gather errors in an array when they can be raised immediately --- .../api/v2/transfers_controller.rb | 35 +++++-------------- app/resources/api/v2/transfer_resource.rb | 31 ++++++---------- .../api/v2/transfer_resource_spec.rb | 8 ++--- 3 files changed, 22 insertions(+), 52 deletions(-) diff --git a/app/controllers/api/v2/transfers_controller.rb b/app/controllers/api/v2/transfers_controller.rb index 9b35095fab..5db526e08d 100644 --- a/app/controllers/api/v2/transfers_controller.rb +++ b/app/controllers/api/v2/transfers_controller.rb @@ -10,40 +10,21 @@ class TransfersController < JSONAPI::ResourceController end class TransferProcessor < JSONAPI::Processor - # Get the Transfer model type needed to be created from the transfer template in the attributes. - # Also put the transfers from the template into the attributes if they exist. - def extract_template_data(attributes) - errors = [] + before_create_resource :extract_template_data + # Put the Transfer model_type needed to be created from the transfer template in the context. + # Also put the transfers from the template into the attributes if they exist. + def extract_template_data + attributes = params[:data][:attributes] template_uuid = attributes[:transfer_template_uuid] - errors += JSONAPI::Exceptions::ParameterMissing.new('transfer_template_uuid').errors if template_uuid.nil? + raise JSONAPI::Exceptions::ParameterMissing.new('transfer_template_uuid') if template_uuid.nil? template = TransferTemplate.with_uuid(template_uuid).first - errors += - JSONAPI::Exceptions::InvalidFieldValue.new('transfer_template_uuid', template_uuid).errors if template.nil? - - return nil, errors if errors.present? + raise JSONAPI::Exceptions::InvalidFieldValue.new('transfer_template_uuid', template_uuid) if template.nil? # Modify attributes according to what we've found in the template. attributes[:transfers] = template.transfers if template.transfers.present? - - [template.transfer_class_name.constantize, errors] - end - - # Override the default behaviour for a JSONAPI::Processor when creating a new resource. - # We need to parse for a transfer_template_uuid attribute so that it can be used to determine the polymorphic - # type of the Transfer represented by a template. The create method is then passed the type to create. - def create_resource - data = params[:data] - attributes = data[:attributes] - model_type, errors = extract_template_data(attributes) - - return JSONAPI::ErrorsOperationResult.new(JSONAPI::BAD_REQUEST, errors) unless errors.empty? - - resource = TransferResource.create_with_model(context, model_type) - result = resource.replace_fields(data) - - JSONAPI::ResourceOperationResult.new((result == :completed ? :created : :accepted), resource) + context[:model_type] = template.transfer_class_name.constantize end end end diff --git a/app/resources/api/v2/transfer_resource.rb b/app/resources/api/v2/transfer_resource.rb index fa907c7b5c..bbf4fa16cf 100644 --- a/app/resources/api/v2/transfer_resource.rb +++ b/app/resources/api/v2/transfer_resource.rb @@ -72,17 +72,6 @@ def transfers=(transfers) end end - # @!attribute [w] transfer_template_uuid - # @return [String] the UUID of a TransferTemplate to create a transfer from. - # This must be provided or the Transfer creation will raise an error. - attribute :transfer_template_uuid, writeonly: true - - def transfer_template_uuid=(uuid) - # Do not update the model. - # This value is used by the controller to create the correct Transfer type and set the transfers attribute. - # It is not stored on the Transfer model. - end - # @!attribute [r] transfer_type # @return [String] The STI type of the transfer. attribute :transfer_type, delegate: :sti_type, readonly: true @@ -150,18 +139,18 @@ def user_uuid=(uuid) filter :transfer_type, apply: ->(records, value, _options) { records.where(sti_type: value) } ### - # Create method + # Custom Methods for Creation ### - # @!method create_with_model - # Create a new Transfer resource with the polymorphic type extracted from a template. This is called by the - # controller when a create request for a Transfer is made. - # @param context [Hash] The context for the request. - # @param model_type [Class] The polymorphic type of the Transfer model to create. - # @return [TransferResource] The new Transfer resource. - def self.create_with_model(context, model_type) - # Create the polymorphic type, not the base class. - new(model_type.new, context) + # @!attribute [w] transfer_template_uuid + # @note This is a required field. + # @param value [String] the UUID of a TransferTemplate to create a transfer from. + # @return [Void] + attribute :transfer_template_uuid, writeonly: true + attr_writer :transfer_template_uuid # This isn't stored, it is consumed by the transfers_controller. + + def self.create(context) + new(context[:model_type].new, context) end end end diff --git a/spec/resources/api/v2/transfer_resource_spec.rb b/spec/resources/api/v2/transfer_resource_spec.rb index 08df1c0be9..9a3e8df831 100644 --- a/spec/resources/api/v2/transfer_resource_spec.rb +++ b/spec/resources/api/v2/transfer_resource_spec.rb @@ -29,15 +29,15 @@ it { is_expected.to filter(:transfer_type) } # Custom methods - describe '#self.create_with_model' do - let(:context) { {} } + describe '#self.create' do let(:model_type) { Transfer::BetweenPlates } + let(:context) { { model_type: } } let(:transfer) { model_type.new } before { allow(model_type).to receive(:new).and_return(transfer) } it 'creates the new Transfer resource with the correct model class' do - described_class.create_with_model(context, model_type) + described_class.create(context) expect(model_type).to have_received(:new) end @@ -45,7 +45,7 @@ it 'creates the new resource with the new Transfer::BetweenPlates' do allow(described_class).to receive(:new).and_call_original - described_class.create_with_model(context, model_type) + described_class.create(context) expect(described_class).to have_received(:new).with(transfer, context) end From 40ab30b12dbec8b80a48711469bcb652a1565699 Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Mon, 16 Dec 2024 11:36:10 +0000 Subject: [PATCH 3/7] Mark which methods are private in the TransferProcessor --- app/controllers/api/v2/transfers_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/api/v2/transfers_controller.rb b/app/controllers/api/v2/transfers_controller.rb index 5db526e08d..12f9614a60 100644 --- a/app/controllers/api/v2/transfers_controller.rb +++ b/app/controllers/api/v2/transfers_controller.rb @@ -12,6 +12,8 @@ class TransfersController < JSONAPI::ResourceController class TransferProcessor < JSONAPI::Processor before_create_resource :extract_template_data + private + # Put the Transfer model_type needed to be created from the transfer template in the context. # Also put the transfers from the template into the attributes if they exist. def extract_template_data From 9430bc59976abd56434defc306a61b7a93df8658 Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Mon, 16 Dec 2024 11:36:38 +0000 Subject: [PATCH 4/7] Move template associated attributes into a block in the TagLayoutResource --- app/resources/api/v2/tag_layout_resource.rb | 44 ++++++++++----------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/app/resources/api/v2/tag_layout_resource.rb b/app/resources/api/v2/tag_layout_resource.rb index 86dc987385..d207dc2103 100644 --- a/app/resources/api/v2/tag_layout_resource.rb +++ b/app/resources/api/v2/tag_layout_resource.rb @@ -25,17 +25,6 @@ class TagLayoutResource < BaseResource # @note This attribute is required. attribute :direction - # @!attribute [w] enforce_uniqueness - # A flag indicating whether to set `enforce_uniqueness` on {TagLayout::TemplateSubmission}s when a template is - # used to create the TagLayout. - # @param value [Boolean] Whether to enforce uniqueness within template submissions. - attribute :enforce_uniqueness, writeonly: true - - def enforce_uniqueness=(value) - # Do not update the model. - # This value is used by the controller if a template UUID was given and is not used by the TagLayout directly. - end - # @!attribute [rw] initial_tag # An offset for the tag set indicating which tag to start with in the layout. # @return [Integer] @@ -94,18 +83,6 @@ def tag2_group_uuid=(value) @model.tag2_group = TagGroup.with_uuid(value).first end - # @!attribute [w] tag_layout_template_uuid - # @param value [String] the UUID of a TagLayoutTemplate to use for attributes of this TagLayout resource. - # Providing this UUID while also providing values for attributes and relationships which can be extracted from - # a {TagLayoutTemplateResource} will generate an error indicating that the UUID should not have been provided. - attribute :tag_layout_template_uuid, writeonly: true - - def tag_layout_template_uuid=(value) - # Do not update the model. - # This value is used by the controller to apply request data to the TagLayout from the indicated template. - # It is not stored on the Transfer model. - end - # @!attribute [rw] tags_per_well # The number of tags in each well. # This is only used and/or returned by specific tag layout {walking_by} algorithms. @@ -165,6 +142,27 @@ def user_uuid=(value) # @return [Api::V2::UserResource] The user who initiated this state change. # @note This relationship is required. has_one :user + + ### + # Template attributes + ### + + # These are consumed by the TagLayoutProcessor and not a concern of the resource. + # They are included here to allow their presence in the JSON:API request body and to document their use cases. + + # @!attribute [w] tag_layout_template_uuid + # @param value [String] the UUID of a TagLayoutTemplate to use for attributes of this TagLayout resource. + # Providing this UUID while also providing values for attributes and relationships which can be extracted from + # a {TagLayoutTemplateResource} will generate an error indicating that the UUID should not have been provided. + attribute :tag_layout_template_uuid, writeonly: true + attr_writer :tag_layout_template_uuid # Not stored on the model + + # @!attribute [w] enforce_uniqueness + # A flag indicating whether to set `enforce_uniqueness` on {TagLayout::TemplateSubmission}s when a template is + # used to create the TagLayout. + # @param value [Boolean] Whether to enforce uniqueness within template submissions. + attribute :enforce_uniqueness, writeonly: true + attr_writer :enforce_uniqueness # Not stored on the model end end end From 76f52511b56ba8bba76c765990465dd7910709f5 Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Mon, 16 Dec 2024 11:38:01 +0000 Subject: [PATCH 5/7] Use the context to pass QcFile information to the default self.create method --- app/controllers/api/v2/qc_files_controller.rb | 41 ++++++--------- app/resources/api/v2/qc_file_resource.rb | 52 ++++++++----------- .../resources/api/v2/qc_file_resource_spec.rb | 8 +-- 3 files changed, 42 insertions(+), 59 deletions(-) diff --git a/app/controllers/api/v2/qc_files_controller.rb b/app/controllers/api/v2/qc_files_controller.rb index 357fdc0e62..81f6443ddf 100644 --- a/app/controllers/api/v2/qc_files_controller.rb +++ b/app/controllers/api/v2/qc_files_controller.rb @@ -10,21 +10,32 @@ class QcFilesController < JSONAPI::ResourceController end class QcFileProcessor < JSONAPI::Processor + before_create_resource :prepare_temporary_file + + private + + def prepare_temporary_file + filename, contents = get_required_attributes + tempfile = create_temporary_file(filename, contents) + + context.merge!(filename:, tempfile:) + end + # Validate that attributes contains both the filename and the contents of the QcFile. - def validate_required_attributes(attributes) - errors = [] + def get_required_attributes + attributes = params[:data][:attributes] filename = attributes[:filename] - errors += JSONAPI::Exceptions::ParameterMissing.new('filename').errors if filename.nil? + raise JSONAPI::Exceptions::ParameterMissing.new('filename') if filename.nil? contents = attributes[:contents] - errors += JSONAPI::Exceptions::ParameterMissing.new('contents').errors if contents.nil? + raise JSONAPI::Exceptions::ParameterMissing.new('contents') if contents.nil? - [filename, contents, errors] + [filename, contents] end # Create a temporary file with the contents. - def create_tempfile(filename, contents) + def create_temporary_file(filename, contents) # The filename for a Tempfile is passed as an array with the basename and extension. # e.g. [ 'file', '.csv' ] filename_components = [File.basename(filename, '.*'), File.extname(filename)] @@ -33,24 +44,6 @@ def create_tempfile(filename, contents) return file end end - - # Override the default behaviour for a JSONAPI::Processor when creating a new resource. - # We need to parse the filename and contents attributes so that we can generate a temporary file for the new - # QcFile model object. Replacing the fields with these values after the new QcFile was created does not generate - # the file correctly in the database. The CarrierWave library needs these values sooner. - def create_resource - data = params[:data] - attributes = data[:attributes] - filename, contents, errors = validate_required_attributes(attributes) - - return JSONAPI::ErrorsOperationResult.new(JSONAPI::BAD_REQUEST, errors) unless errors.empty? - - tempfile = create_tempfile(filename, contents) - resource = QcFileResource.create_with_tempfile(context, tempfile, filename) - result = resource.replace_fields(data) - - JSONAPI::ResourceOperationResult.new((result == :completed ? :created : :accepted), resource) - end end end end diff --git a/app/resources/api/v2/qc_file_resource.rb b/app/resources/api/v2/qc_file_resource.rb index 4aacc3fed3..e21a51193e 100644 --- a/app/resources/api/v2/qc_file_resource.rb +++ b/app/resources/api/v2/qc_file_resource.rb @@ -49,36 +49,10 @@ class QcFileResource < BaseResource # @return [String] The content type, or MIME type, of the QC file. attribute :content_type, readonly: true - # @!attribute [rw] contents - # @return [String] The String contents of the QC file. - # This is usually the CSV data for the QC file. - # This can only be written once on creation. - attribute :contents, write_once: true - - def contents - # The contents comes from the uploaded_data managed by CarrierWave. - @model.current_data - end - - def contents=(value) - # Do not update the model. - # File contents is set via the uploaded_data hash supplied during QcFile creation. - end - # @!attribute [r] created_at # @return [DateTime] The date and time the QC file was created. attribute :created_at, readonly: true - # @!attribute [rw] filename - # @return [String] The filename of the QC file. - # This can only be written once on creation. - attribute :filename, write_once: true - - def filename=(value) - # Do not update the model. - # Filename is set via the uploaded_data hash supplied during QcFile creation. - end - # @!attribute [r] size # @return [Integer] The size of the QC file in bytes. attribute :size, readonly: true @@ -109,16 +83,32 @@ def filename=(value) # Create method ### - # @!method create_with_tempfile + # @!attribute [rw] contents + # @return [String] The String contents of the QC file. + # This is usually the CSV data for the QC file. + # This can only be written once on creation. + attribute :contents, write_once: true + attr_writer :contents # Do not store the value on the model. It is stored by the CarrierWave gem via a Tempfile. + + def contents + # The contents comes from the uploaded_data managed by CarrierWave. + @model.current_data + end + + # @!attribute [rw] filename + # @return [String] The filename of the QC file. + # This can only be written once on creation. + attribute :filename, write_once: true + attr_writer :filename # Do not store the value on the model. This value is consumed by the QcFileProcessor. + + # @!method self.create # Create a new QcFile resource with the uploaded data from a temporary file. This is called by the controller # when a create request for a QcFile is made. It ensures the contents of the file have been written to a # new TempFile instance. # @param context [Hash] The context for the request. - # @param tempfile [Tempfile] A temporary file containing the uploaded data. - # @param filename [String] The filename for the uploaded data. # @return [QcFileResource] The new QcFile resource. - def self.create_with_tempfile(context, tempfile, filename) - opts = { uploaded_data: { tempfile:, filename: } } + def self.create(context) + opts = { uploaded_data: context.slice(:filename, :tempfile) } new(QcFile.new(opts), context) end end diff --git a/spec/resources/api/v2/qc_file_resource_spec.rb b/spec/resources/api/v2/qc_file_resource_spec.rb index e3b9c71596..fe3d81ecc8 100644 --- a/spec/resources/api/v2/qc_file_resource_spec.rb +++ b/spec/resources/api/v2/qc_file_resource_spec.rb @@ -26,16 +26,16 @@ it { is_expected.to filter(:uuid) } # Custom methods - describe '#self.create_with_tempfile' do - let(:context) { {} } + describe '#self.create' do let(:tempfile) { Tempfile.new } let(:filename) { 'filename' } + let(:context) { { tempfile:, filename: } } let(:qc_file) { QcFile.new } it 'creates the new QcFile with uploaded_data' do allow(QcFile).to receive(:new).and_call_original - described_class.create_with_tempfile(context, tempfile, filename) + described_class.create(context) expect(QcFile).to have_received(:new).with({ uploaded_data: { tempfile:, filename: } }) end @@ -44,7 +44,7 @@ allow(QcFile).to receive(:new).and_return(qc_file) allow(described_class).to receive(:new).and_call_original - described_class.create_with_tempfile(context, tempfile, filename) + described_class.create(context) expect(described_class).to have_received(:new).with(qc_file, context) end From 653d03b1d5f7c78394cbabd683e45fed7c5e363b Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Mon, 16 Dec 2024 11:46:18 +0000 Subject: [PATCH 6/7] Fix Rubocop issues --- app/controllers/api/v2/qc_files_controller.rb | 8 ++++---- app/controllers/api/v2/tag_layouts_controller.rb | 9 ++++----- app/controllers/api/v2/transfers_controller.rb | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/controllers/api/v2/qc_files_controller.rb b/app/controllers/api/v2/qc_files_controller.rb index 81f6443ddf..22c475b04f 100644 --- a/app/controllers/api/v2/qc_files_controller.rb +++ b/app/controllers/api/v2/qc_files_controller.rb @@ -15,21 +15,21 @@ class QcFileProcessor < JSONAPI::Processor private def prepare_temporary_file - filename, contents = get_required_attributes + filename, contents = required_attributes tempfile = create_temporary_file(filename, contents) context.merge!(filename:, tempfile:) end # Validate that attributes contains both the filename and the contents of the QcFile. - def get_required_attributes + def required_attributes attributes = params[:data][:attributes] filename = attributes[:filename] - raise JSONAPI::Exceptions::ParameterMissing.new('filename') if filename.nil? + raise JSONAPI::Exceptions::ParameterMissing, 'filename' if filename.nil? contents = attributes[:contents] - raise JSONAPI::Exceptions::ParameterMissing.new('contents') if contents.nil? + raise JSONAPI::Exceptions::ParameterMissing, 'contents' if contents.nil? [filename, contents] end diff --git a/app/controllers/api/v2/tag_layouts_controller.rb b/app/controllers/api/v2/tag_layouts_controller.rb index 6e76e1d20c..ca41e0525c 100644 --- a/app/controllers/api/v2/tag_layouts_controller.rb +++ b/app/controllers/api/v2/tag_layouts_controller.rb @@ -37,11 +37,10 @@ def find_template end def raise_if_key_present(data, key) - unless data[key.to_sym].blank? - raise JSONAPI::Exceptions::BadRequest.new( - "Cannot provide '#{key}' while also providing 'tag_layout_template_uuid'." - ) - end + return if data[key.to_sym].blank? + + raise JSONAPI::Exceptions::BadRequest, + "Cannot provide '#{key}' while also providing 'tag_layout_template_uuid'." end def merge_template_attributes(template) diff --git a/app/controllers/api/v2/transfers_controller.rb b/app/controllers/api/v2/transfers_controller.rb index 12f9614a60..8c135f0e15 100644 --- a/app/controllers/api/v2/transfers_controller.rb +++ b/app/controllers/api/v2/transfers_controller.rb @@ -19,7 +19,7 @@ class TransferProcessor < JSONAPI::Processor def extract_template_data attributes = params[:data][:attributes] template_uuid = attributes[:transfer_template_uuid] - raise JSONAPI::Exceptions::ParameterMissing.new('transfer_template_uuid') if template_uuid.nil? + raise JSONAPI::Exceptions::ParameterMissing, 'transfer_template_uuid' if template_uuid.nil? template = TransferTemplate.with_uuid(template_uuid).first raise JSONAPI::Exceptions::InvalidFieldValue.new('transfer_template_uuid', template_uuid) if template.nil? From eade045965fcb940a5ead6331b0b987495e1a892 Mon Sep 17 00:00:00 2001 From: Stuart McHattie Date: Mon, 16 Dec 2024 11:51:58 +0000 Subject: [PATCH 7/7] Remove the unnecessary documentation of the self.create method --- app/resources/api/v2/qc_file_resource.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/resources/api/v2/qc_file_resource.rb b/app/resources/api/v2/qc_file_resource.rb index e21a51193e..e0f6ce31e2 100644 --- a/app/resources/api/v2/qc_file_resource.rb +++ b/app/resources/api/v2/qc_file_resource.rb @@ -101,12 +101,6 @@ def contents attribute :filename, write_once: true attr_writer :filename # Do not store the value on the model. This value is consumed by the QcFileProcessor. - # @!method self.create - # Create a new QcFile resource with the uploaded data from a temporary file. This is called by the controller - # when a create request for a QcFile is made. It ensures the contents of the file have been written to a - # new TempFile instance. - # @param context [Hash] The context for the request. - # @return [QcFileResource] The new QcFile resource. def self.create(context) opts = { uploaded_data: context.slice(:filename, :tempfile) } new(QcFile.new(opts), context)