From 68816cf01af0cfbf83d9048d6653c5f3244184ff Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sat, 17 May 2025 15:19:01 +0300 Subject: [PATCH] Create parent preferences controller class --- .../basic_preferences_controller.rb | 25 +++--------------- .../preferences/preferences_controller.rb | 26 +++++++++++++++++++ .../_update_success_flash.html.erb | 0 config/locales/en.yml | 9 ++++--- 4 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 app/controllers/preferences/preferences_controller.rb rename app/views/preferences/{basic_preferences => preferences}/_update_success_flash.html.erb (100%) diff --git a/app/controllers/preferences/basic_preferences_controller.rb b/app/controllers/preferences/basic_preferences_controller.rb index 3b0344d21..90a2278ee 100644 --- a/app/controllers/preferences/basic_preferences_controller.rb +++ b/app/controllers/preferences/basic_preferences_controller.rb @@ -1,18 +1,8 @@ module Preferences - class BasicPreferencesController < ApplicationController - layout "site" + class BasicPreferencesController < PreferencesController + private - before_action :authorize_web - before_action :set_locale - - authorize_resource :class => :preferences - - before_action :check_database_readable - before_action :check_database_writable, :only => [:update] - - def show; end - - def update + def update_preferences current_user.languages = params[:user][:languages].split(",") current_user.preferred_editor = if params[:user][:preferred_editor] == "default" @@ -33,14 +23,7 @@ module Preferences success &= map_color_scheme_preference.update(:v => params[:map_color_scheme]) end - if success - # Use a partial so that it is rendered during the next page load in the correct language. - flash[:notice] = { :partial => "update_success_flash" } - redirect_to basic_preferences_path - else - flash.now[:error] = t ".failure" - render :show - end + success end end end diff --git a/app/controllers/preferences/preferences_controller.rb b/app/controllers/preferences/preferences_controller.rb new file mode 100644 index 000000000..3bb89e034 --- /dev/null +++ b/app/controllers/preferences/preferences_controller.rb @@ -0,0 +1,26 @@ +module Preferences + class PreferencesController < ApplicationController + layout "site" + + before_action :authorize_web + before_action :set_locale + + authorize_resource :class => :preferences + + before_action :check_database_readable + before_action :check_database_writable, :only => :update + + def show; end + + def update + if update_preferences + # Use a partial so that it is rendered during the next page load in the correct language. + flash[:notice] = { :partial => "update_success_flash" } + redirect_to :action => :show + else + flash.now[:error] = t "failure", :scope => "preferences.preferences.update" + render :show + end + end + end +end diff --git a/app/views/preferences/basic_preferences/_update_success_flash.html.erb b/app/views/preferences/preferences/_update_success_flash.html.erb similarity index 100% rename from app/views/preferences/basic_preferences/_update_success_flash.html.erb rename to app/views/preferences/preferences/_update_success_flash.html.erb diff --git a/config/locales/en.yml b/config/locales/en.yml index 30444bd84..0cdd5a957 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1949,6 +1949,11 @@ en: flash changed: "Your password has been changed." flash token bad: "Did not find that token, check the URL maybe?" preferences: + preferences: + update: + failure: Couldn't update preferences. + update_success_flash: + message: Preferences updated. basic_preferences: show: title: My Preferences @@ -1963,10 +1968,6 @@ en: light: Light dark: Dark save: Update Preferences - update: - failure: Couldn't update preferences. - update_success_flash: - message: Preferences updated. profiles: show: title: Edit Profile -- 2.39.5