Move export actions into `Settings::ExportController`

This commit is contained in:
Andreas Nedbal 2022-07-02 06:15:00 +02:00 committed by Karina Kwiatek
parent 2a017c8b11
commit 2ee3aab14d
3 changed files with 26 additions and 20 deletions

View File

@ -0,0 +1,22 @@
# frozen_string_literal: true
class Settings::ExportController < ApplicationController
before_action :authenticate_user!
def index
if current_user.export_processing
flash[:info] = t(".info")
end
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
end

View File

@ -1,5 +1,5 @@
class UserController < ApplicationController class UserController < ApplicationController
before_action :authenticate_user!, only: %w[data export begin_export edit_security update_2fa destroy_2fa reset_user_recovery_codes edit_mute edit_blocks] before_action :authenticate_user!, only: %w[data edit_security update_2fa destroy_2fa reset_user_recovery_codes edit_mute edit_blocks]
def show def show
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first!
@ -69,23 +69,6 @@ class UserController < ApplicationController
def data def data
end end
def export
if current_user.export_processing
flash[:info] = t(".info")
end
end
def begin_export
if current_user.can_export?
ExportWorker.perform_async(current_user.id)
flash[:success] = t(".success")
else
flash[:error] = t(".error")
end
redirect_to user_export_path
end
def edit_security def edit_security
if current_user.otp_module_disabled? if current_user.otp_module_disabled?
current_user.otp_secret_key = User.otp_random_secret(25) current_user.otp_secret_key = User.otp_random_secret(25)

View File

@ -73,6 +73,9 @@ Rails.application.routes.draw do
get :privacy, to: redirect('/settings/privacy/edit') get :privacy, to: redirect('/settings/privacy/edit')
resource :privacy, controller: :privacy, only: %i[edit update] resource :privacy, controller: :privacy, only: %i[edit update]
get :export, to: 'export#index'
post :export, to: 'export#create'
end end
resolve('Theme') { [:settings_theme] } # to make link_to/form_for work nicely when passing a `Theme` object to it, see also: https://api.rubyonrails.org/v6.1.5.1/classes/ActionDispatch/Routing/Mapper/CustomUrls.html#method-i-resolve resolve('Theme') { [:settings_theme] } # to make link_to/form_for work nicely when passing a `Theme` object to it, see also: https://api.rubyonrails.org/v6.1.5.1/classes/ActionDispatch/Routing/Mapper/CustomUrls.html#method-i-resolve
resolve('Profile') { [:settings_profile] } resolve('Profile') { [:settings_profile] }
@ -96,8 +99,6 @@ Rails.application.routes.draw do
end end
match '/settings/data', to: 'user#data', via: :get, as: :user_data match '/settings/data', to: 'user#data', via: :get, as: :user_data
match '/settings/export', to: 'user#export', via: :get, as: :user_export
match '/settings/export', to: 'user#begin_export', via: :post, as: :begin_user_export
namespace :ajax do namespace :ajax do
match '/ask', to: 'question#create', via: :post, as: :ask match '/ask', to: 'question#create', via: :post, as: :ask