Skip to content

Commit

Permalink
Merge branch 'develop' into y24-475-bug-improve-integration-suite-uat…
Browse files Browse the repository at this point in the history
…-actions-error-message
  • Loading branch information
yoldas committed Jan 14, 2025
2 parents c0c17aa + 6a728b5 commit 705af56
Show file tree
Hide file tree
Showing 17 changed files with 1,018 additions and 173 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22.11.0
22.13.0
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.5
3.3.6
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ARG CHIPSET=default

# Use the correct base image depending on the architecture
# For Apple M1 Chip, run: docker build --build-arg CHIPSET=m1 .
FROM ruby:3.2.5-slim AS base_default
FROM ruby:3.3.6-slim AS base_default
FROM --platform=linux/amd64 ruby:3.2.5-slim AS base_m1
FROM base_${CHIPSET} AS base

Expand Down
149 changes: 75 additions & 74 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,24 +196,24 @@ GEM
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
database_cleaner-core (2.0.1)
date (3.4.0)
delayed_job (4.1.11)
activesupport (>= 3.0, < 8.0)
delayed_job_active_record (4.1.8)
activerecord (>= 3.0, < 8.0)
date (3.4.1)
delayed_job (4.1.13)
activesupport (>= 3.0, < 9.0)
delayed_job_active_record (4.1.11)
activerecord (>= 3.0, < 9.0)
delayed_job (>= 3.0, < 5)
diff-lcs (1.5.1)
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)
factory_bot (6.4.6)
factory_bot (6.5.0)
activesupport (>= 5.0.0)
factory_bot_rails (6.4.3)
factory_bot (~> 6.4)
factory_bot_rails (6.4.4)
factory_bot (~> 6.5)
railties (>= 5.0.0)
ffi (1.16.3)
flipper (0.25.4)
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 @@ -454,7 +454,7 @@ GEM
rubocop-rspec (~> 3, >= 3.0.1)
ruby-graphviz (1.2.5)
rexml
ruby-prof (1.7.0)
ruby-prof (1.7.1)
ruby-progressbar (1.13.0)
ruby-units (4.0.3)
ruby-vips (2.2.1)
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
Loading

0 comments on commit 705af56

Please sign in to comment.