Move privacy actions from user controller to `Settings::PrivacyController`

This commit is contained in:
Andreas Nedbal 2022-06-28 01:50:20 +02:00 committed by Karina Kwiatek
parent 97d8068a09
commit 8cf6be8067
3 changed files with 24 additions and 22 deletions

View File

@ -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

View File

@ -1,5 +1,5 @@
class UserController < ApplicationController 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 def show
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first!
@ -21,24 +21,6 @@ class UserController < ApplicationController
end end
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 def followers
@title = 'Followers' @title = 'Followers'
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first! @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).includes(:profile).first!

View File

@ -70,6 +70,9 @@ Rails.application.routes.draw do
resource :profile, controller: :profile, only: %i[edit update] resource :profile, controller: :profile, only: %i[edit update]
resource :profile_picture, controller: :profile_picture, only: %i[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 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('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] } resolve('Profile') { [:settings_profile] }
@ -92,9 +95,6 @@ Rails.application.routes.draw do
end end
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/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#export', via: :get, as: :user_export
match '/settings/export', to: 'user#begin_export', via: :post, as: :begin_user_export match '/settings/export', to: 'user#begin_export', via: :post, as: :begin_user_export