Skip to content

Commit

Permalink
Prevent empty spaced commenting and topics
Browse files Browse the repository at this point in the history
* Basic statusCodePage for those users who are accidentally/intentionally putting in blank comments... applies to OpenUserJS#37
* Some missed Apps Hungarian from OpenUserJS#264 ... there's probably more. ;)
* Some STYLEGUIDE.md conformance with braces, newlines and indention
* Stray trailing comma fix
* Flip Cancel and Reply buttons... this may be some of the accidents with empty comments. Most likely when someone is going full screen they might be clicking reply on touch screens... favor canceling instead of replying if that's the case
  • Loading branch information
Martii committed Jan 30, 2015
1 parent 4e2166c commit cf4fa8c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
39 changes: 30 additions & 9 deletions controllers/discussion.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,9 @@ function postTopic(aUser, aCategory, aTopic, aContent, aIssue, aCallback) {
var params = { sort: {} };
params.sort.duplicateId = -1;

if (!urlTopic) { aCallback(null); }
if (!urlTopic) {
aCallback(null);
}

Discussion.findOne({ path: path }, null, params, function (aErr, aDiscussion) {
var newDiscussion = null;
Expand Down Expand Up @@ -414,8 +416,9 @@ exports.createTopic = function (aReq, aRes, aNext) {
var content = aReq.body['comment-content'];

var category = _.findWhere(categories, { slug: categorySlug });
if (!category)
if (!category) {
return aNext();
}

//
var options = {};
Expand All @@ -428,7 +431,14 @@ exports.createTopic = function (aReq, aRes, aNext) {
if (!category.canUserPostTopic(authedUser)) {
return statusCodePage(aReq, aRes, aNext, {
statusCode: 403,
statusMessage: 'You cannot post a topic to this category',
statusMessage: 'You cannot post a topic to this category'
});
}

if ((!topic || !topic.trim()) || (!content || !content.trim())) {
return statusCodePage(aReq, aRes, aNext, {
statusCode: 403,
statusMessage: 'You cannot post an empty discussion topic to this category'
});
}

Expand All @@ -447,14 +457,25 @@ exports.createComment = function (aReq, aRes, aNext) {
var authedUser = aReq.session.user;
var content = aReq.body['comment-content'];

if (!authedUser) { return aNext(); }
if (!authedUser) {
return aNext();
}

findDiscussion(category, topic, function (discussion) {
if (!discussion) { return aNext(); }
findDiscussion(category, topic, function (aDiscussion) {
if (!aDiscussion) {
return aNext();
}

if (!content || !content.trim()) {
return statusCodePage(aReq, aRes, aNext, {
statusCode: 403,
statusMessage: 'You cannot post an empty comment to this discussion'
});
}

postComment(authedUser, discussion, content, false, function (err, discussion) {
aRes.redirect(encodeURI(discussion.path
+ (discussion.duplicateId ? '_' + discussion.duplicateId : '')));
postComment(authedUser, aDiscussion, content, false, function (aErr, aDiscussion) {
aRes.redirect(encodeURI(aDiscussion.path
+ (aDiscussion.duplicateId ? '_' + aDiscussion.duplicateId : '')));
});
});
};
26 changes: 23 additions & 3 deletions controllers/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var scriptStorage = require('./scriptStorage');
var discussionLib = require('./discussion');
var execQueryTask = require('../libs/tasks').execQueryTask;
var countTask = require('../libs/tasks').countTask;
var statusCodePage = require('../libs/templateHelpers').statusCodePage;
var pageMetadata = require('../libs/templateHelpers').pageMetadata;
var orderDir = require('../libs/templateHelpers').orderDir;

Expand Down Expand Up @@ -284,6 +285,14 @@ exports.open = function (aReq, aRes, aNext) {
options.category = category;

if (topic && content) {
if (!topic.trim() || !content.trim()) {
return statusCodePage(aReq, aRes, aNext, {
statusCode: 403,
statusMessage: 'You cannot post an empty issue topic to this ' +
(type === 'libs' ? 'library' : 'script')
});
}

// Issue Submission
discussionLib.postTopic(authedUser, category.slug, topic, content, true,
function (aDiscussion) {
Expand Down Expand Up @@ -315,12 +324,23 @@ exports.comment = function (aReq, aRes, aNext) {

Script.findOne({ installName: scriptStorage.caseInsensitive(installName
+ (type === 'libs' ? '.js' : '.user.js')) }, function (aErr, aScript) {
var content = aReq.body['comment-content'];
var content = aReq.body['comment-content'];

if (aErr || !aScript) { return aNext(); }
if (aErr || !aScript) {
return aNext();
}

if (!content || !content.trim()) {
return statusCodePage(aReq, aRes, aNext, {
statusCode: 403,
statusMessage: 'You cannot post an empty comment to this issue'
});
}

discussionLib.findDiscussion(category, topic, function (aIssue) {
if (!aIssue) { return aNext(); }
if (!aIssue) {
return aNext();
}

discussionLib.postComment(authedUser, aIssue, content, false,
function (aErr, aDiscussion) {
Expand Down
2 changes: 1 addition & 1 deletion views/includes/commentForm.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<form action="{{{discussion.discussionPageUrl}}}" method="post">
<div class="container-fluid row user-content">
<div class="submit-panel pull-right btn-toolbar">
<button class="btn btn-sm btn-success" type="submit"><i class="fa fa-reply"></i> Reply</button>
<button class="btn btn-sm btn-danger" type="button" data-toggle="collapse" data-target="#reply-control"><i class="fa fa-close"></i> Cancel</button>
<button class="btn btn-sm btn-success" type="submit"><i class="fa fa-reply"></i> Reply</button>
</div>
<textarea name="comment-content" data-provide="markdown" data-iconlibrary="fa" class="col-xs-12" placeholder="Type here using Markdown."></textarea>
</div>
Expand Down

0 comments on commit cf4fa8c

Please sign in to comment.