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,15 +168,15 @@ export default Ember.ObjectController.extend(Presence, {
}.property('model.loading'),
save(force) {
const composer = this.get('model'),
self = this;
const composer = this.get('model');
const self = this;
// Clear the warning state if we're not showing the checkbox anymore
if (!this.get('showWarning')) {
this.set('model.isWarning', false);
}
if(composer.get('cantSubmitPost')) {
if (composer.get('cantSubmitPost')) {
const now = Date.now();
this.setProperties({
'view.showTitleTip': now,

View File

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

View File

@ -584,15 +584,18 @@ const ComposerView = Discourse.View.extend(Ember.Evented, {
}.property('model.categoryId'),
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'),
missingChars = this.get('model.missingReplyCharacters');
missingChars = this.get('model.missingReplyCharacters');
let reason;
if (replyLength < 1) {
reason = I18n.t('composer.error.post_missing');
} else if (missingChars > 0) {
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) {
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'),
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'),
historyHeat: function() {

View File

@ -131,8 +131,14 @@ class PostsController < ApplicationController
changes[:category_id] = params[:post][:category_id] if params[:post][:category_id]
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)
if revisor.revise!(current_user, changes)
if revisor.revise!(current_user, changes, opts)
TopicLink.extract_from(post)
QuotedPost.extract_from(post)
end

View File

@ -306,7 +306,7 @@ describe PostsController do
end
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
end