FEATURE: add 'rebake post' in post wrench menu

This commit is contained in:
Régis Hanol 2014-09-11 16:04:40 +02:00
parent 6ca5a9b82c
commit e56fcf0c43
9 changed files with 90 additions and 2 deletions

View file

@ -393,6 +393,10 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, {
} else { } else {
post.set("post_type", moderator); post.set("post_type", moderator);
} }
},
rebakePost: function (post) {
post.rebake();
} }
}, },

View file

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

View file

@ -284,11 +284,15 @@ export default Discourse.View.extend({
postTypeIcon = '<i class="fa fa-shield"></i>', postTypeIcon = '<i class="fa fa-shield"></i>',
postTypeText = isModerator ? I18n.t('post.controls.revert_to_regular') : I18n.t('post.controls.convert_to_moderator'); postTypeText = isModerator ? I18n.t('post.controls.revert_to_regular') : I18n.t('post.controls.convert_to_moderator');
var rebakePostIcon = '<i class="fa fa-cog"></i>',
rebakePostText = I18n.t('post.controls.rebake');
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>' +
'</ul>' + '</ul>' +
'</div>'; '</div>';
@ -309,6 +313,10 @@ export default Discourse.View.extend({
this.get("controller").send("togglePostType", this.get("post")); this.get("controller").send("togglePostType", this.get("post"));
}, },
clickRebakePost: function () {
this.get("controller").send("rebakePost", 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

@ -54,7 +54,7 @@ Discourse.PostView = Discourse.GroupedView.extend(Ember.Evented, {
} }
var $adminMenu = this.get('adminMenu'); var $adminMenu = this.get('adminMenu');
if ($adminMenu && !$(e.target).is($adminMenu) && $adminMenu.has($(e.target)).length === 0) { if ($adminMenu && !$(e.target).is($adminMenu)) {
$adminMenu.hide(); $adminMenu.hide();
this.set('adminMenu', null); this.set('adminMenu', null);
} }

View file

@ -252,6 +252,15 @@ class PostsController < ApplicationController
render nothing: true render nothing: true
end end
def rebake
guardian.ensure_can_rebake!
post = find_post_from_params
post.rebake!(invalidate_oneboxes: true)
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

@ -1111,6 +1111,7 @@ en:
unwiki: "Unwiki post" unwiki: "Unwiki post"
revert_to_regular: "Regular post" revert_to_regular: "Regular post"
convert_to_moderator: "Staff post" convert_to_moderator: "Staff post"
rebake: "Rebake post"
actions: actions:
flag: 'Flag' flag: 'Flag'

View file

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

View file

@ -169,6 +169,10 @@ module PostGuardian
is_staff? is_staff?
end end
def can_rebake?
is_staff?
end
def can_see_flagged_posts? def can_see_flagged_posts?
is_staff? is_staff?
end end

View file

@ -327,7 +327,7 @@ describe PostsController do
let(:user) {log_in} let(:user) {log_in}
let(:post) {Fabricate(:post, user: user)} let(:post) {Fabricate(:post, user: user)}
it "raises an error if the user doesn't have permission to see the post" do it "raises an error if the user doesn't have permission to wiki the post" do
Guardian.any_instance.expects(:can_wiki?).returns(false) Guardian.any_instance.expects(:can_wiki?).returns(false)
xhr :put, :wiki, post_id: post.id, wiki: 'true' xhr :put, :wiki, post_id: post.id, wiki: 'true'
@ -358,6 +358,63 @@ describe PostsController do
end end
describe "post_type" do
include_examples "action requires login", :put, :post_type, post_id: 2
describe "when logged in" do
let(:user) {log_in}
let(:post) {Fabricate(:post, user: user)}
it "raises an error if the user doesn't have permission to change the post type" do
Guardian.any_instance.expects(:can_change_post_type?).returns(false)
xhr :put, :post_type, post_id: post.id, post_type: 2
response.should be_forbidden
end
it "can change the post type" do
Guardian.any_instance.expects(:can_change_post_type?).returns(true)
xhr :put, :post_type, post_id: post.id, post_type: 2
post.reload
post.post_type.should == 2
end
end
end
describe "rebake" do
include_examples "action requires login", :put, :rebake, post_id: 2
describe "when logged in" do
let(:user) {log_in}
let(:post) {Fabricate(:post, user: user)}
it "raises an error if the user doesn't have permission to rebake the post" do
Guardian.any_instance.expects(:can_rebake?).returns(false)
xhr :put, :rebake, post_id: post.id
response.should be_forbidden
end
it "can rebake the post" do
Guardian.any_instance.expects(:can_rebake?).returns(true)
xhr :put, :rebake, post_id: post.id
response.should be_success
end
end
end
describe 'creating a post' do describe 'creating a post' do
include_examples 'action requires login', :post, :create include_examples 'action requires login', :post, :create