mirror of
https://github.com/discourse/discourse.git
synced 2025-06-10 05:23:44 +08:00
Correct post deletion spec so it is async
This commit is contained in:
@ -159,6 +159,7 @@ const Post = RestModel.extend({
|
|||||||
done elsewhere.
|
done elsewhere.
|
||||||
**/
|
**/
|
||||||
setDeletedState(deletedBy) {
|
setDeletedState(deletedBy) {
|
||||||
|
let promise;
|
||||||
this.set('oldCooked', this.get('cooked'));
|
this.set('oldCooked', this.get('cooked'));
|
||||||
|
|
||||||
// Moderators can delete posts. Users can only trigger a deleted at message, unless delete_removed_posts_after is 0.
|
// Moderators can delete posts. Users can only trigger a deleted at message, unless delete_removed_posts_after is 0.
|
||||||
@ -169,8 +170,7 @@ const Post = RestModel.extend({
|
|||||||
can_delete: false
|
can_delete: false
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
promise = cookAsync(I18n.t("post.deleted_by_author", {count: Discourse.SiteSettings.delete_removed_posts_after})).then(cooked => {
|
||||||
cookAsync(I18n.t("post.deleted_by_author", {count: Discourse.SiteSettings.delete_removed_posts_after})).then(cooked => {
|
|
||||||
this.setProperties({
|
this.setProperties({
|
||||||
cooked: cooked,
|
cooked: cooked,
|
||||||
can_delete: false,
|
can_delete: false,
|
||||||
@ -181,6 +181,8 @@ const Post = RestModel.extend({
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return promise || Em.RSVP.Promise.resolve();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -203,11 +205,12 @@ const Post = RestModel.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
destroy(deletedBy) {
|
destroy(deletedBy) {
|
||||||
this.setDeletedState(deletedBy);
|
return this.setDeletedState(deletedBy).then(()=>{
|
||||||
return ajax("/posts/" + this.get('id'), {
|
return ajax("/posts/" + this.get('id'), {
|
||||||
data: { context: window.location.pathname },
|
data: { context: window.location.pathname },
|
||||||
type: 'DELETE'
|
type: 'DELETE'
|
||||||
});
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,9 +64,9 @@ QUnit.test('destroy by non-staff', assert => {
|
|||||||
user = Discourse.User.create({username: 'evil trout'}),
|
user = Discourse.User.create({username: 'evil trout'}),
|
||||||
post = buildPost({user: user, cooked: originalCooked});
|
post = buildPost({user: user, cooked: originalCooked});
|
||||||
|
|
||||||
post.destroy(user);
|
return post.destroy(user).then(() => {
|
||||||
|
|
||||||
assert.ok(!post.get('can_delete'), "the post can't be deleted again in this session");
|
assert.ok(!post.get('can_delete'), "the post can't be deleted again in this session");
|
||||||
assert.ok(post.get('cooked') !== originalCooked, "the cooked content changed");
|
assert.ok(post.get('cooked') !== originalCooked, "the cooked content changed");
|
||||||
assert.equal(post.get('version'), 2, "the version number increased");
|
assert.equal(post.get('version'), 2, "the version number increased");
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
Reference in New Issue
Block a user