FIX: Don't use observers to update data

Message bus events were triggering users who didn't have access to
update posts to update them. Instead, perform the update in the action
itself.
This commit is contained in:
Robin Ward 2015-09-03 11:10:04 -04:00
parent 6a25a62e63
commit e53d9f0e8b
2 changed files with 10 additions and 26 deletions

View File

@ -428,20 +428,14 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
}, },
toggleWiki(post) { toggleWiki(post) {
// the request to the server is made in an observer in the post class post.updatePostField('wiki', !post.get('wiki'));
post.toggleProperty('wiki');
}, },
togglePostType(post) { togglePostType(post) {
// the request to the server is made in an observer in the post class const regular = this.site.get('post_types.regular');
const regular = this.site.get('post_types.regular'), const moderator = this.site.get('post_types.moderator_action');
moderator = this.site.get('post_types.moderator_action');
if (post.get("post_type") === moderator) { post.updatePostField('post_type', post.get('post_type') === moderator ? regular : moderator);
post.set("post_type", regular);
} else {
post.set("post_type", moderator);
}
}, },
rebakePost(post) { rebakePost(post) {

View File

@ -83,23 +83,13 @@ const Post = RestModel.extend({
return this.get("user_id") === Discourse.User.currentProp("id") || Discourse.User.currentProp('staff'); return this.get("user_id") === Discourse.User.currentProp("id") || Discourse.User.currentProp('staff');
}.property("user_id"), }.property("user_id"),
wikiChanged: function() { updatePostField(field, value) {
const data = { wiki: this.get("wiki") }; const data = {};
this._updatePost("wiki", data); data[field] = value;
}.observes('wiki'),
postTypeChanged: function () { Discourse.ajax(`/posts/${this.get('id')}/${field}`, { type: 'PUT', data }).then(() => {
const data = { post_type: this.get("post_type") }; this.set(field, value);
this._updatePost("post_type", data); this.incrementProperty("version");
}.observes("post_type"),
_updatePost(field, data) {
const self = this;
Discourse.ajax("/posts/" + this.get("id") + "/" + field, {
type: "PUT",
data: data
}).then(function () {
self.incrementProperty("version");
}).catch(popupAjaxError); }).catch(popupAjaxError);
}, },