Skip to content

Commit

Permalink
Merge branch 'develop' into develop-Y24-190
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/controllers/api/v2/tag_layouts_controller.rb
  • Loading branch information
sdjmchattie committed Jan 9, 2025
2 parents 073c786 + 7899d2f commit 72c68af
Show file tree
Hide file tree
Showing 26 changed files with 1,311 additions and 151 deletions.
133 changes: 67 additions & 66 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,72 +34,72 @@ GEM
specs:
aasm (5.5.0)
concurrent-ruby (~> 1.0)
actioncable (7.0.8.1)
actionpack (= 7.0.8.1)
activesupport (= 7.0.8.1)
actioncable (7.0.8.7)
actionpack (= 7.0.8.7)
activesupport (= 7.0.8.7)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.8.1)
actionpack (= 7.0.8.1)
activejob (= 7.0.8.1)
activerecord (= 7.0.8.1)
activestorage (= 7.0.8.1)
activesupport (= 7.0.8.1)
actionmailbox (7.0.8.7)
actionpack (= 7.0.8.7)
activejob (= 7.0.8.7)
activerecord (= 7.0.8.7)
activestorage (= 7.0.8.7)
activesupport (= 7.0.8.7)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.8.1)
actionpack (= 7.0.8.1)
actionview (= 7.0.8.1)
activejob (= 7.0.8.1)
activesupport (= 7.0.8.1)
actionmailer (7.0.8.7)
actionpack (= 7.0.8.7)
actionview (= 7.0.8.7)
activejob (= 7.0.8.7)
activesupport (= 7.0.8.7)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.8.1)
actionview (= 7.0.8.1)
activesupport (= 7.0.8.1)
actionpack (7.0.8.7)
actionview (= 7.0.8.7)
activesupport (= 7.0.8.7)
rack (~> 2.0, >= 2.2.4)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actionpack-xml_parser (2.0.1)
actionpack (>= 5.0)
railties (>= 5.0)
actiontext (7.0.8.1)
actionpack (= 7.0.8.1)
activerecord (= 7.0.8.1)
activestorage (= 7.0.8.1)
activesupport (= 7.0.8.1)
actiontext (7.0.8.7)
actionpack (= 7.0.8.7)
activerecord (= 7.0.8.7)
activestorage (= 7.0.8.7)
activesupport (= 7.0.8.7)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.8.1)
activesupport (= 7.0.8.1)
actionview (7.0.8.7)
activesupport (= 7.0.8.7)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.8.1)
activesupport (= 7.0.8.1)
activejob (7.0.8.7)
activesupport (= 7.0.8.7)
globalid (>= 0.3.6)
activemodel (7.0.8.1)
activesupport (= 7.0.8.1)
activerecord (7.0.8.1)
activemodel (= 7.0.8.1)
activesupport (= 7.0.8.1)
activemodel (7.0.8.7)
activesupport (= 7.0.8.7)
activerecord (7.0.8.7)
activemodel (= 7.0.8.7)
activesupport (= 7.0.8.7)
activerecord-import (1.7.0)
activerecord (>= 4.2)
activestorage (7.0.8.1)
actionpack (= 7.0.8.1)
activejob (= 7.0.8.1)
activerecord (= 7.0.8.1)
activesupport (= 7.0.8.1)
activestorage (7.0.8.7)
actionpack (= 7.0.8.7)
activejob (= 7.0.8.7)
activerecord (= 7.0.8.7)
activesupport (= 7.0.8.7)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.8.1)
activesupport (7.0.8.7)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand Down Expand Up @@ -196,7 +196,7 @@ GEM
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
date (3.4.0)
date (3.4.1)
delayed_job (4.1.11)
activesupport (>= 3.0, < 8.0)
delayed_job_active_record (4.1.8)
Expand All @@ -206,7 +206,7 @@ GEM
docile (1.4.0)
domain_name (0.6.20240107)
dry-cli (1.0.0)
erubi (1.13.0)
erubi (1.13.1)
exception_notification (4.5.0)
actionmailer (>= 5.2, < 8)
activesupport (>= 5.2, < 8)
Expand Down Expand Up @@ -257,7 +257,7 @@ GEM
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
logger (1.6.1)
loofah (2.23.1)
loofah (2.24.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mail (2.8.1)
Expand All @@ -273,7 +273,7 @@ GEM
mime-types-data (3.2024.0305)
mini_magick (4.12.0)
mini_mime (1.1.5)
minitest (5.25.1)
minitest (5.25.4)
minitest-profiler (0.0.2)
activesupport (>= 4.1.0)
minitest (>= 5.3.3)
Expand All @@ -285,7 +285,7 @@ GEM
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
mysql2 (0.5.6)
net-imap (0.5.1)
net-imap (0.5.5)
date
net-protocol
net-ldap (0.19.0)
Expand All @@ -297,11 +297,11 @@ GEM
net-protocol
netrc (0.11.0)
nio4r (2.7.4)
nokogiri (1.16.7-arm64-darwin)
nokogiri (1.18.1-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-darwin)
nokogiri (1.18.1-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
nokogiri (1.18.1-x86_64-linux-gnu)
racc (~> 1.4)
ostruct (0.6.0)
parallel (1.26.3)
Expand Down Expand Up @@ -334,22 +334,22 @@ GEM
rack (~> 2.2, >= 2.2.4)
rack-proxy (0.7.7)
rack
rack-test (2.1.0)
rack-test (2.2.0)
rack (>= 1.3)
rails (7.0.8.1)
actioncable (= 7.0.8.1)
actionmailbox (= 7.0.8.1)
actionmailer (= 7.0.8.1)
actionpack (= 7.0.8.1)
actiontext (= 7.0.8.1)
actionview (= 7.0.8.1)
activejob (= 7.0.8.1)
activemodel (= 7.0.8.1)
activerecord (= 7.0.8.1)
activestorage (= 7.0.8.1)
activesupport (= 7.0.8.1)
rails (7.0.8.7)
actioncable (= 7.0.8.7)
actionmailbox (= 7.0.8.7)
actionmailer (= 7.0.8.7)
actionpack (= 7.0.8.7)
actiontext (= 7.0.8.7)
actionview (= 7.0.8.7)
activejob (= 7.0.8.7)
activemodel (= 7.0.8.7)
activerecord (= 7.0.8.7)
activestorage (= 7.0.8.7)
activesupport (= 7.0.8.7)
bundler (>= 1.15.0)
railties (= 7.0.8.1)
railties (= 7.0.8.7)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
Expand All @@ -363,13 +363,13 @@ GEM
activesupport (>= 4.2)
choice (~> 0.2.0)
ruby-graphviz (~> 1.2)
rails-html-sanitizer (1.6.0)
rails-html-sanitizer (1.6.2)
loofah (~> 2.21)
nokogiri (~> 1.14)
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
rails-perftest (0.0.7)
railties (7.0.8.1)
actionpack (= 7.0.8.1)
activesupport (= 7.0.8.1)
railties (7.0.8.7)
actionpack (= 7.0.8.7)
activesupport (= 7.0.8.7)
method_source
rake (>= 12.2)
thor (~> 1.0)
Expand Down Expand Up @@ -515,7 +515,7 @@ GEM
thor (1.3.2)
tilt (2.4.0)
timecop (0.9.10)
timeout (0.4.2)
timeout (0.4.3)
traceroute (0.8.1)
rails (>= 3.0.0)
tzinfo (2.0.6)
Expand All @@ -535,7 +535,8 @@ GEM
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
websocket (1.2.11)
websocket-driver (0.7.6)
websocket-driver (0.7.7)
base64
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
whenever (1.0.0)
Expand Down
77 changes: 77 additions & 0 deletions app/controllers/api/v2/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,82 @@ class OrdersController < JSONAPI::ResourceController
# By default JSONAPI::ResourceController provides most the standard
# behaviour, and in many cases this file may be left empty.
end

class OrderProcessor < JSONAPI::Processor
before_create_resource :prepare_context

private

def prepare_context
context[:template] = find_template
context[:template_attributes] = template_attributes unless context[:template].nil?
end

def find_template
template_uuid = params[:data][:attributes][:submission_template_uuid]
return nil if template_uuid.nil? # No errors -- we just don't have a template.

template = SubmissionTemplate.with_uuid(template_uuid).first
raise JSONAPI::Exceptions::InvalidFieldValue.new(:submission_template_uuid, template_uuid) if template.nil?

template
end

def template_attributes
parameters = params[:data][:attributes][:submission_template_attributes]

raise JSONAPI::Exceptions::ParameterMissing, :submission_template_attributes if parameters.nil?

make_template_attributes(permitted_attributes(parameters))
end

def permitted_attributes(attributes)
attributes.permit(
{ asset_uuids: [], request_options: {} },
:autodetect_projects,
:autodetect_studies,
:user_uuid
)
end

def make_template_attributes(attributes)
{
assets: extract_assets(attributes),
autodetect_projects: attributes[:autodetect_projects],
autodetect_studies: attributes[:autodetect_studies],
request_options: require_attribute(attributes, :request_options),
user: extract_user(attributes)
}.compact
end

def extract_assets(attributes)
asset_uuids = require_attribute(attributes, :asset_uuids)
return nil if asset_uuids.nil?

asset_uuids.map do |uuid|
uuid_obj = Uuid.find_by(external_id: uuid)
raise JSONAPI::Exceptions::InvalidFieldValue.new(:asset_uuids, uuid) if uuid_obj.nil?
uuid_obj&.resource
end
end

def extract_user(attributes)
user_uuid = require_attribute(attributes, :user_uuid)
return nil if user_uuid.nil?

user = User.with_uuid(user_uuid).first
raise JSONAPI::Exceptions::InvalidFieldValue.new(:user_uuid, user_uuid) if user.nil?

user
end

def require_attribute(attributes, key)
value = attributes.require(key)
value = value.to_h if value.instance_of?(ActionController::Parameters) && value.permitted?
value
rescue ActionController::ParameterMissing
raise JSONAPI::Exceptions::ParameterMissing, "submission_template_attributes.#{key}"
end
end
end
end
1 change: 1 addition & 0 deletions app/controllers/samples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def default_permitted_metadata_fields
subject
treatment
donor_id
huMFre_code
]
}
end
Expand Down
1 change: 1 addition & 0 deletions app/models/api/sample_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def json_root
map_attribute_to_json_attribute(:treatment)
map_attribute_to_json_attribute(:date_of_consent_withdrawn)
map_attribute_to_json_attribute(:user_id_of_consent_withdrawn, 'marked_as_consent_withdrawn_by')
map_attribute_to_json_attribute(:huMFre_code)
end

