1
0

exports_controller.rb 929 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # frozen_string_literal: true
  2. class Settings::ExportsController < Settings::BaseController
  3. include Authorization
  4. layout 'admin'
  5. before_action :authenticate_user!
  6. before_action :require_not_suspended!
  7. skip_before_action :require_functional!
  8. def show
  9. @export = Export.new(current_account)
  10. @backups = current_user.backups
  11. end
  12. def create
  13. raise Mastodon::NotPermittedError unless user_signed_in?
  14. backup = nil
  15. RedisLock.acquire(lock_options) do |lock|
  16. if lock.acquired?
  17. authorize :backup, :create?
  18. backup = current_user.backups.create!
  19. else
  20. raise Mastodon::RaceConditionError
  21. end
  22. end
  23. BackupWorker.perform_async(backup.id)
  24. redirect_to settings_export_path
  25. end
  26. def lock_options
  27. { redis: Redis.current, key: "backup:#{current_user.id}" }
  28. end
  29. def require_not_suspended!
  30. forbidden if current_account.suspended?
  31. end
  32. end