Admins can change Edit Comment Window length in Moderation Settings

This commit is contained in:
Benjamin Goering
2017-05-17 15:39:19 -07:00
parent 413eef8834
commit d93ad38dd1
9 changed files with 66 additions and 22 deletions
@@ -96,24 +96,27 @@
}
}
.inlineTextfield {
border-color: #ccc;
border-style: solid;
border-width: 0px 0px 1px 0px;
text-align: center;
font-size: inherit;
}
.inlineTextfield:focus {
outline: none;
}
.charCountTexfield {
width: 4em;
padding: 0px;
border-color: #ccc;
border-style: solid;
border-width: 0px 0px 1px 0px;
font-size: 14px;
text-align: center;
}
.charCountTexfieldEnabled {
border-color: #00796b;
}
.charCountTexfield:focus {
outline: none;
}
.changedSave {
background-color: #00796B;
color: white;
@@ -27,6 +27,12 @@ const ModerationSettings = ({settings, updateSettings, onChangeWordlist}) => {
const on = styles.enabledSetting;
const off = styles.disabledSetting;
const onChangeEditCommentWindowLength = (e) => {
const value = e.target.value;
const valueAsNumber = parseFloat(value);
const milliseconds = (!isNaN(valueAsNumber)) && (valueAsNumber * 1000);
updateSettings({editCommentWindowLength: milliseconds || value});
};
return (
<div className={styles.Configure}>
<Card className={`${styles.configSetting} ${settings.requireEmailConfirmation ? on : off}`}>
@@ -72,6 +78,27 @@ const ModerationSettings = ({settings, updateSettings, onChangeWordlist}) => {
bannedWords={settings.wordlist.banned}
suspectWords={settings.wordlist.suspect}
onChangeWordlist={onChangeWordlist} />
{/* Edit Comment Timeframe */}
<Card className={`${styles.configSetting}`}>
<div className={styles.settingsHeader}>{lang.t('configure.edit-comment-timeframe-heading')}</div>
<p>
{lang.t('configure.edit-comment-timeframe-text-pre')}
&nbsp;
<input
style={{width: '3em'}}
className={styles.inlineTextfield}
type="number"
min="0"
onChange={onChangeEditCommentWindowLength}
placeholder="30"
defaultValue={(settings.editCommentWindowLength / 1000) /* saved as ms, rendered as seconds */}
pattern='[0-9]+([\.][0-9]*)?'
/>
&nbsp;
{lang.t('configure.edit-comment-timeframe-text-post')}
</p>
</Card>
</div>
);
};
@@ -81,7 +81,7 @@ const StreamSettings = ({updateSettings, settingsError, settings, errors}) => {
<p className={settings.charCountEnable ? '' : styles.disabledSettingText}>
<span>{lang.t('configure.comment-count-text-pre')}</span>
<input type='text'
className={`${styles.charCountTexfield} ${settings.charCountEnable && styles.charCountTexfieldEnabled}`}
className={`${styles.inlineTextfield} ${styles.charCountTexfield} ${settings.charCountEnable && styles.charCountTexfieldEnabled}`}
htmlFor='charCount'
onChange={updateCharCount(updateSettings, settingsError)}
value={settings.charCount}
+6
View File
@@ -106,6 +106,9 @@
"include-text": "Include your text here.",
"enable-premod-links": "Pre-Moderate Comments Containing Links",
"enable-premod-links-text": "Moderators must approve any comment containing a link before its published.",
"edit-comment-timeframe-heading": "Edit Comment Timeframe",
"edit-comment-timeframe-text-pre": "Commenters will have",
"edit-comment-timeframe-text-post": "seconds to edit their comments.",
"comment-settings": "Settings",
"embed-comment-stream": "Embed Stream",
"banned-word-text": "Comments which contain these words or phrases (not case-sensitive) will be automatically removed from the comment stream. Type a word and press Enter or Tab to add. Optionally paste a comma-separated list.",
@@ -294,6 +297,9 @@
"embed-comment-stream": "Colocar Hilo de Comentarios",
"enable-premod-links": "Pre-Moderar Commentarios que contienen Enlaces",
"enable-premod-links-text": "Los y las Moderadoras deben aprobar cualquier comentario que contengan links antes de su publicación.",
"edit-comment-timeframe-heading": "Editar Tiempo de Comentario",
"edit-comment-timeframe-text-pre": "Los comentaristas tendrán",
"edit-comment-timeframe-text-post": "segundos para editar sus comentarios.",
"wordlist": "Palabras Suspendidas y Sospechosas",
"banned-word-text": "Comentarios que contengan estas palabras o frases, no separadas por comas y en mayusculas o minusuculas, serán automaticamente marcadas para separar los comentarios publicados.",
"suspect-word-text": "Comentarios que contengan estas palabras o frases, considerando mayusculas y minusculas, serán automaticamente destacadas en los comentarios publicados. Escribir una palabra y apretar Enter o Tabulador para agergarla. Opcionalmente pegar una lista separada por coma.",
@@ -200,7 +200,11 @@ const extension = {
variables: {id, edit},
}) => ({
updateQueries: {
EmbedQuery: (previousData, {mutationResult: {data: {editComment: {comment: {status}}}}}) => {
EmbedQuery: (previousData, {mutationResult: {data: {editComment: {comment, errors}}}}) => {
if (errors && errors.length) {
return previousData;
}
const {status} = comment;
const updateCommentWithEdit = (comment, edit) => {
const {body} = edit;
const editedComment = update(comment, {
+4 -2
View File
@@ -48,10 +48,12 @@ const Comment = {
asset({asset_id}, _, {loaders: {Assets}}) {
return Assets.getByID.load(asset_id);
},
editing(comment) {
async editing(comment, _, {loaders: {Settings}}) {
const settings = await Settings.load();
const editableUntil = new Date(Number(comment.created_at) + settings.editCommentWindowLength);
return {
edited: comment.edited,
editableUntil: comment.editableUntil
editableUntil: editableUntil
};
}
};
-7
View File
@@ -2,8 +2,6 @@ const mongoose = require('../services/mongoose');
const Schema = mongoose.Schema;
const uuid = require('uuid');
const EDIT_WINDOW_MS = 30 * 1000; // 30 seconds
const STATUSES = [
'ACCEPTED',
'REJECTED',
@@ -113,12 +111,7 @@ CommentSchema.virtual('edited').get(function() {
return this.body_history.length > 1;
});
CommentSchema.virtual('editableUntil').get(function() {
return new Date(Number(this.created_at) + EDIT_WINDOW_MS);
});
// Comment model.
const Comment = mongoose.model('Comment', CommentSchema);
module.exports = Comment;
module.exports.EDIT_WINDOW_MS = EDIT_WINDOW_MS;
+7
View File
@@ -88,6 +88,13 @@ const SettingSchema = new Schema({
type: Array,
default: ['localhost']
}
},
// Length of time (in milliseconds) after a comment is posted that it can still be edited by the author
editCommentWindowLength: {
type: Number,
min: [0, 'Edit Comment Window length must be greater than zero'],
default: 30 * 1000,
}
}, {
timestamps: {
+4 -2
View File
@@ -1,8 +1,8 @@
const CommentModel = require('../models/comment');
const EDIT_WINDOW_MS = CommentModel.EDIT_WINDOW_MS;
const ActionModel = require('../models/action');
const ActionsService = require('./actions');
const SettingsService = require('./settings');
const errors = require('../errors');
@@ -53,8 +53,10 @@ module.exports = class CommentsService {
// Establish the edit window (if it exists) and add the condition to the
// original query.
const lastEditableCommentCreatedAt = new Date((new Date()).getTime() - EDIT_WINDOW_MS);
let lastEditableCommentCreatedAt;
if (!ignoreEditWindow) {
const editWindowMs = (await SettingsService.retrieve()).editCommentWindowLength;
lastEditableCommentCreatedAt = new Date((new Date()).getTime() - editWindowMs);
query.created_at = {
$gt: lastEditableCommentCreatedAt,
};