Move profile picture actions to `Settings::ProfilePictureController`

This commit is contained in:
Andreas Nedbal 2022-06-26 19:45:31 +02:00 committed by Karina Kwiatek
parent efa0048c87
commit 8141db2ca7
4 changed files with 27 additions and 18 deletions

View File

@ -6,20 +6,6 @@ class Settings::ProfileController < ApplicationController
def edit; end
def update
user_attributes = params.require(:user).permit(:show_foreign_themes, :profile_picture_x, :profile_picture_y, :profile_picture_w, :profile_picture_h,
:profile_header_x, :profile_header_y, :profile_header_w, :profile_header_h, :profile_picture, :profile_header)
if current_user.update(user_attributes)
text = t(".success")
text += t(".notice.profile_picture") if user_attributes[:profile_picture]
text += t(".notice.profile_header") if user_attributes[:profile_header]
flash[:success] = text
else
flash[:error] = t(".error")
end
redirect_to edit_user_profile_path
end
def update_profile
profile_attributes = params.require(:profile).permit(:display_name, :motivation_header, :website, :location, :description, :anon_display_name)
if current_user.profile.update(profile_attributes)
@ -27,6 +13,7 @@ class Settings::ProfileController < ApplicationController
else
flash[:error] = t(".error")
end
redirect_to edit_user_profile_path
redirect_to settings_profile_path
end
end

View File

@ -0,0 +1,20 @@
# frozen_string_literal: true
class Settings::ProfilePictureController < ApplicationController
before_action :authenticate_user!
def update
user_attributes = params.require(:user).permit(:show_foreign_themes, :profile_picture_x, :profile_picture_y, :profile_picture_w, :profile_picture_h,
:profile_header_x, :profile_header_y, :profile_header_w, :profile_header_h, :profile_picture, :profile_header)
if current_user.update(user_attributes)
text = t(".success")
text += t(".notice.profile_picture") if user_attributes[:profile_picture]
text += t(".notice.profile_header") if user_attributes[:profile_header]
flash[:success] = text
else
flash[:error] = t(".error")
end
redirect_to settings_profile_path
end
end

View File

@ -1,6 +1,6 @@
.card
.card-body
= bootstrap_form_for(current_user, url: { action: :edit }, html: { multipart: true }, method: :patch) do |f|
= bootstrap_form_for(current_user, url: settings_profile_picture_path, html: { multipart: true }, method: :patch) do |f|
.media#profile-picture-media
.pull-left
@ -35,7 +35,7 @@
= f.primary
.card
.card-body
= bootstrap_form_for(current_user.profile, url: { action: :update_profile }, html: { multipart: true }, method: :patch) do |f|
= bootstrap_form_for(current_user.profile, html: { multipart: true }, method: :patch) do |f|
= f.text_field :display_name

View File

@ -67,7 +67,9 @@ Rails.application.routes.draw do
resource :theme, controller: :theme, only: %i[edit update destroy]
get :profile, to: redirect('/settings/profile/edit')
resource :profile, controller: :profile, only: %i[edit update update_profile]
resource :profile, controller: :profile, only: %i[edit update]
resource :profile_picture, controller: :profile_picture, only: %i[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] }