mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 23:07:28 +08:00
FIX: Don't allow a user to stage a post while another is being staged.
This commit is contained in:
@ -461,7 +461,12 @@ Discourse.Composer = Discourse.Model.extend({
|
|||||||
if (post) {
|
if (post) {
|
||||||
post.set('reply_count', (post.get('reply_count') || 0) + 1);
|
post.set('reply_count', (post.get('reply_count') || 0) + 1);
|
||||||
}
|
}
|
||||||
postStream.stagePost(createdPost, currentUser);
|
if (!postStream.stagePost(createdPost, currentUser)) {
|
||||||
|
|
||||||
|
// If we can't stage the post, return and don't save. We're likely currently
|
||||||
|
// staging a post.
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save callback
|
// Save callback
|
||||||
|
@ -323,15 +323,19 @@ Discourse.PostStream = Em.Object.extend({
|
|||||||
@param {Discourse.User} the user creating the post
|
@param {Discourse.User} the user creating the post
|
||||||
**/
|
**/
|
||||||
stagePost: function(post, user) {
|
stagePost: function(post, user) {
|
||||||
var topic = this.get('topic');
|
|
||||||
|
|
||||||
|
// We can't stage two posts simultaneously
|
||||||
|
if (this.get('stagingPost')) { return false; }
|
||||||
|
|
||||||
|
this.set('stagingPost', true);
|
||||||
|
|
||||||
|
var topic = this.get('topic');
|
||||||
topic.setProperties({
|
topic.setProperties({
|
||||||
posts_count: (topic.get('posts_count') || 0) + 1,
|
posts_count: (topic.get('posts_count') || 0) + 1,
|
||||||
last_posted_at: new Date(),
|
last_posted_at: new Date(),
|
||||||
'details.last_poster': user,
|
'details.last_poster': user,
|
||||||
highest_post_number: (topic.get('highest_post_number') || 0) + 1
|
highest_post_number: (topic.get('highest_post_number') || 0) + 1
|
||||||
});
|
});
|
||||||
this.set('stagingPost', true);
|
|
||||||
|
|
||||||
post.setProperties({
|
post.setProperties({
|
||||||
post_number: topic.get('highest_post_number'),
|
post_number: topic.get('highest_post_number'),
|
||||||
@ -343,6 +347,8 @@ Discourse.PostStream = Em.Object.extend({
|
|||||||
if (this.get('lastPostLoaded')) {
|
if (this.get('lastPostLoaded')) {
|
||||||
this.appendPost(post);
|
this.appendPost(post);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -255,7 +255,8 @@ test("staging and undoing a new post", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Stage the new post in the stream
|
// Stage the new post in the stream
|
||||||
postStream.stagePost(stagedPost, user);
|
var result = postStream.stagePost(stagedPost, user);
|
||||||
|
equal(result, true, "it returns true");
|
||||||
equal(topic.get('highest_post_number'), 2, "it updates the highest_post_number");
|
equal(topic.get('highest_post_number'), 2, "it updates the highest_post_number");
|
||||||
ok(postStream.get('loading'), "it is loading while the post is being staged");
|
ok(postStream.get('loading'), "it is loading while the post is being staged");
|
||||||
|
|
||||||
@ -290,11 +291,15 @@ test("staging and committing a post", function() {
|
|||||||
topic.set('posts_count', 1);
|
topic.set('posts_count', 1);
|
||||||
|
|
||||||
// Stage the new post in the stream
|
// Stage the new post in the stream
|
||||||
postStream.stagePost(stagedPost, user);
|
var result = postStream.stagePost(stagedPost, user);
|
||||||
|
equal(result, true, "it returns true");
|
||||||
ok(postStream.get('loading'), "it is loading while the post is being staged");
|
ok(postStream.get('loading'), "it is loading while the post is being staged");
|
||||||
stagedPost.setProperties({ id: 1234, raw: "different raw value" });
|
stagedPost.setProperties({ id: 1234, raw: "different raw value" });
|
||||||
equal(postStream.get('filteredPostsCount'), 1, "it retains the filteredPostsCount");
|
equal(postStream.get('filteredPostsCount'), 1, "it retains the filteredPostsCount");
|
||||||
|
|
||||||
|
result = postStream.stagePost(stagedPost, user);
|
||||||
|
equal(result, false, "you can't stage a post while it is currently staging");
|
||||||
|
|
||||||
postStream.commitPost(stagedPost);
|
postStream.commitPost(stagedPost);
|
||||||
ok(postStream.get('posts').contains(stagedPost), "the post is still in the stream");
|
ok(postStream.get('posts').contains(stagedPost), "the post is still in the stream");
|
||||||
ok(!postStream.get('loading'), "it is no longer loading");
|
ok(!postStream.get('loading'), "it is no longer loading");
|
||||||
|
Reference in New Issue
Block a user