diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6 index 77ef47499a3..571e9bf6518 100644 --- a/app/assets/javascripts/discourse/controllers/topic.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic.js.es6 @@ -397,6 +397,10 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, { rebakePost: function (post) { post.rebake(); + }, + + unhidePost: function (post) { + post.unhide(); } }, @@ -512,30 +516,30 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, { } var postStream = topicController.get('postStream'); - if (data.type === "revised" || data.type === "acted") { - // TODO we could update less data for "acted" - // (only post actions) - postStream.triggerChangedPost(data.id, data.updated_at); - return; + switch (data.type) { + case "revised": + case "acted": + case "rebaked": { + // TODO we could update less data for "acted" (only post actions) + postStream.triggerChangedPost(data.id, data.updated_at); + return; + } + case "deleted": { + postStream.triggerDeletedPost(data.id, data.post_number); + return; + } + case "recovered": { + postStream.triggerRecoveredPost(data.id, data.post_number); + return; + } + case "created": { + postStream.triggerNewPostInStream(data.id); + return; + } + default: { + Em.Logger.warn("unknown topic bus message type", data); + } } - - if (data.type === "deleted") { - postStream.triggerDeletedPost(data.id, data.post_number); - return; - } - - if (data.type === "recovered") { - postStream.triggerRecoveredPost(data.id, data.post_number); - return; - } - - if (data.type === "created") { - postStream.triggerNewPostInStream(data.id); - return; - } - - // log a warning - Em.Logger.warn("unknown topic bus message type", data); }); }, diff --git a/app/assets/javascripts/discourse/models/_post.js b/app/assets/javascripts/discourse/models/_post.js index 5afb2491887..eeeb86eae7a 100644 --- a/app/assets/javascripts/discourse/models/_post.js +++ b/app/assets/javascripts/discourse/models/_post.js @@ -404,6 +404,10 @@ Discourse.Post = Discourse.Model.extend({ rebake: function () { return Discourse.ajax("/posts/" + this.get("id") + "/rebake", { type: "PUT" }); + }, + + unhide: function () { + return Discourse.ajax("/posts/" + this.get("id") + "/unhide", { type: "PUT" }); } }); diff --git a/app/assets/javascripts/discourse/views/post-menu.js.es6 b/app/assets/javascripts/discourse/views/post-menu.js.es6 index f8e66106121..81d51729289 100644 --- a/app/assets/javascripts/discourse/views/post-menu.js.es6 +++ b/app/assets/javascripts/discourse/views/post-menu.js.es6 @@ -287,12 +287,16 @@ export default Discourse.View.extend({ var rebakePostIcon = '', rebakePostText = I18n.t('post.controls.rebake'); + var unhidePostIcon = '', + unhidePostText = I18n.t('post.controls.unhide'); + var html = '
' + '

' + I18n.t('admin_title') + '

' + '' + '
'; @@ -317,6 +321,10 @@ export default Discourse.View.extend({ this.get("controller").send("rebakePost", this.get("post")); }, + clickUnhidePost: function () { + this.get("controller").send("unhidePost", this.get("post")); + }, + buttonForShowMoreActions: function() { return new Button('showMoreActions', 'show_more', 'ellipsis-h'); }, diff --git a/app/assets/stylesheets/common/base/topic-post.scss b/app/assets/stylesheets/common/base/topic-post.scss index 82b269d1e56..7e4cc8b641f 100644 --- a/app/assets/stylesheets/common/base/topic-post.scss +++ b/app/assets/stylesheets/common/base/topic-post.scss @@ -162,4 +162,4 @@ kbd padding: .1em .6em; * * { display: none; } -} \ No newline at end of file +} diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 105623a8d1c..dab90386676 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -261,6 +261,16 @@ class PostsController < ApplicationController render nothing: true end + def unhide + post = find_post_from_params + + guardian.ensure_can_unhide!(post) + + post.unhide! + + render nothing: true + end + def flagged_posts params.permit(:offset, :limit) guardian.ensure_can_see_flagged_posts! diff --git a/app/models/post.rb b/app/models/post.rb index 34451ba120d..6dab76e33f2 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -293,6 +293,7 @@ class Post < ActiveRecord::Base self.update_attributes(hidden: false, hidden_at: nil, hidden_reason_id: nil) self.topic.update_attributes(visible: true) save(validate: false) + publish_change_to_clients!(:acted) end def url @@ -352,6 +353,8 @@ class Post < ActiveRecord::Base # make sure we trigger the post process trigger_post_process(true) + publish_change_to_clients!(:rebaked) + new_cooked != old_cooked end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 165f3b2766a..8aa94aa20eb 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1112,6 +1112,7 @@ en: convert_to_moderator: "Add Staff Color" revert_to_regular: "Remove Staff Color" rebake: "Rebuild HTML" + unhide: "Unhide" actions: flag: 'Flag' diff --git a/config/routes.rb b/config/routes.rb index aaf51b3f8d8..81e2aa88b5b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -265,6 +265,7 @@ Discourse::Application.routes.draw do put "wiki" put "post_type" put "rebake" + put "unhide" get "replies" get "revisions/:revision" => "posts#revisions" put "recover" diff --git a/lib/guardian/post_guardian.rb b/lib/guardian/post_guardian.rb index 4e3af29e5ab..901e641d7f6 100644 --- a/lib/guardian/post_guardian.rb +++ b/lib/guardian/post_guardian.rb @@ -184,4 +184,8 @@ module PostGuardian def can_see_deleted_posts? is_staff? end + + def can_unhide?(post) + post.try(:hidden) && is_staff? + end end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 9ce2533c860..6f0dbc52475 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -823,6 +823,8 @@ describe Post do Post.exec_sql("UPDATE posts SET cooked = 'frogs' WHERE id = ?", post.id) post.reload + post.expects(:publish_change_to_clients!).with(:rebaked) + result = post.rebake! post.baked_at.should_not == first_baked @@ -857,6 +859,8 @@ describe Post do post.hidden.should == true + post.expects(:publish_change_to_clients!).with(:acted) + post.unhide! post.reload