diff --git a/app/assets/javascripts/discourse/templates/user/preferences.hbs b/app/assets/javascripts/discourse/templates/user/preferences.hbs
index 9d71a07e1..e8f6e1f05 100644
--- a/app/assets/javascripts/discourse/templates/user/preferences.hbs
+++ b/app/assets/javascripts/discourse/templates/user/preferences.hbs
@@ -97,15 +97,25 @@
{{#if allowBackgrounds}}
-
-
-
- {{image-uploader uploadUrl=imageUploadUrl
- imageUrl=profile_background
- instantDelete="true"
- type="profile_background"}}
+
+
+
+ {{image-uploader uploadUrl=imageUploadUrl
+ imageUrl=profile_background
+ instantDelete="true"
+ type="profile_background"}}
+
+
+
+
+
+
+ {{image-uploader uploadUrl=imageUploadUrl
+ imageUrl=expansion_background
+ instantDelete="true"
+ type="expansion_background"}}
+
-
{{/if}}
{{#if allowUserLocale}}
diff --git a/app/assets/javascripts/discourse/views/user-expansion.js.es6 b/app/assets/javascripts/discourse/views/user-expansion.js.es6
index 69bcf9b73..328b2e9b7 100644
--- a/app/assets/javascripts/discourse/views/user-expansion.js.es6
+++ b/app/assets/javascripts/discourse/views/user-expansion.js.es6
@@ -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;
diff --git a/app/assets/stylesheets/desktop/poster_expansion.scss b/app/assets/stylesheets/desktop/poster_expansion.scss
index 95a09baca..c16aff2c5 100644
--- a/app/assets/stylesheets/desktop/poster_expansion.scss
+++ b/app/assets/stylesheets/desktop/poster_expansion.scss
@@ -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;
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 4afdadbad..adba1eeca 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -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
diff --git a/app/jobs/scheduled/clean_up_uploads.rb b/app/jobs/scheduled/clean_up_uploads.rb
index dbce58d0e..2588843b0 100644
--- a/app/jobs/scheduled/clean_up_uploads.rb
+++ b/app/jobs/scheduled/clean_up_uploads.rb
@@ -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!
diff --git a/app/models/user_profile.rb b/app/models/user_profile.rb
index c78cee3ef..56e9299da 100644
--- a/app/models/user_profile.rb
+++ b/app/models/user_profile.rb
@@ -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
diff --git a/app/serializers/user_serializer.rb b/app/serializers/user_serializer.rb
index 96f43569a..b15c514ad 100644
--- a/app/serializers/user_serializer.rb
+++ b/app/serializers/user_serializer.rb
@@ -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
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index bc2d79d8b..d2a801324 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -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."
diff --git a/db/migrate/20141016183307_add_expansion_background_to_user_profiles.rb b/db/migrate/20141016183307_add_expansion_background_to_user_profiles.rb
new file mode 100644
index 000000000..af0c536bf
--- /dev/null
+++ b/db/migrate/20141016183307_add_expansion_background_to_user_profiles.rb
@@ -0,0 +1,5 @@
+class AddExpansionBackgroundToUserProfiles < ActiveRecord::Migration
+ def change
+ add_column :user_profiles, :expansion_background, :string, limit: 255
+ end
+end
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb
index 1af534373..0b3d63c45 100644
--- a/spec/controllers/users_controller_spec.rb
+++ b/spec/controllers/users_controller_spec.rb
@@ -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
diff --git a/spec/serializers/user_serializer_spec.rb b/spec/serializers/user_serializer_spec.rb
index 7bdb95a74..e2ca7460c 100644
--- a/spec/serializers/user_serializer_spec.rb
+++ b/spec/serializers/user_serializer_spec.rb
@@ -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'