Skip to content

Commit

Permalink
FIX: Do not show bootbox if post has no replies. (#7866)
Browse files Browse the repository at this point in the history
When we delete a post that has replies, we show a modal asking if the user wants to delete the post, the post and its direct replies or the post and all its replies.

If replies are deleted before a post, that modal would ask the user if they want to delete the post and 0 replies.

That commit ensure we skip the modal and directly delete the post in this case.
  • Loading branch information
nbianca authored and ZogStriP committed Jul 12, 2019
1 parent 22e2631 commit c4d1833
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/assets/javascripts/discourse/controllers/topic.js.es6
Expand Up @@ -523,6 +523,16 @@ export default Ember.Controller.extend(bufferedProperty("model"), {

if (user.get("staff") && hasReplies) {
ajax(`/posts/${post.id}/reply-ids.json`).then(replies => {
if (replies.length === 0) {
return post
.destroy(user)
.then(refresh)
.catch(error => {
popupAjaxError(error);
post.undoDeleteState();
});
}

const buttons = [];

buttons.push({
Expand Down
39 changes: 39 additions & 0 deletions test/javascripts/controllers/topic-test.js.es6
Expand Up @@ -511,3 +511,42 @@ QUnit.test("topVisibleChanged", function(assert) {
"it should work with a post-placehodler"
);
});

QUnit.test(
"deletePost - no modal is shown if post does not have replies",
function(assert) {
/* global server */
server.get("/posts/2/reply-ids.json", () => {
return [200, { "Content-Type": "application/json" }, []];
});

let destroyed;
const post = Ember.Object.create({
id: 2,
post_number: 2,
can_delete: true,
reply_count: 3,
destroy: () => {
destroyed = true;
return Ember.RSVP.Promise.resolve();
}
});

const postStream = Ember.Object.create({
stream: [2, 3, 4],
posts: [post, { id: 3 }, { id: 4 }]
});

const currentUser = Ember.Object.create({ staff: true });
const model = Topic.create({ postStream });
const controller = this.subject({ model, currentUser });

const done = assert.async();
controller.send("deletePost", post);

Ember.run.next(() => {
assert.ok(destroyed, "post was destroyed");
done();
});
}
);

0 comments on commit c4d1833

Please sign in to comment.