diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c43f6f101..f768cadea0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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:** diff --git a/app/models/trade/annual_report_upload.rb b/app/models/trade/annual_report_upload.rb index ea7c05a28b..5a7f3f6a70 100644 --- a/app/models/trade/annual_report_upload.rb +++ b/app/models/trade/annual_report_upload.rb @@ -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 @@ -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 @@ -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? diff --git a/config/secrets.yml b/config/secrets.yml index 9079d96b72..eebc25aee2 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -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' diff --git a/lib/modules/trade/changelog_csv_generator.rb b/lib/modules/trade/changelog_csv_generator.rb index d6f3589415..1a5dd14122 100644 --- a/lib/modules/trade/changelog_csv_generator.rb +++ b/lib/modules/trade/changelog_csv_generator.rb @@ -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 diff --git a/spec/models/trade/annual_report_upload_spec.rb b/spec/models/trade/annual_report_upload_spec.rb index 9eb526b351..2838815d38 100644 --- a/spec/models/trade/annual_report_upload_spec.rb +++ b/spec/models/trade/annual_report_upload_spec.rb @@ -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) diff --git a/spec/workers/submission_worker_spec.rb b/spec/workers/submission_worker_spec.rb index cf1290644c..8f70bb3c48 100644 --- a/spec/workers/submission_worker_spec.rb +++ b/spec/workers/submission_worker_spec.rb @@ -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) @@ -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) @@ -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',