mirror of
https://github.com/discourse/discourse.git
synced 2025-03-26 03:55:38 +08:00
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
app
assets/javascripts
controllers
spec/controllers
test/javascripts/admin
@ -46,12 +46,12 @@ Discourse.AdminFlagsController = Ember.ArrayController.extend({
|
|||||||
Deletes a post
|
Deletes a post
|
||||||
|
|
||||||
@method deletePost
|
@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;
|
var adminFlagsController = this;
|
||||||
item.deletePost().then((function() {
|
post.deletePost().then((function() {
|
||||||
adminFlagsController.removeObject(item);
|
adminFlagsController.removeObject(post);
|
||||||
}), function() {
|
}), function() {
|
||||||
bootbox.alert(I18n.t("admin.flags.error"));
|
bootbox.alert(I18n.t("admin.flags.error"));
|
||||||
});
|
});
|
||||||
|
@ -66,7 +66,7 @@ Discourse.FlaggedPost = Discourse.Post.extend({
|
|||||||
}.property('flaggedForSpam'),
|
}.property('flaggedForSpam'),
|
||||||
|
|
||||||
deletePost: function() {
|
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 });
|
return Discourse.ajax('/t/' + this.topic_id, { type: 'DELETE', cache: false });
|
||||||
} else {
|
} else {
|
||||||
return Discourse.ajax('/posts/' + this.id, { type: 'DELETE', cache: false });
|
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 (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');
|
var topic = post.get('topic');
|
||||||
if (topic.get('deleted_at')) {
|
if (topic.get('deleted_at')) {
|
||||||
if (!topic.get('details.can_recover')) { return; }
|
if (!topic.get('details.can_recover')) { return; }
|
||||||
|
@ -154,7 +154,6 @@ class PostsController < ApplicationController
|
|||||||
raise Discourse::InvalidParameters.new(:post_ids) if posts.blank?
|
raise Discourse::InvalidParameters.new(:post_ids) if posts.blank?
|
||||||
|
|
||||||
# Make sure we can delete the posts
|
# Make sure we can delete the posts
|
||||||
|
|
||||||
posts.each {|p| guardian.ensure_can_delete!(p) }
|
posts.each {|p| guardian.ensure_can_delete!(p) }
|
||||||
|
|
||||||
Post.transaction do
|
Post.transaction do
|
||||||
|
@ -231,7 +231,7 @@ describe PostsController do
|
|||||||
update_params.delete(:post)
|
update_params.delete(:post)
|
||||||
lambda {
|
lambda {
|
||||||
xhr :put, :update, update_params
|
xhr :put, :update, update_params
|
||||||
}.should raise_error(ActionController::ParameterMissing)
|
}.should raise_error(ActionController::ParameterMissing)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an error when the user doesn't have permission to see the post" do
|
it "raises an error when the user doesn't have permission to see the post" do
|
||||||
|
19
test/javascripts/admin/models/flagged_post_test.js
Normal file
19
test/javascripts/admin/models/flagged_post_test.js
Normal file
@ -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…
x
Reference in New Issue
Block a user