preferences_controller.rb 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # frozen_string_literal: true
  2. class Settings::PreferencesController < Settings::BaseController
  3. layout 'admin'
  4. before_action :authenticate_user!
  5. def show; end
  6. def update
  7. user_settings.update(user_settings_params.to_h)
  8. if current_user.update(user_params)
  9. I18n.locale = current_user.locale
  10. redirect_to after_update_redirect_path, notice: I18n.t('generic.changes_saved_msg')
  11. else
  12. render :show
  13. end
  14. end
  15. private
  16. def after_update_redirect_path
  17. settings_preferences_path
  18. end
  19. def user_settings
  20. UserSettingsDecorator.new(current_user)
  21. end
  22. def user_params
  23. params.require(:user).permit(
  24. :locale,
  25. chosen_languages: []
  26. )
  27. end
  28. def user_settings_params
  29. params.require(:user).permit(
  30. :setting_default_privacy,
  31. :setting_default_sensitive,
  32. :setting_default_language,
  33. :setting_unfollow_modal,
  34. :setting_boost_modal,
  35. :setting_delete_modal,
  36. :setting_auto_play_gif,
  37. :setting_display_media,
  38. :setting_expand_spoilers,
  39. :setting_reduce_motion,
  40. :setting_system_font_ui,
  41. :setting_noindex,
  42. :setting_theme,
  43. :setting_hide_network,
  44. :setting_aggregate_reblogs,
  45. :setting_show_application,
  46. :setting_advanced_layout,
  47. :setting_use_blurhash,
  48. :setting_use_pending_items,
  49. :setting_trends,
  50. :setting_crop_images,
  51. notification_emails: %i(follow follow_request reblog favourite mention digest report pending_account trending_tag),
  52. interactions: %i(must_be_follower must_be_following must_be_following_dm)
  53. )
  54. end
  55. end