mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-02 11:59:17 -05:00
Merge pull request #1380 from ZogStriP/fix-changing-another-user-avatar-changes-your-not-theirs
FIX: changing another user's avatar changes yours
This commit is contained in:
commit
7f185b6a6f
6 changed files with 52 additions and 45 deletions
|
@ -8,39 +8,7 @@
|
||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
Discourse.AvatarSelectorController = Discourse.Controller.extend(Discourse.ModalFunctionality, {
|
Discourse.AvatarSelectorController = Discourse.Controller.extend(Discourse.ModalFunctionality, {
|
||||||
init: function() {
|
|
||||||
// copy some data to support the cancel action
|
|
||||||
this.setProperties(this.get("currentUser").getProperties(
|
|
||||||
"username",
|
|
||||||
"has_uploaded_avatar",
|
|
||||||
"use_uploaded_avatar",
|
|
||||||
"gravatar_template",
|
|
||||||
"uploaded_avatar_template"
|
|
||||||
));
|
|
||||||
},
|
|
||||||
|
|
||||||
toggleUseUploadedAvatar: function(toggle) {
|
toggleUseUploadedAvatar: function(toggle) {
|
||||||
this.set("use_uploaded_avatar", toggle);
|
this.set("use_uploaded_avatar", toggle);
|
||||||
},
|
|
||||||
|
|
||||||
saveAvatarSelection: function() {
|
|
||||||
// sends the information to the server if it has changed
|
|
||||||
if (this.get("use_uploaded_avatar") !== this.get("currentUser.use_uploaded_avatar")) {
|
|
||||||
var data = { use_uploaded_avatar: this.get("use_uploaded_avatar") };
|
|
||||||
Discourse.ajax("/users/" + this.get("currentUser.username") + "/preferences/avatar/toggle", { type: 'PUT', data: data });
|
|
||||||
}
|
|
||||||
// saves the data back to the currentUser object
|
|
||||||
var currentUser = this.get("currentUser");
|
|
||||||
currentUser.setProperties(this.getProperties(
|
|
||||||
"has_uploaded_avatar",
|
|
||||||
"use_uploaded_avatar",
|
|
||||||
"gravatar_template",
|
|
||||||
"uploaded_avatar_template"
|
|
||||||
));
|
|
||||||
if (this.get("use_uploaded_avatar")) {
|
|
||||||
currentUser.set("avatar_template", this.get("uploaded_avatar_template"));
|
|
||||||
} else {
|
|
||||||
currentUser.set("avatar_template", this.get("gravatar_template"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -139,7 +139,7 @@ Discourse.User = Discourse.Model.extend({
|
||||||
**/
|
**/
|
||||||
save: function() {
|
save: function() {
|
||||||
var user = this;
|
var user = this;
|
||||||
return Discourse.ajax("/users/" + this.get('username').toLowerCase(), {
|
return Discourse.ajax("/users/" + this.get('username_lower'), {
|
||||||
data: this.getProperties('auto_track_topics_after_msecs',
|
data: this.getProperties('auto_track_topics_after_msecs',
|
||||||
'bio_raw',
|
'bio_raw',
|
||||||
'website',
|
'website',
|
||||||
|
@ -260,6 +260,17 @@ Discourse.User = Discourse.Model.extend({
|
||||||
user.setProperties(json.user);
|
user.setProperties(json.user);
|
||||||
return user;
|
return user;
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
Change avatar selection
|
||||||
|
|
||||||
|
@method toggleAvatarSelection
|
||||||
|
@returns {Promise} the result of the toggle avatar selection
|
||||||
|
*/
|
||||||
|
toggleAvatarSelection: function() {
|
||||||
|
var data = { use_uploaded_avatar: this.get("use_uploaded_avatar") };
|
||||||
|
return Discourse.ajax("/users/" + this.get("username") + "/preferences/avatar/toggle", { type: 'PUT', data: data });
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -18,7 +18,35 @@ Discourse.PreferencesRoute = Discourse.RestrictedUserRoute.extend({
|
||||||
events: {
|
events: {
|
||||||
showAvatarSelector: function() {
|
showAvatarSelector: function() {
|
||||||
Discourse.Route.showModal(this, 'avatarSelector');
|
Discourse.Route.showModal(this, 'avatarSelector');
|
||||||
this.controllerFor("avatarSelector").init();
|
var user = this.modelFor("user");
|
||||||
|
console.log(user);
|
||||||
|
this.controllerFor("avatarSelector").setProperties(user.getProperties(
|
||||||
|
"username",
|
||||||
|
"email",
|
||||||
|
"has_uploaded_avatar",
|
||||||
|
"use_uploaded_avatar",
|
||||||
|
"gravatar_template",
|
||||||
|
"uploaded_avatar_template"
|
||||||
|
));
|
||||||
|
},
|
||||||
|
|
||||||
|
saveAvatarSelection: function() {
|
||||||
|
var user = this.modelFor("user");
|
||||||
|
var avatar = this.controllerFor("avatarSelector");
|
||||||
|
// sends the information to the server if it has changed
|
||||||
|
if (avatar.get("use_uploaded_avatar") !== user.get("use_uploaded_avatar")) { user.toggleAvatarSelection(); }
|
||||||
|
// saves the data back
|
||||||
|
user.setProperties(avatar.getProperties(
|
||||||
|
"has_uploaded_avatar",
|
||||||
|
"use_uploaded_avatar",
|
||||||
|
"gravatar_template",
|
||||||
|
"uploaded_avatar_template"
|
||||||
|
));
|
||||||
|
if (avatar.get("use_uploaded_avatar")) {
|
||||||
|
user.set("avatar_template", avatar.get("uploaded_avatar_template"));
|
||||||
|
} else {
|
||||||
|
user.set("avatar_template", avatar.get("gravatar_template"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<input type="radio" id="avatar" name="avatar" value="gravatar" {{action toggleUseUploadedAvatar false}}>
|
<input type="radio" id="avatar" name="avatar" value="gravatar" {{action toggleUseUploadedAvatar false}}>
|
||||||
<label class="radio" for="avatar">{{avatar controller imageSize="large" template="gravatar_template"}} {{{i18n user.change_avatar.gravatar}}} {{currentUser.email}}</label>
|
<label class="radio" for="avatar">{{avatar controller imageSize="large" template="gravatar_template"}} {{{i18n user.change_avatar.gravatar}}} {{email}}</label>
|
||||||
<a href="//gravatar.com/emails" target="_blank" title="{{i18n user.change_avatar.gravatar_title}}" class="btn"><i class="icon-pencil"></i></a>
|
<a href="//gravatar.com/emails" target="_blank" title="{{i18n user.change_avatar.gravatar_title}}" class="btn"><i class="icon-pencil"></i></a>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -14,11 +14,7 @@ class CurrentUserSerializer < BasicUserSerializer
|
||||||
:external_links_in_new_tab,
|
:external_links_in_new_tab,
|
||||||
:dynamic_favicon,
|
:dynamic_favicon,
|
||||||
:trust_level,
|
:trust_level,
|
||||||
:can_edit,
|
:can_edit
|
||||||
:use_uploaded_avatar,
|
|
||||||
:has_uploaded_avatar,
|
|
||||||
:gravatar_template,
|
|
||||||
:uploaded_avatar_template
|
|
||||||
|
|
||||||
def include_site_flagged_posts_count?
|
def include_site_flagged_posts_count?
|
||||||
object.staff?
|
object.staff?
|
||||||
|
@ -40,8 +36,4 @@ class CurrentUserSerializer < BasicUserSerializer
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def gravatar_template
|
|
||||||
User.gravatar_template(object.email)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,7 +51,11 @@ class UserSerializer < BasicUserSerializer
|
||||||
:new_topic_duration_minutes,
|
:new_topic_duration_minutes,
|
||||||
:external_links_in_new_tab,
|
:external_links_in_new_tab,
|
||||||
:dynamic_favicon,
|
:dynamic_favicon,
|
||||||
:enable_quoting
|
:enable_quoting,
|
||||||
|
:use_uploaded_avatar,
|
||||||
|
:has_uploaded_avatar,
|
||||||
|
:gravatar_template,
|
||||||
|
:uploaded_avatar_template
|
||||||
|
|
||||||
|
|
||||||
def auto_track_topics_after_msecs
|
def auto_track_topics_after_msecs
|
||||||
|
@ -78,4 +82,8 @@ class UserSerializer < BasicUserSerializer
|
||||||
UserAction.stats(object.id, scope)
|
UserAction.stats(object.id, scope)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def gravatar_template
|
||||||
|
User.gravatar_template(object.email)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue