FIX: Do not show bootbox if post has no replies. (#7866)

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.
This commit is contained in:
Bianca Nenciu 2019-07-12 12:42:57 +03:00 committed by Régis Hanol
parent 22e2631f29
commit c4d1833588
2 changed files with 49 additions and 0 deletions

View File

@ -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({

View File

@ -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();
});
}
);