mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 13:53:45 +08:00
FEATURE: Allow a user to upload an image for their expansion background.
This commit is contained in:
parent
bde0820cd4
commit
4d465362b5
|
@ -106,6 +106,16 @@
|
|||
type="profile_background"}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group pref-profile-bg">
|
||||
<label class="control-label">{{i18n user.change_expansion_background.title}}</label>
|
||||
<div class="controls">
|
||||
{{image-uploader uploadUrl=imageUploadUrl
|
||||
imageUrl=expansion_background
|
||||
instantDelete="true"
|
||||
type="expansion_background"}}
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if allowUserLocale}}
|
||||
|
|
|
@ -7,6 +7,21 @@ var clickOutsideEventName = "mousedown.outside-user-expansion",
|
|||
export default Discourse.View.extend(CleansUp, {
|
||||
elementId: 'user-expansion',
|
||||
classNameBindings: ['controller.visible::hidden', 'controller.showBadges'],
|
||||
allowBackgrounds: Discourse.computed.setting('allow_profile_backgrounds'),
|
||||
|
||||
addBackground: function() {
|
||||
var url = this.get('controller.user.expansion_background');
|
||||
if (!this.get('allowBackgrounds')) { return; }
|
||||
|
||||
var $this = this.$();
|
||||
if (!$this) { return; }
|
||||
|
||||
if (Ember.empty(url)) {
|
||||
$this.css('background-image', '');
|
||||
} else {
|
||||
$this.css('background-image', "url(" + url + ")");
|
||||
}
|
||||
}.observes('controller.user.expansion_background'),
|
||||
|
||||
_setup: function() {
|
||||
var self = this;
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
padding: 12px 12px 5px 12px;
|
||||
border: 1px solid scale-color-diff();
|
||||
|
||||
background-size: cover;
|
||||
background-position: center center;
|
||||
|
||||
.avatar-placeholder {
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
|
|
|
@ -461,6 +461,8 @@ class UsersController < ApplicationController
|
|||
upload_avatar_for(user, upload)
|
||||
when "profile_background"
|
||||
upload_profile_background_for(user.user_profile, upload)
|
||||
when "expansion_background"
|
||||
upload_expansion_background_for(user.user_profile, upload)
|
||||
end
|
||||
else
|
||||
render status: 422, text: upload.errors.full_messages
|
||||
|
@ -490,6 +492,8 @@ class UsersController < ApplicationController
|
|||
image_type = params.require(:image_type)
|
||||
if image_type == 'profile_background'
|
||||
user.user_profile.clear_profile_background
|
||||
elsif image_type == 'expansion_background'
|
||||
user.user_profile.clear_expansion_background
|
||||
else
|
||||
raise Discourse::InvalidParameters.new(:image_type)
|
||||
end
|
||||
|
@ -547,8 +551,11 @@ class UsersController < ApplicationController
|
|||
|
||||
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 }
|
||||
end
|
||||
|
||||
def upload_expansion_background_for(user_profile, upload)
|
||||
user_profile.upload_expansion_background(upload)
|
||||
render json: { url: upload.url, width: upload.width, height: upload.height }
|
||||
end
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ module Jobs
|
|||
|
||||
ignore_urls = []
|
||||
ignore_urls << UserProfile.uniq.where("profile_background IS NOT NULL AND profile_background != ''").pluck(:profile_background)
|
||||
ignore_urls << UserProfile.uniq.where("expansion_background IS NOT NULL AND expansion_background != ''").pluck(:expansion_background)
|
||||
ignore_urls << Category.uniq.where("logo_url IS NOT NULL AND logo_url != ''").pluck(:logo_url)
|
||||
ignore_urls << Category.uniq.where("background_url IS NOT NULL AND background_url != ''").pluck(:background_url)
|
||||
ignore_urls.flatten!
|
||||
|
|
|
@ -29,6 +29,16 @@ class UserProfile < ActiveRecord::Base
|
|||
cook
|
||||
end
|
||||
|
||||
def upload_expansion_background(upload)
|
||||
self.expansion_background = upload.url
|
||||
self.save!
|
||||
end
|
||||
|
||||
def clear_expansion_background
|
||||
self.expansion_background = ""
|
||||
self.save!
|
||||
end
|
||||
|
||||
def upload_profile_background(upload)
|
||||
self.profile_background = upload.url
|
||||
self.save!
|
||||
|
@ -96,6 +106,7 @@ end
|
|||
# bio_cooked :text
|
||||
# dismissed_banner_key :integer
|
||||
# profile_background :string(255)
|
||||
# expansion_background :string(255)
|
||||
# bio_cooked_version :integer
|
||||
#
|
||||
# Indexes
|
||||
|
|
|
@ -27,6 +27,7 @@ class UserSerializer < BasicUserSerializer
|
|||
:created_at,
|
||||
:website,
|
||||
:profile_background,
|
||||
:expansion_background,
|
||||
:location,
|
||||
:can_edit,
|
||||
:can_edit_username,
|
||||
|
@ -117,6 +118,14 @@ class UserSerializer < BasicUserSerializer
|
|||
profile_background.present?
|
||||
end
|
||||
|
||||
def expansion_background
|
||||
object.user_profile.expansion_background
|
||||
end
|
||||
|
||||
def include_expansion_background?
|
||||
expansion_background.present?
|
||||
end
|
||||
|
||||
def location
|
||||
object.user_profile.location
|
||||
end
|
||||
|
|
|
@ -369,6 +369,9 @@ en:
|
|||
change_profile_background:
|
||||
title: "Profile Background"
|
||||
|
||||
change_expansion_background:
|
||||
title: "User Expansion Background"
|
||||
|
||||
email:
|
||||
title: "Email"
|
||||
instructions: "Never shown to the public."
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddExpansionBackgroundToUserProfiles < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :user_profiles, :expansion_background, :string, limit: 255
|
||||
end
|
||||
end
|
|
@ -1156,6 +1156,21 @@ describe UsersController do
|
|||
json['height'].should == 200
|
||||
end
|
||||
|
||||
it 'is successful for expansion backgrounds' do
|
||||
upload = Fabricate(:upload)
|
||||
Upload.expects(:create_for).returns(upload)
|
||||
xhr :post, :upload_user_image, username: user.username, file: user_image, image_type: "expansion_background"
|
||||
user.reload
|
||||
|
||||
user.user_profile.expansion_background.should == "/uploads/default/1/1234567890123456.png"
|
||||
|
||||
# returns the url, width and height of the uploaded image
|
||||
json = JSON.parse(response.body)
|
||||
json['url'].should == "/uploads/default/1/1234567890123456.png"
|
||||
json['width'].should == 100
|
||||
json['height'].should == 200
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "with url" do
|
||||
|
@ -1204,6 +1219,20 @@ describe UsersController do
|
|||
json['width'].should == 100
|
||||
json['height'].should == 200
|
||||
end
|
||||
|
||||
it 'is successful for expansion backgrounds' do
|
||||
upload = Fabricate(:upload)
|
||||
Upload.expects(:create_for).returns(upload)
|
||||
xhr :post, :upload_user_image, username: user.username, file: user_image_url, image_type: "expansion_background"
|
||||
user.reload
|
||||
user.user_profile.expansion_background.should == "/uploads/default/1/1234567890123456.png"
|
||||
|
||||
# returns the url, width and height of the uploaded image
|
||||
json = JSON.parse(response.body)
|
||||
json['url'].should == "/uploads/default/1/1234567890123456.png"
|
||||
json['width'].should == 100
|
||||
json['height'].should == 200
|
||||
end
|
||||
end
|
||||
|
||||
it "should handle malformed urls" do
|
||||
|
|
|
@ -32,6 +32,16 @@ describe UserSerializer do
|
|||
end
|
||||
end
|
||||
|
||||
context "with filled out expansion background" do
|
||||
before do
|
||||
user.user_profile.expansion_background = 'http://expansion.com'
|
||||
end
|
||||
|
||||
it "has a profile background" do
|
||||
expect(json[:expansion_background]).to eq 'http://expansion.com'
|
||||
end
|
||||
end
|
||||
|
||||
context "with filled out profile background" do
|
||||
before do
|
||||
user.user_profile.profile_background = 'http://background.com'
|
||||
|
|
Loading…
Reference in New Issue
Block a user