FIX: Moderation actions can have their messages removed

This commit is contained in:
Robin Ward 2015-07-28 16:58:56 -04:00
parent 510813769f
commit 5f45e5361f
6 changed files with 20 additions and 13 deletions

View File

@ -168,8 +168,8 @@ export default Ember.ObjectController.extend(Presence, {
}.property('model.loading'), }.property('model.loading'),
save(force) { save(force) {
const composer = this.get('model'), const composer = this.get('model');
self = this; const self = this;
// Clear the warning state if we're not showing the checkbox anymore // Clear the warning state if we're not showing the checkbox anymore
if (!this.get('showWarning')) { if (!this.get('showWarning')) {

View File

@ -114,6 +114,7 @@ const Composer = RestModel.extend({
// whether to disable the post button // whether to disable the post button
cantSubmitPost: function() { cantSubmitPost: function() {
// can't submit while loading // can't submit while loading
if (this.get('loading')) return true; if (this.get('loading')) return true;
@ -199,12 +200,9 @@ const Composer = RestModel.extend({
} }
}.property('privateMessage'), }.property('privateMessage'),
/**
Number of missing characters in the reply until valid.
@property missingReplyCharacters
**/
missingReplyCharacters: function() { missingReplyCharacters: function() {
const postType = this.get('post.post_type');
if (postType === this.site.get('post_types.small_action')) { return 0; }
return this.get('minimumPostLength') - this.get('replyLength'); return this.get('minimumPostLength') - this.get('replyLength');
}.property('minimumPostLength', 'replyLength'), }.property('minimumPostLength', 'replyLength'),

View File

@ -584,6 +584,9 @@ const ComposerView = Discourse.View.extend(Ember.Evented, {
}.property('model.categoryId'), }.property('model.categoryId'),
replyValidation: function() { replyValidation: function() {
const postType = this.get('model.post.post_type');
if (postType === this.site.get('post_types.small_action')) { return; }
const replyLength = this.get('model.replyLength'), const replyLength = this.get('model.replyLength'),
missingChars = this.get('model.missingReplyCharacters'); missingChars = this.get('model.missingReplyCharacters');
@ -592,7 +595,7 @@ const ComposerView = Discourse.View.extend(Ember.Evented, {
reason = I18n.t('composer.error.post_missing'); reason = I18n.t('composer.error.post_missing');
} else if (missingChars > 0) { } else if (missingChars > 0) {
reason = I18n.t('composer.error.post_length', {min: this.get('model.minimumPostLength')}); reason = I18n.t('composer.error.post_length', {min: this.get('model.minimumPostLength')});
let tl = Discourse.User.currentProp("trust_level"); const tl = Discourse.User.currentProp("trust_level");
if (tl === 0 || tl === 1) { if (tl === 0 || tl === 1) {
reason += "<br/>" + I18n.t('composer.error.try_like'); reason += "<br/>" + I18n.t('composer.error.try_like');
} }

View File

@ -13,7 +13,7 @@ const PostView = Discourse.GroupedView.extend(Ember.Evented, {
post: Ember.computed.alias('content'), post: Ember.computed.alias('content'),
templateName: function() { templateName: function() {
return (this.get('post.post_type') === 3) ? 'post-small-action' : 'post'; return (this.get('post.post_type') === this.site.get('post_types.small_action')) ? 'post-small-action' : 'post';
}.property('post.post_type'), }.property('post.post_type'),
historyHeat: function() { historyHeat: function() {

View File

@ -131,8 +131,14 @@ class PostsController < ApplicationController
changes[:category_id] = params[:post][:category_id] if params[:post][:category_id] changes[:category_id] = params[:post][:category_id] if params[:post][:category_id]
end end
# We don't need to validate edits to small action posts by staff
opts = {}
if post.post_type == Post.types[:small_action] && current_user.staff?
opts[:skip_validations] = true
end
revisor = PostRevisor.new(post) revisor = PostRevisor.new(post)
if revisor.revise!(current_user, changes) if revisor.revise!(current_user, changes, opts)
TopicLink.extract_from(post) TopicLink.extract_from(post)
QuotedPost.extract_from(post) QuotedPost.extract_from(post)
end end

View File

@ -306,7 +306,7 @@ describe PostsController do
end end
it "calls revise with valid parameters" do it "calls revise with valid parameters" do
PostRevisor.any_instance.expects(:revise!).with(post.user, { raw: 'edited body' , edit_reason: 'typo' }) PostRevisor.any_instance.expects(:revise!).with(post.user, { raw: 'edited body' , edit_reason: 'typo' }, anything)
xhr :put, :update, update_params xhr :put, :update, update_params
end end