export_controller_concern.rb 686 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # frozen_string_literal: true
  2. module ExportControllerConcern
  3. extend ActiveSupport::Concern
  4. included do
  5. before_action :authenticate_user!
  6. before_action :require_not_suspended!
  7. before_action :load_export
  8. skip_before_action :require_functional!
  9. end
  10. private
  11. def load_export
  12. @export = Export.new(current_account)
  13. end
  14. def send_export_file
  15. respond_to do |format|
  16. format.csv { send_data export_data, filename: export_filename }
  17. end
  18. end
  19. def export_data
  20. raise 'Override in controller'
  21. end
  22. def export_filename
  23. "#{controller_name}.csv"
  24. end
  25. def require_not_suspended!
  26. forbidden if current_account.suspended?
  27. end
  28. end