From 8cf6be8067c461b7f0f4199c7cc3ad9a250a5711 Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Tue, 28 Jun 2022 01:50:20 +0200 Subject: [PATCH] Move privacy actions from user controller to `Settings::PrivacyController` --- .../settings/privacy_controller.rb | 20 +++++++++++++++++++ app/controllers/user_controller.rb | 20 +------------------ config/routes.rb | 6 +++--- 3 files changed, 24 insertions(+), 22 deletions(-) create mode 100644 app/controllers/settings/privacy_controller.rb diff --git a/app/controllers/settings/privacy_controller.rb b/app/controllers/settings/privacy_controller.rb new file mode 100644 index 00000000..f85201f1 --- /dev/null +++ b/app/controllers/settings/privacy_controller.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class Settings::PrivacyController < ApplicationController + before_action :authenticate_user! + + def edit; end + + def update + user_attributes = params.require(:user).permit(:privacy_allow_anonymous_questions, + :privacy_allow_public_timeline, + :privacy_allow_stranger_answers, + :privacy_show_in_search) + if current_user.update(user_attributes) + flash[:success] = t(".success") + else + flash[:error] = t(".error") + end + redirect_to settings_privacy_path + end +end diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 5de75c18..e475c1eb 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,5 +1,5 @@ class UserController < ApplicationController - before_action :authenticate_user!, only: %w[edit_privacy update_privacy 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 export begin_export edit_security update_2fa destroy_2fa reset_user_recovery_codes edit_mute edit_blocks] def show @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! @@ -21,24 +21,6 @@ class UserController < ApplicationController end end - # region Privacy settings - def edit_privacy - end - - def update_privacy - user_attributes = params.require(:user).permit(:privacy_allow_anonymous_questions, - :privacy_allow_public_timeline, - :privacy_allow_stranger_answers, - :privacy_show_in_search) - if current_user.update(user_attributes) - flash[:success] = t(".success") - else - flash[:error] = t(".error") - end - redirect_to edit_user_privacy_path - end - # endregion - def followers @title = 'Followers' @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! diff --git a/config/routes.rb b/config/routes.rb index e0f53ca3..7ba4b4e3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -70,6 +70,9 @@ Rails.application.routes.draw do resource :profile, controller: :profile, only: %i[edit update] resource :profile_picture, controller: :profile_picture, only: %i[update] + + get :privacy, to: redirect('/settings/privacy/edit') + resource :privacy, controller: :privacy, only: %i[edit update] 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('Profile') { [:settings_profile] } @@ -92,9 +95,6 @@ Rails.application.routes.draw do end end - match '/settings/privacy', to: 'user#edit_privacy', via: :get, as: :edit_user_privacy - match '/settings/privacy', to: 'user#update_privacy', via: :patch, as: :update_user_privacy - 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