Skip to content

Commit

Permalink
Merge branch 'release-1.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Levia committed Jun 17, 2019
2 parents 174f8ee + 2a0c98c commit 028e613
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 13 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
### 1.2.1

**Trade Admin**

* Make annual reports submission synchronous again

**Configuration**

* Pull correct email address for automatic emails

### 1.2.0

**Species+ Admin:**
Expand Down
32 changes: 26 additions & 6 deletions app/models/trade/annual_report_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Trade::AnnualReportUpload < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
track_who_does_it
attr_accessible :csv_source_file, :trading_country_id, :point_of_view,
:submitted_at, :submitted_by_id, :number_of_records_submitted,
:aws_storage_path
:submitted_at, :submitted_by_id, :number_of_rows,
:number_of_records_submitted, :aws_storage_path
mount_uploader :csv_source_file, Trade::CsvSourceFileUploader
belongs_to :trading_country, :class_name => GeoEntity, :foreign_key => :trading_country_id
validates :csv_source_file, :csv_column_headers => true, :on => :create
Expand All @@ -39,8 +39,8 @@ def copy_to_sandbox

# object that represents the particular sandbox table linked to this annual
# report upload
def sandbox
return nil if submitted_at.present?
def sandbox(tmp=false)
return nil if submitted_at.present? && !tmp
@sandbox ||= Trade::Sandbox.new(self)
end

Expand Down Expand Up @@ -80,8 +80,28 @@ def submit(submitter)
self.errors[:base] << "Submit failed, primary validation errors present."
return false
end

SubmissionWorker.perform_async(self.id, submitter.id)
return false unless sandbox.copy_from_sandbox_to_shipments(submitter)

records_submitted = sandbox.moved_rows_cnt
# remove uploaded file
store_dir = csv_source_file.store_dir
remove_csv_source_file!
puts '### removing uploads dir ###'
puts Rails.root.join('public', store_dir)
FileUtils.remove_dir(Rails.root.join('public', store_dir), :force => true)

# clear downloads cache
DownloadsCacheCleanupWorker.perform_async(:shipments)

# flag as submitted
update_attributes({
submitted_at: DateTime.now,
submitted_by_id: submitter.id,
number_of_records_submitted: records_submitted
})

# This has been temporarily disabled as originally part of EPIX
#ChangesHistoryGeneratorWorker.perform_async(self.id, submitter.id)
end

def reported_by_exporter?
Expand Down
2 changes: 1 addition & 1 deletion config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ common: &defaults
username: <%= ENV["MAILER_USERNAME"] %>
password: <%= ENV["MAILER_PASSWORD"] %>
host: <%= ENV["MAILER_HOST"] %>
from: <%= ENV["MAILER_FROM"] %>
from: <%= ENV["MAILER_USERNAME"] %>
redis:
namespace: 'SAPI'
url: 'redis://127.0.0.1:6379/1'
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/trade/changelog_csv_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.call(aru, requester, duplicates=nil)

tempfile = Tempfile.new(["changelog_sapi_#{aru.id}-", ".csv"], Rails.root.join('tmp'))

ar_klass = aru.sandbox.ar_klass
ar_klass = aru.sandbox(true).ar_klass

all_columns = DEFAULT_COLUMNS + data_columns.map(&:camelize)
all_columns = all_columns + ['Duplicate'] if duplicates
Expand Down
3 changes: 2 additions & 1 deletion spec/models/trade/annual_report_upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ def invalid_file
)
@submitter = FactoryGirl.create(:user, role: User::MANAGER)
end
context "it calls submission worker" do
pending "it calls submission worker" do
# This has been disabled due to some issues with asynchronous reports submission"
subject { # aru no primary errors
aru = build(:annual_report_upload, :trading_country_id => @argentina.id, :point_of_view => 'I')
aru.save(:validate => false)
Expand Down
9 changes: 5 additions & 4 deletions spec/workers/submission_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
Trade::ChangelogCsvGenerator.stub(:call).and_return(Tempfile.new('changelog.csv'))
SubmissionWorker.any_instance.stub(:upload_on_S3)
end
context "when no primary errors" do
# Test temporarily disabled because SubmissionWorker has been disabled
pending "when no primary errors" do
before(:each) do
@aru = build(:annual_report_upload, :trading_country_id => @argentina.id, :point_of_view => 'I')
@aru.save(:validate => false)
Expand Down Expand Up @@ -55,14 +56,14 @@
SubmissionWorker.new.perform(@aru.id, @submitter.id)
Trade::Permit.find_by_number('BBB').should_not be_nil
end
context "when permit previously reported" do
pending "when permit previously reported" do
before(:each) { create(:permit, :number => 'xxx') }
specify {
expect { SubmissionWorker.new.perform(@aru.id, @submitter.id) }.to change { Trade::Permit.count }.by(2)
}
end
end
context "when primary errors present" do
pending "when primary errors present" do
before(:each) do
@aru = build(:annual_report_upload)
@aru.save(:validate => false)
Expand All @@ -80,7 +81,7 @@
expect { SubmissionWorker.new.perform(@aru.id, @submitter.id) }.not_to change { Trade::Shipment.count }
}
end
context "when reported under a synonym" do
pending "when reported under a synonym" do
before(:each) do
@synonym = create_cites_eu_species(
:name_status => 'S',
Expand Down

0 comments on commit 028e613

Please sign in to comment.