Add warning input to flag dialog

Added isWarning property
pass is_warning along to post_action
Added is_warning to possible arguments to receive from post_actions route
Only show warning checkbox for staff
Only permit the is_warning argument if the user is staff
This commit is contained in:
cpradio 2016-04-03 11:33:56 -04:00
parent b0f4c9ec43
commit b4f4cf794b
7 changed files with 23 additions and 2 deletions

View File

@ -5,6 +5,7 @@ export default Ember.Controller.extend({
needs: ['flag'],
message: Em.computed.alias('controllers.flag.message'),
isWarning: Em.computed.alias('controllers.flag.isWarning'),
customPlaceholder: function(){
return I18n.t("flagging.custom_placeholder_" + this.get('model.name_key'));

View File

@ -7,6 +7,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
selected: null,
flagTopic: null,
message: null,
isWarning: false,
topicActionByName: null,
onShow() {
@ -97,7 +98,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
postAction = this.get('topicActionByName.' + this.get('selected.name_key'));
}
let params = this.get('selected.is_custom_flag') ? {message: this.get('message')} : {};
let params = this.get('selected.is_custom_flag') ? {message: this.get('message') } : {};
if (opts) { params = $.extend(params, opts); }
this.send('hideModal');
@ -118,6 +119,11 @@ export default Ember.Controller.extend(ModalFunctionality, {
});
},
createFlagAsWarning() {
this.send('createFlag', {isWarning: true});
this.set('model.hidden', true);
},
changePostActionType(action) {
this.set('selected', action);
},
@ -133,6 +139,12 @@ export default Ember.Controller.extend(ModalFunctionality, {
}
}.property('selected.name_key', 'userDetails.can_be_deleted', 'userDetails.can_delete_all_posts'),
canSendWarning: function() {
if (this.get("flagTopic")) return false;
return (Discourse.User.currentProp('staff') && this.get('selected.name_key') === 'notify_user');
}.property('selected.name_key'),
usernameChanged: function() {
this.set('userDetails', null);
this.fetchUserDetails();

View File

@ -59,6 +59,7 @@ export default RestModel.extend({
id: this.get('flagTopic') ? this.get('flagTopic.id') : post.get('id'),
post_action_type_id: this.get('id'),
message: opts.message,
is_warning: opts.isWarning,
take_action: opts.takeAction,
flag_topic: this.get('flagTopic') ? true : false
},

View File

@ -38,6 +38,10 @@
<div class="modal-footer">
<button class='btn btn-primary' {{action "createFlag"}} {{bind-attr disabled="submitDisabled"}} title="{{i18n 'flagging.submit_tooltip'}}">{{{submitText}}}</button>
{{#if canSendWarning}}
<button class="btn btn-danger" {{action "createFlagAsWarning" }} {{bind-attr disabled="submitDisabled"}} title="{{i18n 'flagging.official_warning'}}"><i class="fa fa-exclamation-triangle"></i> {{i18n 'flagging.official_warning'}}</button>
{{/if}}
{{#if canTakeAction}}
<button class='btn btn-danger' {{action "takeAction"}} {{bind-attr disabled="submitDisabled"}} title="{{i18n 'flagging.take_action_tooltip'}}"><i class="fa fa-gavel"></i>{{i18n 'flagging.take_action'}}</button>
{{/if}}

View File

@ -11,6 +11,7 @@ class PostActionsController < ApplicationController
args = {}
args[:message] = params[:message] if params[:message].present?
args[:is_warning] = params[:is_warning] if params[:is_warning].present? && guardian.is_staff?
args[:take_action] = true if guardian.is_staff? && params[:take_action] == 'true'
args[:flag_topic] = true if params[:flag_topic] == 'true'

View File

@ -215,11 +215,12 @@ SQL
title = I18n.t("post_action_types.#{post_action_type}.email_title", title: post.topic.title)
body = I18n.t("post_action_types.#{post_action_type}.email_body", message: opts[:message], link: "#{Discourse.base_url}#{post.url}")
warning = opts[:is_warning] if opts[:is_warning].present?
title = title.truncate(255, separator: /\s/)
opts = {
archetype: Archetype.private_message,
is_warning: warning,
title: title,
raw: body
}

View File

@ -1753,6 +1753,7 @@ en:
action: 'Flag Post'
take_action: "Take Action"
notify_action: 'Message'
official_warning: 'Official Warning'
delete_spammer: "Delete Spammer"
delete_confirm: "You are about to delete <b>%{posts}</b> posts and <b>%{topics}</b> topics from this user, remove their account, block signups from their IP address <b>%{ip_address}</b>, and add their email address <b>%{email}</b> to a permanent block list. Are you sure this user is really a spammer?"
yes_delete_spammer: "Yes, Delete Spammer"