FIX: Properly associate user_profiles background urls via upload id.

`Upload#url` is more likely and can change from time to time. When it
does changes, we don't want to have to look through multiple tables to
ensure that the URLs are all up to date. Instead, we simply associate
uploads properly to `UserProfile` so that it does not have to replicate
the URLs in the table.
This commit is contained in:
Guo Xiang Tan
2019-04-29 11:58:52 +08:00
committed by Guo Xiang Tan
parent c9f6beba05
commit 24347ace10
39 changed files with 360 additions and 384 deletions

View File

@@ -131,7 +131,7 @@ export default Ember.Component.extend(
}
},
@observes("user.card_background")
@observes("user.card_background_upload_url")
addBackground() {
if (!this.get("allowBackgrounds")) {
return;
@@ -142,7 +142,7 @@ export default Ember.Component.extend(
return;
}
const url = this.get("user.card_background");
const url = this.get("user.card_background_upload_url");
const bg = Ember.isEmpty(url)
? ""
: `url(${Discourse.getURLWithCDN(url)})`;

View File

@@ -10,8 +10,8 @@ export default Ember.Controller.extend(PreferencesTabController, {
"location",
"custom_fields",
"user_fields",
"profile_background",
"card_background",
"profile_background_upload_url",
"card_background_upload_url",
"date_of_birth"
],

View File

@@ -21,8 +21,8 @@ export default Ember.Controller.extend(CanCheckEmails, {
return !profileHidden && viewingSelf;
},
@computed("model.profileBackground")
hasProfileBackground(background) {
@computed("model.profileBackgroundUrl")
hasProfileBackgroundUrl(background) {
return !Ember.isEmpty(background.toString());
},

View File

@@ -77,8 +77,8 @@ const User = RestModel.extend({
return username;
},
@computed("profile_background")
profileBackground(bgUrl) {
@computed("profile_background_upload_url")
profileBackgroundUrl(bgUrl) {
if (
Ember.isEmpty(bgUrl) ||
!Discourse.SiteSettings.allow_profile_backgrounds
@@ -250,8 +250,8 @@ const User = RestModel.extend({
"user_fields",
"muted_usernames",
"ignored_usernames",
"profile_background",
"card_background",
"profile_background_upload_url",
"card_background_upload_url",
"muted_tags",
"tracked_tags",
"watched_tags",

View File

@@ -32,7 +32,8 @@
<div class="control-group pref-profile-bg">
<label class="control-label">{{i18n 'user.change_profile_background.title'}}</label>
<div class="controls">
{{image-uploader imageUrl=model.profile_background type="profile_background"}}
{{image-uploader imageUrl=model.profile_background_upload_url
type="profile_background"}}
</div>
<div class='instructions'>
{{i18n 'user.change_profile_background.instructions'}}
@@ -42,7 +43,8 @@
<div class="control-group pref-profile-bg">
<label class="control-label">{{i18n 'user.change_card_background.title'}}</label>
<div class="controls">
{{image-uploader imageUrl=model.card_background type="card_background"}}
{{image-uploader imageUrl=model.card_background_upload_url
type="card_background"}}
</div>
<div class='instructions'>
{{i18n 'user.change_card_background.instructions'}}

View File

@@ -1,7 +1,7 @@
<div class="container {{if viewingSelf 'viewing-self'}}">
{{#d-section class="user-main"}}
<section class="{{if collapsedInfo 'collapsed-info'}} about {{if hasProfileBackground 'has-background' 'no-background'}}" >
<section class="{{if collapsedInfo 'collapsed-info'}} about {{if hasProfileBackgroundUrl 'has-background' 'no-background'}}" >
{{#unless collapsedInfo}}
{{#if showStaffCounters}}
<div class='staff-counters'>
@@ -34,7 +34,7 @@
{{/if}}
</div>
{{/if}}
<div class="user-profile-image" style={{model.profileBackground}}></div>
<div class="user-profile-image" style={{model.profileBackgroundUrl}}></div>
{{/unless}}
<div class='details'>