FIX: deleting a flagged post issue
cf. http://meta.discourse.org/t/deleting-a-flagged-post-issue/10061 The bug was only happening when you were about the delete the first post, which means deleting the entire topic.
This commit is contained in:
parent
7caefded86
commit
af96ef2994
|
@ -46,12 +46,12 @@ Discourse.AdminFlagsController = Ember.ArrayController.extend({
|
|||
Deletes a post
|
||||
|
||||
@method deletePost
|
||||
@param {Discourse.FlaggedPost} item The post to delete
|
||||
@param {Discourse.FlaggedPost} post The post to delete
|
||||
**/
|
||||
deletePost: function(item) {
|
||||
deletePost: function(post) {
|
||||
var adminFlagsController = this;
|
||||
item.deletePost().then((function() {
|
||||
adminFlagsController.removeObject(item);
|
||||
post.deletePost().then((function() {
|
||||
adminFlagsController.removeObject(post);
|
||||
}), function() {
|
||||
bootbox.alert(I18n.t("admin.flags.error"));
|
||||
});
|
||||
|
|
|
@ -66,7 +66,7 @@ Discourse.FlaggedPost = Discourse.Post.extend({
|
|||
}.property('flaggedForSpam'),
|
||||
|
||||
deletePost: function() {
|
||||
if (this.get('post_number') === '1') {
|
||||
if (this.get('post_number') === 1) {
|
||||
return Discourse.ajax('/t/' + this.topic_id, { type: 'DELETE', cache: false });
|
||||
} else {
|
||||
return Discourse.ajax('/posts/' + this.id, { type: 'DELETE', cache: false });
|
||||
|
|
|
@ -75,7 +75,7 @@ Discourse.PostMenuView = Discourse.View.extend({
|
|||
|
||||
if (post.get('post_number') === 1) {
|
||||
|
||||
// If if it's the first post, the delete/undo actions are related to the topic
|
||||
// If it's the first post, the delete/undo actions are related to the topic
|
||||
var topic = post.get('topic');
|
||||
if (topic.get('deleted_at')) {
|
||||
if (!topic.get('details.can_recover')) { return; }
|
||||
|
|
|
@ -154,7 +154,6 @@ class PostsController < ApplicationController
|
|||
raise Discourse::InvalidParameters.new(:post_ids) if posts.blank?
|
||||
|
||||
# Make sure we can delete the posts
|
||||
|
||||
posts.each {|p| guardian.ensure_can_delete!(p) }
|
||||
|
||||
Post.transaction do
|
||||
|
|
|
@ -231,7 +231,7 @@ describe PostsController do
|
|||
update_params.delete(:post)
|
||||
lambda {
|
||||
xhr :put, :update, update_params
|
||||
}.should raise_error(ActionController::ParameterMissing)
|
||||
}.should raise_error(ActionController::ParameterMissing)
|
||||
end
|
||||
|
||||
it "raises an error when the user doesn't have permission to see the post" do
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
module("Discourse.FlaggedPost");
|
||||
|
||||
test('delete first post', function() {
|
||||
this.stub(Discourse, 'ajax');
|
||||
|
||||
Discourse.FlaggedPost.create({ id: 1, topic_id: 2, post_number: 1 })
|
||||
.deletePost();
|
||||
|
||||
ok(Discourse.ajax.calledWith("/t/2", { type: 'DELETE', cache: false }), "it deleted the topic");
|
||||
});
|
||||
|
||||
test('delete second post', function() {
|
||||
this.stub(Discourse, 'ajax');
|
||||
|
||||
Discourse.FlaggedPost.create({ id: 1, topic_id: 2, post_number: 2 })
|
||||
.deletePost();
|
||||
|
||||
ok(Discourse.ajax.calledWith("/posts/1", { type: 'DELETE', cache: false }), "it deleted the post");
|
||||
});
|
Loading…
Reference in New Issue