FIX: allow staff members to restore withdrawn posts that are flagged

This commit is contained in:
Régis Hanol 2014-09-09 20:26:40 +02:00
parent c9dea9ce5c
commit 79030c874e
5 changed files with 29 additions and 31 deletions

View File

@ -2,37 +2,25 @@ import ModalFunctionality from 'discourse/mixins/modal-functionality';
import ObjectController from 'discourse/controllers/object'; import ObjectController from 'discourse/controllers/object';
export default ObjectController.extend(ModalFunctionality, { export default ObjectController.extend(ModalFunctionality, {
needs: ["adminFlags"], needs: ["adminFlags"],
_agreeFlag: function (actionOnPost) {
var adminFlagController = this.get("controllers.adminFlags");
var post = this.get("content");
var self = this;
return post.agreeFlags(actionOnPost).then(function () {
adminFlagController.removeObject(post);
self.send("closeModal");
}, function () {
bootbox.alert(I18n.t("admin.flags.error"));
});
},
actions: { actions: {
agreeFlagHidePost: function () { return this._agreeFlag("hide"); },
agreeFlagHidePost: function () { agreeFlagKeepPost: function () { return this._agreeFlag("keep"); },
var adminFlagController = this.get("controllers.adminFlags"); agreeFlagRestorePost: function () { return this._agreeFlag("restore"); }
var post = this.get("content");
var self = this;
return post.agreeFlags("hide").then(function () {
adminFlagController.removeObject(post);
self.send("closeModal");
}, function () {
bootbox.alert(I18n.t("admin.flags.error"));
});
},
agreeFlagKeepPost: function () {
var adminFlagController = this.get("controllers.adminFlags");
var post = this.get("content");
var self = this;
return post.agreeFlags("keep").then(function () {
adminFlagController.removeObject(post);
self.send("closeModal");
}, function () {
bootbox.alert(I18n.t("admin.flags.error"));
});
}
} }
}); });

View File

@ -1,6 +1,10 @@
{{#unless postHidden}} {{#if user_deleted}}
<button title="{{i18n admin.flags.agree_flag_hide_post_title}}" {{action agreeFlagHidePost}} class="btn"><i class="fa fa-thumbs-o-up"></i><i class="fa fa-eye-slash"></i>{{i18n admin.flags.agree_flag_hide_post}}</button> <button title="{{i18n admin.flags.agree_flag_restore_post_title}}" {{action agreeFlagRestorePost}} class="btn"><i class="fa fa-thumbs-o-up"></i><i class="fa fa-eye"></i>{{i18n admin.flags.agree_flag_restore_post}}</button>
{{/unless}} {{else}}
{{#unless postHidden}}
<button title="{{i18n admin.flags.agree_flag_hide_post_title}}" {{action agreeFlagHidePost}} class="btn"><i class="fa fa-thumbs-o-up"></i><i class="fa fa-eye-slash"></i>{{i18n admin.flags.agree_flag_hide_post}}</button>
{{/unless}}
{{/if}}
<button title="{{i18n admin.flags.agree_flag_title}}" {{action agreeFlagKeepPost}} class="btn"><i class="fa fa-thumbs-o-up"></i>{{i18n admin.flags.agree_flag}}</button> <button title="{{i18n admin.flags.agree_flag_title}}" {{action agreeFlagKeepPost}} class="btn"><i class="fa fa-thumbs-o-up"></i>{{i18n admin.flags.agree_flag}}</button>
{{#if canDeleteAsSpammer}} {{#if canDeleteAsSpammer}}
<button title="{{i18n admin.flags.delete_spammer_title}}" {{action deleteSpammer user}} class="btn btn-danger"><i class="fa fa-exclamation-triangle"></i>{{i18n admin.flags.delete_spammer}}</button> <button title="{{i18n admin.flags.delete_spammer_title}}" {{action deleteSpammer user}} class="btn btn-danger"><i class="fa fa-exclamation-triangle"></i>{{i18n admin.flags.delete_spammer}}</button>

View File

@ -26,11 +26,14 @@ class Admin::FlagsController < Admin::AdminController
keep_post = params[:action_on_post] == "keep" keep_post = params[:action_on_post] == "keep"
delete_post = params[:action_on_post] == "delete" delete_post = params[:action_on_post] == "delete"
restore_post = params[:action_on_post] == "restore"
PostAction.agree_flags!(post, current_user, delete_post) PostAction.agree_flags!(post, current_user, delete_post)
if delete_post if delete_post
PostDestroyer.new(current_user, post).destroy PostDestroyer.new(current_user, post).destroy
elsif restore_post
PostDestroyer.new(current_user, post).recover
elsif !keep_post elsif !keep_post
PostAction.hide_post!(post, post_action_type) PostAction.hide_post!(post, post_action_type)
end end

View File

@ -1498,6 +1498,8 @@ en:
agree_flag_modal_title: "Agree and..." agree_flag_modal_title: "Agree and..."
agree_flag_hide_post: "Agree (hide post + send PM)" agree_flag_hide_post: "Agree (hide post + send PM)"
agree_flag_hide_post_title: "Hide this post and automatically send the user a private message urging them to edit it" agree_flag_hide_post_title: "Hide this post and automatically send the user a private message urging them to edit it"
agree_flag_restore_post: "Agree (restore post)"
agree_flag_restore_post_title: "Restore this post"
agree_flag: "Agree with flag" agree_flag: "Agree with flag"
agree_flag_title: "Agree with flag and keep the post unchanged" agree_flag_title: "Agree with flag and keep the post unchanged"
defer_flag: "Defer" defer_flag: "Defer"

View File

@ -26,6 +26,7 @@ module FlagQuery
p.post_number, p.post_number,
p.hidden, p.hidden,
p.deleted_at, p.deleted_at,
p.user_deleted,
(SELECT created_at FROM post_revisions WHERE post_id = p.id AND user_id = p.user_id ORDER BY created_at DESC LIMIT 1) AS last_revised_at, (SELECT created_at FROM post_revisions WHERE post_id = p.id AND user_id = p.user_id ORDER BY created_at DESC LIMIT 1) AS last_revised_at,
(SELECT COUNT(*) FROM post_actions WHERE (disagreed_at IS NOT NULL OR agreed_at IS NOT NULL OR deferred_at IS NOT NULL) AND post_id = p.id)::int AS previous_flags_count (SELECT COUNT(*) FROM post_actions WHERE (disagreed_at IS NOT NULL OR agreed_at IS NOT NULL OR deferred_at IS NOT NULL) AND post_id = p.id)::int AS previous_flags_count
FROM posts p FROM posts p