mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
move profile_background from User to UserProfile
This commit is contained in:
parent
00910679ad
commit
386d1e231a
8 changed files with 53 additions and 18 deletions
|
@ -357,7 +357,7 @@ class UsersController < ApplicationController
|
||||||
when "avatar"
|
when "avatar"
|
||||||
upload_avatar_for(user, upload)
|
upload_avatar_for(user, upload)
|
||||||
when "profile_background"
|
when "profile_background"
|
||||||
upload_profile_background_for(user, upload)
|
upload_profile_background_for(user.user_profile, upload)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
render status: 422, text: upload.errors.full_messages
|
render status: 422, text: upload.errors.full_messages
|
||||||
|
@ -384,8 +384,7 @@ class UsersController < ApplicationController
|
||||||
user = fetch_user_from_params
|
user = fetch_user_from_params
|
||||||
guardian.ensure_can_edit!(user)
|
guardian.ensure_can_edit!(user)
|
||||||
|
|
||||||
user.profile_background = ""
|
user.user_profile.clear_profile_background
|
||||||
user.save!
|
|
||||||
|
|
||||||
render nothing: true
|
render nothing: true
|
||||||
end
|
end
|
||||||
|
@ -429,8 +428,8 @@ class UsersController < ApplicationController
|
||||||
render json: { upload_id: upload.id, url: upload.url, width: upload.width, height: upload.height }
|
render json: { upload_id: upload.id, url: upload.url, width: upload.width, height: upload.height }
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload_profile_background_for(user, upload)
|
def upload_profile_background_for(user_profile, upload)
|
||||||
user.upload_profile_background(upload)
|
user_profile.upload_profile_background(upload)
|
||||||
# TODO: add a resize job here
|
# TODO: add a resize job here
|
||||||
|
|
||||||
render json: { url: upload.url, width: upload.width, height: upload.height }
|
render json: { url: upload.url, width: upload.width, height: upload.height }
|
||||||
|
|
|
@ -6,7 +6,7 @@ module Jobs
|
||||||
def execute(args)
|
def execute(args)
|
||||||
return unless SiteSetting.clean_up_uploads?
|
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
|
grace_period = [SiteSetting.clean_orphan_uploads_grace_period_hours, 1].max
|
||||||
|
|
||||||
|
|
|
@ -533,14 +533,6 @@ class User < ActiveRecord::Base
|
||||||
created_at > 1.day.ago
|
created_at > 1.day.ago
|
||||||
end
|
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)
|
def generate_api_key(created_by)
|
||||||
if api_key.present?
|
if api_key.present?
|
||||||
api_key.regenerate!(created_by)
|
api_key.regenerate!(created_by)
|
||||||
|
@ -773,7 +765,6 @@ end
|
||||||
# mailing_list_mode :boolean default(FALSE), not null
|
# mailing_list_mode :boolean default(FALSE), not null
|
||||||
# primary_group_id :integer
|
# primary_group_id :integer
|
||||||
# locale :string(10)
|
# locale :string(10)
|
||||||
# profile_background :string(255)
|
|
||||||
# registration_ip_address :inet
|
# registration_ip_address :inet
|
||||||
# last_redirected_to_top_at :datetime
|
# last_redirected_to_top_at :datetime
|
||||||
# disable_jump_reply :boolean default(FALSE), not null
|
# disable_jump_reply :boolean default(FALSE), not null
|
||||||
|
|
|
@ -25,6 +25,16 @@ class UserProfile < ActiveRecord::Base
|
||||||
cook
|
cook
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def cook
|
def cook
|
||||||
|
@ -46,4 +56,5 @@ end
|
||||||
# bio_raw :text
|
# bio_raw :text
|
||||||
# location :string(255)
|
# location :string(255)
|
||||||
# website :string(255)
|
# website :string(255)
|
||||||
|
# profile_background :string(255)
|
||||||
#
|
#
|
||||||
|
|
|
@ -135,6 +135,13 @@ class UserSerializer < BasicUserSerializer
|
||||||
object.user_profile.bio_processed
|
object.user_profile.bio_processed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def profile_background
|
||||||
|
object.user_profile.profile_background
|
||||||
|
end
|
||||||
|
def include_profile_background?
|
||||||
|
profile_background.present?
|
||||||
|
end
|
||||||
|
|
||||||
def stats
|
def stats
|
||||||
UserAction.stats(object.id, scope)
|
UserAction.stats(object.id, scope)
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
class MoveProfileBackgroundToUserProfiles < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
add_column :user_profiles, :profile_background, :string, limit: 255
|
||||||
|
|
||||||
|
execute "UPDATE user_profiles SET profile_background = (SELECT profile_background FROM users WHERE user_profiles.user_id = users.id)"
|
||||||
|
|
||||||
|
remove_column :users, :profile_background
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
add_column :users, :profile_background, :string, limit: 255
|
||||||
|
|
||||||
|
execute "UPDATE users SET profile_background = (SELECT profile_background FROM user_profiles WHERE user_profiles.user_id = users.id)"
|
||||||
|
|
||||||
|
remove_column :user_profiles, :profile_background
|
||||||
|
end
|
||||||
|
end
|
|
@ -1169,7 +1169,7 @@ describe UsersController do
|
||||||
xhr :post, :upload_user_image, username: user.username, file: user_image, user_image_type: "profile_background"
|
xhr :post, :upload_user_image, username: user.username, file: user_image, user_image_type: "profile_background"
|
||||||
user.reload
|
user.reload
|
||||||
|
|
||||||
user.profile_background.should == "/uploads/default/1/1234567890123456.png"
|
user.user_profile.profile_background.should == "/uploads/default/1/1234567890123456.png"
|
||||||
|
|
||||||
# returns the url, width and height of the uploaded image
|
# returns the url, width and height of the uploaded image
|
||||||
json = JSON.parse(response.body)
|
json = JSON.parse(response.body)
|
||||||
|
@ -1218,7 +1218,7 @@ describe UsersController do
|
||||||
Upload.expects(:create_for).returns(upload)
|
Upload.expects(:create_for).returns(upload)
|
||||||
xhr :post, :upload_user_image, username: user.username, file: user_image_url, user_image_type: "profile_background"
|
xhr :post, :upload_user_image, username: user.username, file: user_image_url, user_image_type: "profile_background"
|
||||||
user.reload
|
user.reload
|
||||||
user.profile_background.should == "/uploads/default/1/1234567890123456.png"
|
user.user_profile.profile_background.should == "/uploads/default/1/1234567890123456.png"
|
||||||
|
|
||||||
# returns the url, width and height of the uploaded image
|
# returns the url, width and height of the uploaded image
|
||||||
json = JSON.parse(response.body)
|
json = JSON.parse(response.body)
|
||||||
|
@ -1287,7 +1287,7 @@ describe UsersController do
|
||||||
|
|
||||||
it 'it successful' do
|
it 'it successful' do
|
||||||
xhr :put, :clear_profile_background, username: user.username
|
xhr :put, :clear_profile_background, username: user.username
|
||||||
user.reload.profile_background.should == ""
|
user.reload.user_profile.profile_background.should == ""
|
||||||
response.should be_success
|
response.should be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,16 @@ describe UserSerializer do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with filled out profile background" do
|
||||||
|
before do
|
||||||
|
user.user_profile.profile_background = 'http://background.com'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "has a profile background" do
|
||||||
|
expect(json[:profile_background]).to eq 'http://background.com'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "with filled out website" do
|
context "with filled out website" do
|
||||||
before do
|
before do
|
||||||
user.user_profile.website = 'http://example.com'
|
user.user_profile.website = 'http://example.com'
|
||||||
|
|
Loading…
Reference in a new issue