mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 01:31:35 +08:00
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:
@ -428,20 +428,14 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, {
|
||||
},
|
||||
|
||||
toggleWiki(post) {
|
||||
// the request to the server is made in an observer in the post class
|
||||
post.toggleProperty('wiki');
|
||||
post.updatePostField('wiki', !post.get('wiki'));
|
||||
},
|
||||
|
||||
togglePostType(post) {
|
||||
// the request to the server is made in an observer in the post class
|
||||
const regular = this.site.get('post_types.regular'),
|
||||
moderator = this.site.get('post_types.moderator_action');
|
||||
const regular = this.site.get('post_types.regular');
|
||||
const moderator = this.site.get('post_types.moderator_action');
|
||||
|
||||
if (post.get("post_type") === moderator) {
|
||||
post.set("post_type", regular);
|
||||
} else {
|
||||
post.set("post_type", moderator);
|
||||
}
|
||||
post.updatePostField('post_type', post.get('post_type') === moderator ? regular : moderator);
|
||||
},
|
||||
|
||||
rebakePost(post) {
|
||||
|
@ -83,23 +83,13 @@ const Post = RestModel.extend({
|
||||
return this.get("user_id") === Discourse.User.currentProp("id") || Discourse.User.currentProp('staff');
|
||||
}.property("user_id"),
|
||||
|
||||
wikiChanged: function() {
|
||||
const data = { wiki: this.get("wiki") };
|
||||
this._updatePost("wiki", data);
|
||||
}.observes('wiki'),
|
||||
updatePostField(field, value) {
|
||||
const data = {};
|
||||
data[field] = value;
|
||||
|
||||
postTypeChanged: function () {
|
||||
const data = { post_type: this.get("post_type") };
|
||||
this._updatePost("post_type", data);
|
||||
}.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");
|
||||
Discourse.ajax(`/posts/${this.get('id')}/${field}`, { type: 'PUT', data }).then(() => {
|
||||
this.set(field, value);
|
||||
this.incrementProperty("version");
|
||||
}).catch(popupAjaxError);
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user