mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FIX: Don't allow a user to stage a post while another is being staged.
This commit is contained in:
parent
d98f288aa4
commit
efd631296e
3 changed files with 21 additions and 5 deletions
|
@ -461,7 +461,12 @@ Discourse.Composer = Discourse.Model.extend({
|
|||
if (post) {
|
||||
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
|
||||
|
|
|
@ -323,15 +323,19 @@ Discourse.PostStream = Em.Object.extend({
|
|||
@param {Discourse.User} the user creating the post
|
||||
**/
|
||||
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({
|
||||
posts_count: (topic.get('posts_count') || 0) + 1,
|
||||
last_posted_at: new Date(),
|
||||
'details.last_poster': user,
|
||||
highest_post_number: (topic.get('highest_post_number') || 0) + 1
|
||||
});
|
||||
this.set('stagingPost', true);
|
||||
|
||||
post.setProperties({
|
||||
post_number: topic.get('highest_post_number'),
|
||||
|
@ -343,6 +347,8 @@ Discourse.PostStream = Em.Object.extend({
|
|||
if (this.get('lastPostLoaded')) {
|
||||
this.appendPost(post);
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -255,7 +255,8 @@ test("staging and undoing a new post", function() {
|
|||
});
|
||||
|
||||
// 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");
|
||||
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);
|
||||
|
||||
// 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");
|
||||
stagedPost.setProperties({ id: 1234, raw: "different raw value" });
|
||||
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);
|
||||
ok(postStream.get('posts').contains(stagedPost), "the post is still in the stream");
|
||||
ok(!postStream.get('loading'), "it is no longer loading");
|
||||
|
|
Loading…
Reference in a new issue