2022-07-01 21:15:00 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Settings::ExportController < ApplicationController
|
|
|
|
before_action :authenticate_user!
|
2022-12-10 06:56:07 -08:00
|
|
|
before_action :mark_notifications_as_read, only: %i[index]
|
2022-07-01 21:15:00 -07:00
|
|
|
|
|
|
|
def index
|
2022-07-02 05:43:53 -07:00
|
|
|
flash[:info] = t(".info") if current_user.export_processing
|
2022-07-01 21:15:00 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
if current_user.can_export?
|
|
|
|
ExportWorker.perform_async(current_user.id)
|
|
|
|
flash[:success] = t(".success")
|
|
|
|
else
|
|
|
|
flash[:error] = t(".error")
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to settings_export_path
|
|
|
|
end
|
2022-12-10 06:56:07 -08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2023-06-16 09:20:21 -07:00
|
|
|
# rubocop:disable Rails/SkipsModelValidations
|
2022-12-10 06:56:07 -08:00
|
|
|
def mark_notifications_as_read
|
2023-06-16 09:20:21 -07:00
|
|
|
updated = Notification::DataExported
|
|
|
|
.where(recipient: current_user, new: true)
|
|
|
|
.update_all(new: false)
|
|
|
|
current_user.touch(:notifications_updated_at) if updated.positive?
|
2022-12-10 06:56:07 -08:00
|
|
|
end
|
2023-06-16 09:20:21 -07:00
|
|
|
# rubocop:enable Rails/SkipsModelValidations
|
2022-07-01 21:15:00 -07:00
|
|
|
end
|