extra_json_attributes do |_object, json_attributes|
Expand Down
3 changes: 3 additions & 0 deletions app/models/order_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
# If we remove this, then we break our API endpoints. Some of which, at least at one point, actually had
# external users.
OrderTemplate = SubmissionTemplate

# TODO: {API v1 removal} this alias was created for v1 and should not be in v2. When v1 is removed, we should try
# to remove this alias as well.
13 changes: 13 additions & 0 deletions app/models/sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class Current < ActiveSupport::CurrentAttributes
custom_attribute(:date_of_consent_withdrawn)
custom_attribute(:user_id_of_consent_withdrawn)

custom_attribute(:huMFre_code)

# These fields are warehoused, so need to match the encoding restrictions there
# This excludes supplementary characters, which include emoji and rare kanji
# @note phenotype isn't currently broadcast but has a field waiting in the warehouse
Expand Down Expand Up @@ -226,6 +228,17 @@ class Current < ActiveSupport::CurrentAttributes
# Sample::Metadata tracks sample information, either for use in the lab, or passing to
# the EBI
class Metadata
# HuMFre numbers contain tissue information, which is only relevant for human samples.
validates :huMFre_code,
length: {
maximum: 16
},
format: {
with: %r{\A(?:\d{2}/\d{2,}|\d{2}/\d{4}-\d{3})\z},
message: 'must match a valid format, e.g. 12/34 or 12/2023-001'
},
allow_blank: true

# This constraint doesn't match that described in the manifest, and is more permissive
# It was added on conversion of out database to utf8 to address concerns that this would
# lead to an increase in characters that their pipeline cannot process. Only a handful
Expand Down
1 change: 1 addition & 0 deletions app/resources/api/v2/base_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class BaseResource < JSONAPI::Resource
abstract

# Loaded on the base class so that they can be loaded globally.
Order.descendants.each { |subclass| model_hint model: subclass, resource: :order }
Purpose.descendants.each { |subclass| model_hint model: subclass, resource: :purpose }
Plate.descendants.each { |subclass| model_hint model: subclass, resource: :plate }
Tube.descendants.each { |subclass| model_hint model: subclass, resource: :tube }
Expand Down
Loading

0 comments on commit 72c68af

Please sign in to comment.