Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ursm authored and maimux2x committed Oct 15, 2024
1 parent 907d047 commit be3d616
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 2 deletions.
3 changes: 3 additions & 0 deletions api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ gem "rails", "~> 7.2.0"

gem "aws-sdk-s3"
gem "base62-rb"
gem "bcrypt_pbkdf"
gem "bootsnap", require: false
gem "ed25519"
gem "fetch-api"
gem "jb"
gem "json"
gem "metabobank_tools", github: "ddbj/metabobank_tools"
gem "net-ssh"
gem "noodles_gff", path: "../noodles_gff-rb"
gem "openid_connect"
gem "pagy"
Expand Down
7 changes: 7 additions & 0 deletions api/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ GEM
aws-eventstream (~> 1, >= 1.0.2)
base62-rb (0.3.1)
base64 (0.2.0)
bcrypt_pbkdf (1.1.1)
bcrypt_pbkdf (1.1.1-arm64-darwin)
bigdecimal (3.1.8)
bindata (2.5.0)
bootsnap (1.18.4)
Expand All @@ -141,6 +143,7 @@ GEM
reline (>= 0.3.8)
diff-lcs (1.5.1)
drb (2.2.1)
ed25519 (1.3.0)
email_validator (2.2.4)
activemodel
erubi (1.13.0)
Expand Down Expand Up @@ -218,6 +221,7 @@ GEM
timeout
net-smtp (0.5.0)
net-protocol
net-ssh (7.2.3)
nio4r (2.7.3)
nokogiri (1.16.7-aarch64-linux)
racc (~> 1.4)
Expand Down Expand Up @@ -427,15 +431,18 @@ PLATFORMS
DEPENDENCIES
aws-sdk-s3
base62-rb
bcrypt_pbkdf
bootsnap
brakeman
climate_control
debug
ed25519
factory_bot_rails
fetch-api
jb
json
metabobank_tools!
net-ssh
noodles_gff!
openid_connect
pagy
Expand Down
43 changes: 42 additions & 1 deletion api/app/models/database/dra/submitter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
class Database::DRA::Submitter
def submit(submission)
# do nothing
submitter_id = submission.validation.user.uid
user_id = SubmitterDB::Login.where(submitter_id:).pick(:usr_id)

DRMDB::Record.transaction isolation: Rails.env.test? ? nil : :serializable do
serial = (DRMDB::Submission.where(submitter_id:).maximum(:serial) || 0) + 1
submission_id = "#{submitter_id}-#{serial.to_s.rjust(4, '0')}"

submission = DRMDB::Submission.create!(
usr_id: user_id,
submitter_id:,
serial:,
create_date: Date.current
)

submission.status_histories.create!(
status: :new
)

DRMDB::OperationHistory.create!(
type: :info,
summary: "Status update to new",
usr_id: user_id,
serial:,
submitter_id:
)

DRMDB::ExtEntity.create!(
acc_type: :submission,
ref_name: submission_id,
status: :inputting
) do |entity|
entity.ext_permits.build(
submitter_id:
)
end

host, user, key_data = ENV.values_at("DRA_SSH_HOST", "DRA_SSH_USER", "DRA_SSH_KEY_DATA")

Net::SSH.start host, user, key_data: [ key_data ] do |ssh|
ssh.exec! "sudo /usr/local/sbin/chroot-createdir.sh #{submitter_id} #{submission_id}"
end
end
end
end
7 changes: 6 additions & 1 deletion api/app/models/drmdb/operation_history.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
class DRMDB::OperationHistory < DRMDB::Record
self.table_name = "operation_history"
self.table_name = "operation_history"
self.inheritance_column = nil

enum :type, {
info: 3
}
end
6 changes: 6 additions & 0 deletions api/app/models/drmdb/status_history.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
class DRMDB::StatusHistory < DRMDB::Record
self.table_name = "status_history"

belongs_to :submission, class_name: "DRMDB::Submission", foreign_key: "sub_id"

enum :status, {
new: 100
}, prefix: true
end
2 changes: 2 additions & 0 deletions api/app/models/drmdb/submission.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class DRMDB::Submission < DRMDB::Record
self.table_name = "submission"

has_many :status_histories, class_name: "DRMDB::StatusHistory", foreign_key: "sub_id"
end
5 changes: 5 additions & 0 deletions api/spec/factories/submitterdb_logins.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FactoryBot.define do
factory :submitterdb_login, class: 'SubmitterDB::Login' do
password { 'password' }
end
end
59 changes: 59 additions & 0 deletions api/spec/models/database/dra/submitter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
require 'rails_helper'

RSpec.describe Database::DRA::Submitter, type: :model do
example do
submission = create(:submission, {
validation: build(:validation, :valid, {
user: build(:user, uid: 'alice')
})
})

user_id = create(:submitterdb_login, **{
submitter_id: 'alice'
}).usr_id

expect(Net::SSH).to receive(:start)

Database::DRA::Submitter.new.submit submission

submission = DRMDB::Submission.sole

expect(submission).to have_attributes(
usr_id: user_id,
submitter_id: 'alice',
serial: 1
)

status_history = DRMDB::StatusHistory.sole

expect(status_history).to have_attributes(
sub_id: submission[:sub_id],
status: 'new'
)

operation_history = DRMDB::OperationHistory.sole

expect(operation_history).to have_attributes(
type: 'info',
summary: 'Status update to new',
usr_id: user_id,
serial: 1,
submitter_id: 'alice'
)

ext_entity = DRMDB::ExtEntity.sole

expect(ext_entity).to have_attributes(
acc_type: 'submission',
ref_name: 'alice-0001',
status: 'inputting'
)

ext_permit = DRMDB::ExtPermit.sole

expect(ext_permit).to have_attributes(
ext_id: ext_entity.ext_id,
submitter_id: 'alice'
)
end
end

0 comments on commit be3d616

Please sign in to comment.