mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
move profile_background from User to UserProfile
This commit is contained in:
committed by
Robin Ward
parent
00910679ad
commit
386d1e231a
@@ -357,7 +357,7 @@ class UsersController < ApplicationController
|
||||
when "avatar"
|
||||
upload_avatar_for(user, upload)
|
||||
when "profile_background"
|
||||
upload_profile_background_for(user, upload)
|
||||
upload_profile_background_for(user.user_profile, upload)
|
||||
end
|
||||
else
|
||||
render status: 422, text: upload.errors.full_messages
|
||||
@@ -384,8 +384,7 @@ class UsersController < ApplicationController
|
||||
user = fetch_user_from_params
|
||||
guardian.ensure_can_edit!(user)
|
||||
|
||||
user.profile_background = ""
|
||||
user.save!
|
||||
user.user_profile.clear_profile_background
|
||||
|
||||
render nothing: true
|
||||
end
|
||||
@@ -429,8 +428,8 @@ class UsersController < ApplicationController
|
||||
render json: { upload_id: upload.id, url: upload.url, width: upload.width, height: upload.height }
|
||||
end
|
||||
|
||||
def upload_profile_background_for(user, upload)
|
||||
user.upload_profile_background(upload)
|
||||
def upload_profile_background_for(user_profile, upload)
|
||||
user_profile.upload_profile_background(upload)
|
||||
# TODO: add a resize job here
|
||||
|
||||
render json: { url: upload.url, width: upload.width, height: upload.height }
|
||||
|
||||
@@ -6,7 +6,7 @@ module Jobs
|
||||
def execute(args)
|
||||
return unless SiteSetting.clean_up_uploads?
|
||||
|
||||
uploads_used_as_profile_backgrounds = User.uniq.where("profile_background IS NOT NULL AND profile_background != ''").pluck(:profile_background)
|
||||
uploads_used_as_profile_backgrounds = UserProfile.uniq.where("profile_background IS NOT NULL AND profile_background != ''").pluck(:profile_background)
|
||||
|
||||
grace_period = [SiteSetting.clean_orphan_uploads_grace_period_hours, 1].max
|
||||
|
||||
|
||||
@@ -533,14 +533,6 @@ class User < ActiveRecord::Base
|
||||
created_at > 1.day.ago
|
||||
end
|
||||
|
||||
# TODO this is a MESS
|
||||
# at most user table should have profile_background_upload_id
|
||||
# best case is to move this to another table
|
||||
def upload_profile_background(upload)
|
||||
self.profile_background = upload.url
|
||||
self.save!
|
||||
end
|
||||
|
||||
def generate_api_key(created_by)
|
||||
if api_key.present?
|
||||
api_key.regenerate!(created_by)
|
||||
@@ -773,7 +765,6 @@ end
|
||||
# mailing_list_mode :boolean default(FALSE), not null
|
||||
# primary_group_id :integer
|
||||
# locale :string(10)
|
||||
# profile_background :string(255)
|
||||
# registration_ip_address :inet
|
||||
# last_redirected_to_top_at :datetime
|
||||
# disable_jump_reply :boolean default(FALSE), not null
|
||||
|
||||
@@ -25,6 +25,16 @@ class UserProfile < ActiveRecord::Base
|
||||
cook
|
||||
end
|
||||
|
||||
def upload_profile_background(upload)
|
||||
self.profile_background = upload.url
|
||||
self.save!
|
||||
end
|
||||
|
||||
def clear_profile_background
|
||||
self.profile_background = ""
|
||||
self.save!
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def cook
|
||||
@@ -46,4 +56,5 @@ end
|
||||
# bio_raw :text
|
||||
# location :string(255)
|
||||
# website :string(255)
|
||||
# profile_background :string(255)
|
||||
#
|
||||
|
||||
@@ -135,6 +135,13 @@ class UserSerializer < BasicUserSerializer
|
||||
object.user_profile.bio_processed
|
||||
end
|
||||
|
||||
def profile_background
|
||||
object.user_profile.profile_background
|
||||
end
|
||||
def include_profile_background?
|
||||
profile_background.present?
|
||||
end
|
||||
|
||||
def stats
|
||||
UserAction.stats(object.id, scope)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user