Skip to content

Commit

Permalink
add proforma_version to account_link
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoehn committed Aug 9, 2024
1 parent 649662b commit fa49748
Show file tree
Hide file tree
Showing 21 changed files with 158 additions and 60 deletions.
37 changes: 19 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ GEM
bindex (0.8.1)
binding_of_caller (1.0.1)
debug_inspector (>= 1.2.0)
bootsnap (1.18.3)
bootsnap (1.18.4)
msgpack (~> 1.2)
bootstrap-will_paginate (1.0.0)
will_paginate
Expand Down Expand Up @@ -163,12 +163,12 @@ GEM
factory_bot_rails (6.4.3)
factory_bot (~> 6.4)
railties (>= 5.0.0)
faraday (2.10.0)
faraday (2.10.1)
faraday-net_http (>= 2.0, < 3.2)
logger
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (3.1.0)
faraday-net_http (3.1.1)
net-http
ffi (1.17.0)
fugit (1.11.0)
Expand Down Expand Up @@ -198,7 +198,7 @@ GEM
rails-i18n
rainbow (>= 2.2.2, < 4.0)
terminal-table (>= 1.5.1)
image_processing (1.12.2)
image_processing (1.13.0)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
io-console (0.7.2)
Expand Down Expand Up @@ -285,7 +285,7 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.3)
nokogiri (1.16.6)
nokogiri (1.16.7)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
omniauth (2.1.2)
Expand All @@ -304,7 +304,7 @@ GEM
parser (3.3.4.0)
ast (~> 2.4.1)
racc
pg (1.5.6)
pg (1.5.7)
proformaxml (1.5.0)
activemodel (>= 5.2.3, < 8.0.0)
activesupport (>= 5.2.3, < 8.0.0)
Expand Down Expand Up @@ -332,7 +332,7 @@ GEM
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
raabro (1.4.0)
racc (1.8.0)
racc (1.8.1)
rack (3.1.7)
rack-mini-profiler (3.3.1)
rack (>= 1.2.0)
Expand Down Expand Up @@ -408,7 +408,7 @@ GEM
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.3.2)
rexml (3.3.4)
strscan
rouge (4.3.0)
rqrcode (2.2.0)
Expand Down Expand Up @@ -436,7 +436,7 @@ GEM
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rubocop (1.65.0)
rubocop (1.65.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand All @@ -447,7 +447,7 @@ GEM
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
rubocop-ast (1.32.0)
parser (>= 3.3.1.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
Expand All @@ -461,7 +461,7 @@ GEM
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rspec (3.0.3)
rubocop-rspec (3.0.4)
rubocop (~> 1.61)
rubocop-rspec_rails (2.30.0)
rubocop (~> 1.61)
Expand All @@ -474,8 +474,9 @@ GEM
ruby-saml (1.16.0)
nokogiri (>= 1.13.10)
rexml
ruby-vips (2.2.1)
ruby-vips (2.2.2)
ffi (~> 1.12)
logger
rubyzip (2.3.2)
sassc (2.4.0)
ffi (~> 1.9)
Expand All @@ -492,10 +493,10 @@ GEM
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
semantic_range (3.0.0)
sentry-rails (5.18.1)
sentry-rails (5.18.2)
railties (>= 5.0)
sentry-ruby (~> 5.18.1)
sentry-ruby (5.18.1)
sentry-ruby (~> 5.18.2)
sentry-ruby (5.18.2)
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
set (1.1.0)
Expand Down Expand Up @@ -527,7 +528,7 @@ GEM
slim_lint (0.27.0)
rubocop (>= 1.0, < 2.0)
slim (>= 3.0, < 6.0)
solid_queue (0.3.3)
solid_queue (0.4.1)
activejob (>= 7.1)
activerecord (>= 7.1)
concurrent-ruby (>= 1.3.1)
Expand All @@ -539,7 +540,7 @@ GEM
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.5.1)
sprockets-rails (3.5.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
Expand Down Expand Up @@ -586,7 +587,7 @@ GEM
will_paginate (4.0.1)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.16)
zeitwerk (2.6.17)

PLATFORMS
ruby
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/account_links_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ def set_user

# Never trust parameters from the scary internet, only allow the following list through.
def account_link_params
params.require(:account_link).permit(:push_url, :check_uuid_url, :api_key, :name)
params.require(:account_link).permit(:push_url, :check_uuid_url, :api_key, :name, :proforma_version)
end
end
32 changes: 16 additions & 16 deletions app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def add_to_collection
end

def download
zip_file = ProformaService::ExportTask.call(task: @task, options: { version: params[:version] })
zip_file = ProformaService::ExportTask.call(task: @task, options: {version: params[:version]})
send_data(zip_file.string, type: 'application/zip', filename: "task_#{@task.id}.zip", disposition: 'attachment')
end

Expand All @@ -100,21 +100,21 @@ def import_start # rubocop:disable Metric/AbcSize, Metrics/MethodLength
respond_to do |format|
format.js { render layout: false }
end
# rescue ProformaXML::ProformaError => e
# messages = prettify_import_errors(e)
# flash[:alert] = messages
# render json: {
# status: 'failure',
# message: t('.error', error: messages),
# actions: '',
# }
# rescue StandardError => e
# Sentry.capture_exception(e)
# render json: {
# status: 'failure',
# message: t('tasks.import.internal_error'),
# actions: '',
# }
rescue ProformaXML::ProformaError => e
messages = prettify_import_errors(e)
flash[:alert] = messages
render json: {
status: 'failure',
message: t('.error', error: messages),
actions: '',
}
rescue StandardError => e
Sentry.capture_exception(e)
render json: {
status: 'failure',
message: t('tasks.import.internal_error'),
actions: '',
}
end

def import_confirm # rubocop:disable Metric/AbcSize
Expand Down
2 changes: 2 additions & 0 deletions app/models/account_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class AccountLink < ApplicationRecord
validates :push_url, presence: true
validates :api_key, presence: true
validates :name, presence: true
validates :proforma_version, inclusion: {in: [*ProformaXML::SCHEMA_VERSIONS], allow_nil: true}
normalizes :proforma_version, with: ->(proforma_version) { proforma_version.presence }

belongs_to :user

Expand Down
12 changes: 6 additions & 6 deletions app/services/proforma_service/cache_import_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ def initialize(user:, zip_file:)
def execute
data = {}
# ActiveRecord::Base.transaction do
import_file = ImportFileCache.create!(user: @user, zip_file: @zip_file)
ProformaService::ConvertZipToProformaTasks.call(zip_file: @zip_file).each do |proforma_task|
task = Task.find_by(uuid: proforma_task[:uuid])
import_file = ImportFileCache.create!(user: @user, zip_file: @zip_file)
ProformaService::ConvertZipToProformaTasks.call(zip_file: @zip_file).each do |proforma_task|
task = Task.find_by(uuid: proforma_task[:uuid])

data[SecureRandom.uuid] = file_data_hash(task, import_file, proforma_task)
end
import_file.update!(data:)
data[SecureRandom.uuid] = file_data_hash(task, import_file, proforma_task)
end
import_file.update!(data:)
# end
data
end
Expand Down
2 changes: 1 addition & 1 deletion app/services/proforma_service/export_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module ProformaService
class ExportTasks < ServiceBase
def initialize(tasks:, options:)
def initialize(tasks:, options: {})
super()
@tasks = tasks
@options = options
Expand Down
3 changes: 2 additions & 1 deletion app/services/proforma_service/handle_export_confirm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def execute
end

account_link = AccountLink.find(@account_link_id)
zip_stream = ProformaService::ExportTask.call(task: @task, options: {description_format: 'md'})
zip_stream = ProformaService::ExportTask.call(task: @task,
options: {description_format: 'md', version: account_link.proforma_version || ProformaXML::SCHEMA_VERSION_LATEST})
error = TaskService::PushExternal.call(zip: zip_stream, account_link:)

[@task, error]
Expand Down
2 changes: 1 addition & 1 deletion app/services/proforma_service/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(zip:, user:)
def execute
if single_task?
proforma_task = ProformaXML::Importer.call(zip: @zip)
ProformaService::ImportTask.call(proforma_task: proforma_task, user: @user)
ProformaService::ImportTask.call(proforma_task:, user: @user)
else
import_multi
end
Expand Down
3 changes: 3 additions & 0 deletions app/views/account_links/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
.input-group
= f.text_field :api_key, data: {toggle: 'tooltip', placement: 'bottom'}, title: t('.info.token'), class: 'form-control'
= button_tag t('.button.generate'), type: 'button', class: 'generate-api-key-token btn btn-light'
.field-element.form-group
= f.label :proforma_version, AccountLink.human_attribute_name('proforma_version'), class: 'form-label'
= f.select :proforma_version, options_for_select(ProformaXML::SCHEMA_VERSIONS, @account_link.proforma_version), {include_blank: t('account_links.common.proforma_version.select_default', latest_version: ProformaXML::SCHEMA_VERSION_LATEST)}, {class: 'form-select'}
.form-group
.actions.btn-group role='group'
= f.submit t('.button.save'), class: 'btn btn-important'
Expand Down
3 changes: 3 additions & 0 deletions app/views/account_links/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
.row
.col-auto.row-label = AccountLink.human_attribute_name('api_key')
.col.row-value = @account_link.api_key
.row
.col-auto.row-label = AccountLink.human_attribute_name('proforma_version')
.col.row-value = @account_link.proforma_version.presence || t('account_links.common.proforma_version.select_default', latest_version: ProformaXML::SCHEMA_VERSION_LATEST)
- if @account_link.shared_users.any?
.row.vertical
.col.row-label = t('account_links.show.shared_users')
Expand Down
2 changes: 1 addition & 1 deletion config/locales/de/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ de:
app_name: CodeHarbor
button:
abort: Abbrechen
available_versions: Verfügbare ProFormA-XML Versionen
back: Zurück
cancel: Abbrechen
close: Schließen
Expand All @@ -27,7 +28,6 @@ de:
sign_up: Registrieren
update: Aktualisieren
view: Ansehen
available_versions: "Verfügbare ProFormA-XML Versionen"
'yes': Ja
created: Erstellt
created_at: Erstellt am
Expand Down
3 changes: 3 additions & 0 deletions config/locales/de/views/account_links.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
de:
account_links:
common:
proforma_version:
select_default: aktuellste Version (momentan %{latest_version})
edit:
header: Bearbeiten des Account-Links
form:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ en:
app_name: CodeHarbor
button:
abort: Abort
available_versions: Available ProFormA-XML versions
back: Back
cancel: Cancel
close: Close
Expand All @@ -28,7 +29,6 @@ en:
update: Update
view: View
'yes': 'yes'
available_versions: "Available ProFormA-XML versions"
created: Created
created_at: Created at
created_by: Created by
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en/views/account_links.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
en:
account_links:
common:
proforma_version:
select_default: latest (currently %{latest_version})
edit:
header: Editing Account Link
form:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddProformaVersionToAccountLink < ActiveRecord::Migration[7.1]
def change
add_column :account_links, :proforma_version, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_07_03_221801) do
ActiveRecord::Schema[7.1].define(version: 2024_07_31_205103) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
Expand All @@ -29,6 +29,7 @@
t.string "api_key"
t.string "name"
t.string "check_uuid_url"
t.string "proforma_version"
t.index ["user_id"], name: "index_account_links_on_user_id"
end

Expand Down
15 changes: 12 additions & 3 deletions spec/controllers/collections_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,10 @@
let(:collection) { create(:collection, valid_attributes.merge(users: [user], tasks:)) }
let(:tasks) { create_list(:task, 2) }
let(:zip) { instance_double(StringIO, string: 'dummy') }
let(:proforma_version) { '2.1' }
let(:get_request) { get :download_all, params: {id: collection.id, version: proforma_version} }

let(:get_request) { get :download_all, params: {id: collection.id} }

before { allow(ProformaService::ExportTasks).to receive(:call).with(tasks: collection.reload.tasks).and_return(zip) }
before { allow(ProformaService::ExportTasks).to receive(:call).with(tasks: collection.reload.tasks, options: {version: proforma_version}).and_return(zip) }

it do
get_request
Expand All @@ -404,6 +404,15 @@
get_request
expect(response.header['Content-Disposition']).to include "attachment; filename=\"#{collection.title}.zip\""
end

context 'when proforma_version is 2.0' do
let(:proforma_version) { '2.0' }

it 'sends the correct data' do
get_request
expect(response.body).to eql 'dummy'
end
end
end

describe 'POST #share' do
Expand Down
Loading

0 comments on commit fa49748

Please sign in to comment.