Move theme actions from `UserController` to `Settings::ThemeController`
This commit is contained in:
parent
449aa1d998
commit
298c7d625e
|
@ -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
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue