From 298c7d625e0aa9eda6b720d456f989d120e2e263 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Sun, 26 Jun 2022 02:58:22 +0200 Subject: [PATCH] Move theme actions from `UserController` to `Settings::ThemeController` --- app/controllers/settings/theme_controller.rb | 45 ++++++++++++++++++++ app/controllers/user_controller.rb | 44 +------------------ 2 files changed, 46 insertions(+), 43 deletions(-) create mode 100644 app/controllers/settings/theme_controller.rb diff --git a/app/controllers/settings/theme_controller.rb b/app/controllers/settings/theme_controller.rb new file mode 100644 index 00000000..1f3a252d --- /dev/null +++ b/app/controllers/settings/theme_controller.rb @@ -0,0 +1,45 @@ +class Settings::ThemeController < ApplicationController + include ThemeHelper + + before_action :authenticate_user! + + def edit + end + + def update + update_attributes = params.require(:theme).permit([ + :primary_color, :primary_text, + :danger_color, :danger_text, + :success_color, :success_text, + :warning_color, :warning_text, + :info_color, :info_text, + :dark_color, :dark_text, + :light_color, :light_text, + :raised_background, :raised_accent, + :background_color, :body_text, + :muted_text, :input_color, + :input_text + ]) + + if current_user.theme.nil? + current_user.theme = Theme.new update_attributes + current_user.theme.user_id = current_user.id + + if current_user.theme.save + flash[:success] = t(".success") + else + flash[:error] = t(".error", errors: current_user.theme.errors.messages.flatten.join(" ")) + end + elsif current_user.theme.update(update_attributes) + flash[:success] = t(".success") + else + flash[:error] = t(".error", errors: current_user.theme.errors.messages.flatten.join(" ")) + end + redirect_to edit_user_theme_path + end + + def destroy + current_user.theme.destroy! + redirect_to edit_user_theme_path + end +end diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 9c48184e..54bcf939 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,7 +1,5 @@ class UserController < ApplicationController - include ThemeHelper - - before_action :authenticate_user!, only: %w(edit update edit_privacy update_privacy edit_theme update_theme preview_theme delete_theme data export begin_export edit_security update_2fa destroy_2fa reset_user_recovery_codes edit_mute) + before_action :authenticate_user!, only: %w(edit update edit_privacy update_privacy data export begin_export edit_security update_2fa destroy_2fa reset_user_recovery_codes edit_mute) def show @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! @@ -119,46 +117,6 @@ class UserController < ApplicationController def data end - def edit_theme - end - - def delete_theme - current_user.theme.destroy! - redirect_to edit_user_theme_path - end - - def update_theme - update_attributes = params.require(:theme).permit([ - :primary_color, :primary_text, - :danger_color, :danger_text, - :success_color, :success_text, - :warning_color, :warning_text, - :info_color, :info_text, - :dark_color, :dark_text, - :light_color, :light_text, - :raised_background, :raised_accent, - :background_color, :body_text, - :muted_text, :input_color, - :input_text - ]) - - if current_user.theme.nil? - current_user.theme = Theme.new update_attributes - current_user.theme.user_id = current_user.id - - if current_user.theme.save - flash[:success] = t(".success") - else - flash[:error] = t(".error", errors: current_user.theme.errors.messages.flatten.join(" ")) - end - elsif current_user.theme.update(update_attributes) - flash[:success] = t(".success") - else - flash[:error] = t(".error", errors: current_user.theme.errors.messages.flatten.join(" ")) - end - redirect_to edit_user_theme_path - end - def export if current_user.export_processing flash[:info] = t(".info")