mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
closes #705
This commit is contained in:
@@ -340,6 +340,7 @@ define(['taskbar'], function(taskbar) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
composer.post = function(post_uuid) {
|
composer.post = function(post_uuid) {
|
||||||
var postData = composer.posts[post_uuid],
|
var postData = composer.posts[post_uuid],
|
||||||
postContainer = $('#cmp-uuid-' + post_uuid),
|
postContainer = $('#cmp-uuid-' + post_uuid),
|
||||||
@@ -350,33 +351,13 @@ define(['taskbar'], function(taskbar) {
|
|||||||
bodyEl.val(bodyEl.val().trim());
|
bodyEl.val(bodyEl.val().trim());
|
||||||
|
|
||||||
if(postData.uploadsInProgress && postData.uploadsInProgress.length) {
|
if(postData.uploadsInProgress && postData.uploadsInProgress.length) {
|
||||||
return app.alert({
|
return composerAlert('Still uploading', 'Please wait for uploads to complete.');
|
||||||
type: 'warning',
|
} else if (titleEl.val().length < parseInt(config.minimumTitleLength, 10)) {
|
||||||
timeout: 2000,
|
return composerAlert('Title too short', 'Please enter a longer title. At least ' + config.minimumTitleLength+ ' characters.');
|
||||||
title: 'Still uploading',
|
} else if (titleEl.val().length > parseInt(config.maximumTitleLength, 10)) {
|
||||||
message: "Please wait for uploads to complete.",
|
return composerAlert('Title too long', 'Please enter a shorter title. Titles can\'t be longer than ' + config.maximumTitleLength + ' characters.');
|
||||||
alert_id: 'post_error'
|
} else if (bodyEl.val().length < parseInt(config.minimumPostLength, 10)) {
|
||||||
});
|
return composerAlert('Content too short', 'Please enter a longer post. At least ' + config.minimumPostLength + ' characters.');
|
||||||
}
|
|
||||||
|
|
||||||
if (titleEl.val().length < config.minimumTitleLength) {
|
|
||||||
return app.alert({
|
|
||||||
type: 'danger',
|
|
||||||
timeout: 2000,
|
|
||||||
title: 'Title too short',
|
|
||||||
message: "Please enter a longer title. At least " + config.minimumTitleLength+ " characters.",
|
|
||||||
alert_id: 'post_error'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bodyEl.val().length < config.minimumPostLength) {
|
|
||||||
return app.alert({
|
|
||||||
type: 'danger',
|
|
||||||
timeout: 2000,
|
|
||||||
title: 'Content too short',
|
|
||||||
message: "Please enter a longer post. At least " + config.minimumPostLength + " characters.",
|
|
||||||
alert_id: 'post_error'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Still here? Let's post.
|
// Still here? Let's post.
|
||||||
@@ -402,6 +383,17 @@ define(['taskbar'], function(taskbar) {
|
|||||||
composer.discard(post_uuid);
|
composer.discard(post_uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function composerAlert(title, message) {
|
||||||
|
app.alert({
|
||||||
|
type: 'danger',
|
||||||
|
timeout: 2000,
|
||||||
|
title: title,
|
||||||
|
message: message,
|
||||||
|
alert_id: 'post_error'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
composer.discard = function(post_uuid) {
|
composer.discard = function(post_uuid) {
|
||||||
if (composer.posts[post_uuid]) {
|
if (composer.posts[post_uuid]) {
|
||||||
$('#cmp-uuid-' + post_uuid).remove();
|
$('#cmp-uuid-' + post_uuid).remove();
|
||||||
|
|||||||
@@ -215,6 +215,9 @@ var async = require('async'),
|
|||||||
}, {
|
}, {
|
||||||
field: 'minimumTitleLength',
|
field: 'minimumTitleLength',
|
||||||
value: 3
|
value: 3
|
||||||
|
}, {
|
||||||
|
field: 'maximumTitleLength',
|
||||||
|
value: 255
|
||||||
}, {
|
}, {
|
||||||
field: 'minimumUsernameLength',
|
field: 'minimumUsernameLength',
|
||||||
value: 2
|
value: 2
|
||||||
|
|||||||
19
src/posts.js
19
src/posts.js
@@ -356,25 +356,6 @@ var db = require('./database'),
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Posts.emitContentTooShortAlert = function(socket) {
|
|
||||||
socket.emit('event:alert', {
|
|
||||||
type: 'danger',
|
|
||||||
timeout: 2000,
|
|
||||||
title: 'Content too short',
|
|
||||||
message: "Please enter a longer post. At least " + meta.config.minimumPostLength + " characters.",
|
|
||||||
alert_id: 'post_error'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Posts.emitTooManyPostsAlert = function(socket) {
|
|
||||||
socket.emit('event:alert', {
|
|
||||||
title: 'Too many posts!',
|
|
||||||
message: 'You can only post every ' + meta.config.postDelay + ' seconds.',
|
|
||||||
type: 'danger',
|
|
||||||
timeout: 2000
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Posts.uploadPostImage = function(image, callback) {
|
Posts.uploadPostImage = function(image, callback) {
|
||||||
|
|
||||||
if(!image) {
|
if(!image) {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ var path = require('path'),
|
|||||||
|
|
||||||
config.postDelay = meta.config.postDelay;
|
config.postDelay = meta.config.postDelay;
|
||||||
config.minimumTitleLength = meta.config.minimumTitleLength;
|
config.minimumTitleLength = meta.config.minimumTitleLength;
|
||||||
|
config.maximumTitleLength = meta.config.maximumTitleLength;
|
||||||
config.minimumPostLength = meta.config.minimumPostLength;
|
config.minimumPostLength = meta.config.minimumPostLength;
|
||||||
config.imgurClientIDSet = !! meta.config.imgurClientID;
|
config.imgurClientIDSet = !! meta.config.imgurClientID;
|
||||||
config.minimumUsernameLength = meta.config.minimumUsernameLength;
|
config.minimumUsernameLength = meta.config.minimumUsernameLength;
|
||||||
|
|||||||
@@ -81,6 +81,33 @@ Upgrade.upgrade = function(callback) {
|
|||||||
winston.info('[2013/12/31] Re-slugify Topics and Users skipped');
|
winston.info('[2013/12/31] Re-slugify Topics and Users skipped');
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
thisSchemaDate = new Date(2014, 0, 1).getTime();
|
||||||
|
if (schemaDate < thisSchemaDate) {
|
||||||
|
updatesMade = true;
|
||||||
|
|
||||||
|
db.isObjectField('config', 'maximumTitleLength', function(err, isField) {
|
||||||
|
if(err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
if(!isField) {
|
||||||
|
db.setObjectField('config', 'maximumTitleLength', 255, function(err) {
|
||||||
|
if(err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
winston.info('[2013/12/31] Added maximumTitleLength');
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
winston.info('[2013/12/31] maximumTitleLength already set');
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
winston.info('[2013/12/31] maximumTitleLength skipped');
|
||||||
|
next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Add new schema updates here
|
// Add new schema updates here
|
||||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 17!!!
|
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 17!!!
|
||||||
|
|||||||
@@ -362,6 +362,35 @@ websockets.init = function(io) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function emitAlert(socket, title, message) {
|
||||||
|
socket.emit('event:alert', {
|
||||||
|
type: 'danger',
|
||||||
|
timeout: 2000,
|
||||||
|
title: title,
|
||||||
|
message: message,
|
||||||
|
alert_id: 'post_error'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitContentTooShortAlert(socket) {
|
||||||
|
socket.emit('event:alert', {
|
||||||
|
type: 'danger',
|
||||||
|
timeout: 2000,
|
||||||
|
title: 'Content too short',
|
||||||
|
message: "Please enter a longer post. At least " + meta.config.minimumPostLength + " characters.",
|
||||||
|
alert_id: 'post_error'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitTooManyPostsAlert(socket) {
|
||||||
|
socket.emit('event:alert', {
|
||||||
|
title: 'Too many posts!',
|
||||||
|
message: 'You can only post every ' + meta.config.postDelay + ' seconds.',
|
||||||
|
type: 'danger',
|
||||||
|
timeout: 2000
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
socket.on('api:topics.post', function(data) {
|
socket.on('api:topics.post', function(data) {
|
||||||
if (uid < 1 && parseInt(meta.config.allowGuestPosting, 10) === 0) {
|
if (uid < 1 && parseInt(meta.config.allowGuestPosting, 10) === 0) {
|
||||||
socket.emit('event:alert', {
|
socket.emit('event:alert', {
|
||||||
@@ -376,11 +405,13 @@ websockets.init = function(io) {
|
|||||||
topics.post(uid, data.title, data.content, data.category_id, function(err, result) {
|
topics.post(uid, data.title, data.content, data.category_id, function(err, result) {
|
||||||
if(err) {
|
if(err) {
|
||||||
if (err.message === 'title-too-short') {
|
if (err.message === 'title-too-short') {
|
||||||
topics.emitTitleTooShortAlert(socket);
|
emitAlert(socket, 'Title too short', 'Please enter a longer title. At least ' + meta.config.minimumTitleLength + ' characters.');
|
||||||
|
} else if (err.message === 'title-too-long') {
|
||||||
|
emitAlert(socket, 'Title too long', 'Please enter a shorter title. Titles can\'t be longer than ' + meta.config.maximumTitleLength + ' characters.');
|
||||||
} else if (err.message === 'content-too-short') {
|
} else if (err.message === 'content-too-short') {
|
||||||
posts.emitContentTooShortAlert(socket);
|
emitContentTooShortAlert(socket);
|
||||||
} else if (err.message === 'too-many-posts') {
|
} else if (err.message === 'too-many-posts') {
|
||||||
posts.emitTooManyPostsAlert(socket);
|
emitTooManyPostsAlert(socket);
|
||||||
} else if (err.message === 'no-privileges') {
|
} else if (err.message === 'no-privileges') {
|
||||||
socket.emit('event:alert', {
|
socket.emit('event:alert', {
|
||||||
title: 'Unable to post',
|
title: 'Unable to post',
|
||||||
@@ -445,16 +476,16 @@ websockets.init = function(io) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (Date.now() - lastPostTime < meta.config.postDelay * 1000) {
|
if (Date.now() - lastPostTime < meta.config.postDelay * 1000) {
|
||||||
posts.emitTooManyPostsAlert(socket);
|
emitTooManyPostsAlert(socket);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
topics.reply(data.topic_id, uid, data.content, function(err, postData) {
|
topics.reply(data.topic_id, uid, data.content, function(err, postData) {
|
||||||
if(err) {
|
if(err) {
|
||||||
if (err.message === 'content-too-short') {
|
if (err.message === 'content-too-short') {
|
||||||
posts.emitContentTooShortAlert(socket);
|
emitContentTooShortAlert(socket);
|
||||||
} else if (err.message === 'too-many-posts') {
|
} else if (err.message === 'too-many-posts') {
|
||||||
posts.emitTooManyPostsAlert(socket);
|
emitTooManyPostsAlert(socket);
|
||||||
} else if (err.message === 'reply-error') {
|
} else if (err.message === 'reply-error') {
|
||||||
socket.emit('event:alert', {
|
socket.emit('event:alert', {
|
||||||
title: 'Reply Unsuccessful',
|
title: 'Reply Unsuccessful',
|
||||||
@@ -628,7 +659,7 @@ websockets.init = function(io) {
|
|||||||
topics.emitTitleTooShortAlert(socket);
|
topics.emitTitleTooShortAlert(socket);
|
||||||
return;
|
return;
|
||||||
} else if (!data.content || data.content.length < parseInt(meta.config.minimumPostLength, 10)) {
|
} else if (!data.content || data.content.length < parseInt(meta.config.minimumPostLength, 10)) {
|
||||||
posts.emitContentTooShortAlert(socket);
|
emitContentTooShortAlert(socket);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user