FEATURE: staff option to unhide a post

This commit is contained in:
Régis Hanol 2014-09-22 18:55:13 +02:00
parent e8522e839b
commit 0b13f6572f
10 changed files with 63 additions and 24 deletions

View file

@ -397,6 +397,10 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, {
rebakePost: function (post) { rebakePost: function (post) {
post.rebake(); post.rebake();
},
unhidePost: function (post) {
post.unhide();
} }
}, },
@ -512,30 +516,30 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, {
} }
var postStream = topicController.get('postStream'); var postStream = topicController.get('postStream');
if (data.type === "revised" || data.type === "acted") { switch (data.type) {
// TODO we could update less data for "acted" case "revised":
// (only post actions) case "acted":
case "rebaked": {
// TODO we could update less data for "acted" (only post actions)
postStream.triggerChangedPost(data.id, data.updated_at); postStream.triggerChangedPost(data.id, data.updated_at);
return; return;
} }
case "deleted": {
if (data.type === "deleted") {
postStream.triggerDeletedPost(data.id, data.post_number); postStream.triggerDeletedPost(data.id, data.post_number);
return; return;
} }
case "recovered": {
if (data.type === "recovered") {
postStream.triggerRecoveredPost(data.id, data.post_number); postStream.triggerRecoveredPost(data.id, data.post_number);
return; return;
} }
case "created": {
if (data.type === "created") {
postStream.triggerNewPostInStream(data.id); postStream.triggerNewPostInStream(data.id);
return; return;
} }
default: {
// log a warning
Em.Logger.warn("unknown topic bus message type", data); Em.Logger.warn("unknown topic bus message type", data);
}
}
}); });
}, },

View file

@ -404,6 +404,10 @@ Discourse.Post = Discourse.Model.extend({
rebake: function () { rebake: function () {
return Discourse.ajax("/posts/" + this.get("id") + "/rebake", { type: "PUT" }); return Discourse.ajax("/posts/" + this.get("id") + "/rebake", { type: "PUT" });
},
unhide: function () {
return Discourse.ajax("/posts/" + this.get("id") + "/unhide", { type: "PUT" });
} }
}); });

View file

@ -287,12 +287,16 @@ export default Discourse.View.extend({
var rebakePostIcon = '<i class="fa fa-cog"></i>', var rebakePostIcon = '<i class="fa fa-cog"></i>',
rebakePostText = I18n.t('post.controls.rebake'); rebakePostText = I18n.t('post.controls.rebake');
var unhidePostIcon = '<i class="fa fa-eye"></i>',
unhidePostText = I18n.t('post.controls.unhide');
var html = '<div class="post-admin-menu">' + var html = '<div class="post-admin-menu">' +
'<h3>' + I18n.t('admin_title') + '</h3>' + '<h3>' + I18n.t('admin_title') + '</h3>' +
'<ul>' + '<ul>' +
'<li class="btn btn-admin" data-action="toggleWiki">' + wikiIcon + wikiText + '</li>' + '<li class="btn btn-admin" data-action="toggleWiki">' + wikiIcon + wikiText + '</li>' +
'<li class="btn btn-admin" data-action="togglePostType">' + postTypeIcon + postTypeText + '</li>' + '<li class="btn btn-admin" data-action="togglePostType">' + postTypeIcon + postTypeText + '</li>' +
'<li class="btn btn-admin" data-action="rebakePost">' + rebakePostIcon + rebakePostText + '</li>' + '<li class="btn btn-admin" data-action="rebakePost">' + rebakePostIcon + rebakePostText + '</li>' +
(post.hidden ? '<li class="btn btn-admin" data-action="unhidePost">' + unhidePostIcon + unhidePostText + '</li>' : '') +
'</ul>' + '</ul>' +
'</div>'; '</div>';
@ -317,6 +321,10 @@ export default Discourse.View.extend({
this.get("controller").send("rebakePost", this.get("post")); this.get("controller").send("rebakePost", this.get("post"));
}, },
clickUnhidePost: function () {
this.get("controller").send("unhidePost", this.get("post"));
},
buttonForShowMoreActions: function() { buttonForShowMoreActions: function() {
return new Button('showMoreActions', 'show_more', 'ellipsis-h'); return new Button('showMoreActions', 'show_more', 'ellipsis-h');
}, },

View file

@ -261,6 +261,16 @@ class PostsController < ApplicationController
render nothing: true render nothing: true
end end
def unhide
post = find_post_from_params
guardian.ensure_can_unhide!(post)
post.unhide!
render nothing: true
end
def flagged_posts def flagged_posts
params.permit(:offset, :limit) params.permit(:offset, :limit)
guardian.ensure_can_see_flagged_posts! guardian.ensure_can_see_flagged_posts!

View file

@ -293,6 +293,7 @@ class Post < ActiveRecord::Base
self.update_attributes(hidden: false, hidden_at: nil, hidden_reason_id: nil) self.update_attributes(hidden: false, hidden_at: nil, hidden_reason_id: nil)
self.topic.update_attributes(visible: true) self.topic.update_attributes(visible: true)
save(validate: false) save(validate: false)
publish_change_to_clients!(:acted)
end end
def url def url
@ -352,6 +353,8 @@ class Post < ActiveRecord::Base
# make sure we trigger the post process # make sure we trigger the post process
trigger_post_process(true) trigger_post_process(true)
publish_change_to_clients!(:rebaked)
new_cooked != old_cooked new_cooked != old_cooked
end end

View file

@ -1112,6 +1112,7 @@ en:
convert_to_moderator: "Add Staff Color" convert_to_moderator: "Add Staff Color"
revert_to_regular: "Remove Staff Color" revert_to_regular: "Remove Staff Color"
rebake: "Rebuild HTML" rebake: "Rebuild HTML"
unhide: "Unhide"
actions: actions:
flag: 'Flag' flag: 'Flag'

View file

@ -265,6 +265,7 @@ Discourse::Application.routes.draw do
put "wiki" put "wiki"
put "post_type" put "post_type"
put "rebake" put "rebake"
put "unhide"
get "replies" get "replies"
get "revisions/:revision" => "posts#revisions" get "revisions/:revision" => "posts#revisions"
put "recover" put "recover"

View file

@ -184,4 +184,8 @@ module PostGuardian
def can_see_deleted_posts? def can_see_deleted_posts?
is_staff? is_staff?
end end
def can_unhide?(post)
post.try(:hidden) && is_staff?
end
end end

View file

@ -823,6 +823,8 @@ describe Post do
Post.exec_sql("UPDATE posts SET cooked = 'frogs' WHERE id = ?", post.id) Post.exec_sql("UPDATE posts SET cooked = 'frogs' WHERE id = ?", post.id)
post.reload post.reload
post.expects(:publish_change_to_clients!).with(:rebaked)
result = post.rebake! result = post.rebake!
post.baked_at.should_not == first_baked post.baked_at.should_not == first_baked
@ -857,6 +859,8 @@ describe Post do
post.hidden.should == true post.hidden.should == true
post.expects(:publish_change_to_clients!).with(:acted)
post.unhide! post.unhide!
post.reload post.reload