exports_controller.rb 828 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # frozen_string_literal: true
  2. class Settings::ExportsController < Settings::BaseController
  3. include Authorization
  4. include Redisable
  5. include Lockable
  6. skip_before_action :check_self_destruct!
  7. skip_before_action :require_functional!
  8. def show
  9. @export_summary = ExportSummary.new(preloaded_account)
  10. @backups = current_user.backups
  11. end
  12. def create
  13. backup = nil
  14. with_redis_lock("backup:#{current_user.id}") do
  15. authorize :backup, :create?
  16. backup = current_user.backups.create!
  17. end
  18. BackupWorker.perform_async(backup.id)
  19. redirect_to settings_export_path
  20. end
  21. private
  22. def preloaded_account
  23. current_account.tap do |account|
  24. ActiveRecord::Associations::Preloader.new(
  25. records: [account],
  26. associations: :account_stat
  27. ).call
  28. end
  29. end
  30. end