fixed attachments deletion in backup_job, and more (#9221)

pull/9224/head
Markus Kahl 4 years ago committed by GitHub
parent b9ce297ea9
commit 6156d4b837
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/controllers/admin/backups_controller.rb
  2. 2
      app/helpers/backup_helper.rb
  3. 2
      app/models/export.rb
  4. 2
      app/views/user_mailer/backup_token_reset.html.erb
  5. 2
      app/workers/backup_job.rb
  6. 3
      spec/workers/backup_job_spec.rb

@ -41,7 +41,7 @@ class Admin::BackupsController < ApplicationController
def show
@backup_token = Token::Backup.find_by user: current_user
last_backup = Backup.last
last_backup = find_backup user: current_user
if last_backup
@job_status_id = last_backup.job_status.job_id
@ -88,6 +88,13 @@ class Admin::BackupsController < ApplicationController
private
def find_backup(status: :success, user: current_user)
Backup
.joins(:job_status)
.where(job_status: { user: user, status: status })
.last
end
def token_reset_successful!(token)
notify_user_and_admins current_user, backup_token: token

@ -55,7 +55,7 @@ module BackupHelper
end
def just_installed_openproject?(after: instant_backup_threshold_date)
created_at = Project.order(created_at: :asc).limit(1).pick(:created_at)
created_at = User.order(created_at: :asc).limit(1).pick(:created_at)
created_at && created_at >= after
end

@ -3,7 +3,7 @@ class Export < ApplicationRecord
:job_status,
-> { where(reference_type: "Export") },
class_name: "JobStatus::Status",
foreign_key: :reference
foreign_key: :reference_id
)
def ready?

@ -34,7 +34,7 @@ See docs/COPYRIGHT.rdoc for more details.
%>
<% if @waiting_period %>
&nbsp;
<%= t(:mail_body_backup_waiting_period hours: @waiting_period.in_hours.to_i) %>
<%= t(:mail_body_backup_waiting_period, hours: @waiting_period.in_hours.to_i) %>
<% end %>
</p>

@ -55,7 +55,7 @@ class BackupJob < ::ApplicationJob
ensure
remove_files! db_dump_file_name, archive_file_name
attachments.each(&:destroy) unless success?
backup.attachments.each(&:destroy) unless success?
Rails.logger.info(
"BackupJob(include_attachments: #{include_attachments}) finished " \

@ -57,7 +57,6 @@ describe BackupJob, type: :model do
let(:db_dump_success) { false }
let(:attachments) { [] }
let(:arguments) { [{ backup: backup, user: user, **opts }] }
let(:user) { FactoryBot.create :user }
@ -65,8 +64,6 @@ describe BackupJob, type: :model do
before do
previous_backup; backup; status # create
allow(job).to receive(:job_status).and_return job_status
allow(job).to receive(:attachments).and_return attachments
allow(job).to receive(:arguments).and_return arguments
allow(job).to receive(:job_id).and_return job_id

Loading…
Cancel
Save