From 8c4524458bfb5ba85a8845acb11337637fd55aaa Mon Sep 17 00:00:00 2001 From: Martii Date: Wed, 11 Oct 2017 06:04:59 -0600 Subject: [PATCH] Start tracking and showing browser used to post comments * Converted the bullet to an icon from *font-awesome* * We can make the `background-image` set to an image at some point with `color: transparent;`. Fits within current constraints. e.g. pretty when we add fair use icons *(tried one of mine hard-coded already)* * The other site shows the full agent and I guess it's not as much of a privacy risk... weighing in more on beneficial to not having to ask "What browser are you using" for support. It is somewhat cosmetic but somewhat useful save for those spoofing which is why it's discrete * UA shows up on tooltip only, if available, to keep it more discrete. Current shows `n/a` if not collected, and always showing *(prefer this personally esp. when `edited` gets completed)* since this commit starts collection. Applies to #764 and modification of #601 --- controllers/discussion.js | 15 ++++++++++----- controllers/issue.js | 6 ++++-- models/comment.js | 1 + public/css/common.css | 6 ++++++ views/includes/comment.html | 3 ++- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/controllers/discussion.js b/controllers/discussion.js index 0631e4293..cef9645f3 100644 --- a/controllers/discussion.js +++ b/controllers/discussion.js @@ -410,13 +410,14 @@ exports.newTopic = function (aReq, aRes, aNext) { }; // Does all the work of submitting a new comment and updating the discussion -function postComment(aUser, aDiscussion, aContent, aCreator, aCallback) { +function postComment(aUser, aDiscussion, aContent, aCreator, aUserAgent, aCallback) { var created = new Date(); var comment = new Comment({ content: aContent, author: aUser.name, created: created, rating: 0, + userAgent: aUserAgent, creator: aCreator, flags: { critical: 0, absolute: 0 }, flagged: false, @@ -436,7 +437,7 @@ exports.postComment = postComment; // Does all the work of submitting a new topic and // resolving topic url collisions -function postTopic(aUser, aCategory, aTopic, aContent, aIssue, aCallback) { +function postTopic(aUser, aCategory, aTopic, aContent, aIssue, aUserAgent, aCallback) { var urlTopic = cleanFilename(aTopic, '').replace(/_\d+$/, ''); var path = '/' + aCategory + '/' + urlTopic; var params = { sort: {} }; @@ -479,7 +480,7 @@ function postTopic(aUser, aCategory, aTopic, aContent, aIssue, aCallback) { newDiscussion.save(function (aErr, aDiscussion) { // Now post the first comment - postComment(aUser, aDiscussion, aContent, true, function (aErr, aDiscussion) { + postComment(aUser, aDiscussion, aContent, true, aUserAgent, function (aErr, aDiscussion) { aCallback(aDiscussion); }); }); @@ -496,6 +497,7 @@ exports.createTopic = function (aReq, aRes, aNext) { var authedUser = aReq.session.user; var topic = aReq.body['discussion-topic']; var content = aReq.body['comment-content']; + var userAgent = aReq.headers['user-agent']; if (!category) { aNext(); @@ -523,7 +525,7 @@ exports.createTopic = function (aReq, aRes, aNext) { return; } - postTopic(authedUser, category.slug, topic, content, false, function (aDiscussion) { + postTopic(authedUser, category.slug, topic, content, false, userAgent, function (aDiscussion) { if (!aDiscussion) { exports.newTopic(aReq, aRes, aNext); return; @@ -551,6 +553,7 @@ exports.createComment = function (aReq, aRes, aNext) { findDiscussion(category, topic, function (aDiscussion) { // var content = aReq.body['comment-content']; + var userAgent = aReq.headers['user-agent']; if (!aDiscussion) { aNext(); @@ -565,7 +568,9 @@ exports.createComment = function (aReq, aRes, aNext) { return; } - postComment(authedUser, aDiscussion, content, false, function (aErr, aDiscussion) { + + + postComment(authedUser, aDiscussion, content, false, userAgent, function (aErr, aDiscussion) { aRes.redirect(aDiscussion.path.split('/').map(function (aStr) { return encodeURIComponent(aStr); }).join('/') + diff --git a/controllers/issue.js b/controllers/issue.js index b2cf228d9..8422791b2 100644 --- a/controllers/issue.js +++ b/controllers/issue.js @@ -345,6 +345,7 @@ exports.open = function (aReq, aRes, aNext) { var category = null; var topic = aReq.body['discussion-topic']; var content = aReq.body['comment-content']; + var userAgent = aReq.headers['user-agent']; var tasks = []; // Session @@ -377,7 +378,7 @@ exports.open = function (aReq, aRes, aNext) { } // Issue Submission - discussionLib.postTopic(authedUser, category.slug, topic, content, true, + discussionLib.postTopic(authedUser, category.slug, topic, content, true, userAgent, function (aDiscussion) { if (!aDiscussion) { aRes.redirect('/' + category.slugUri + '/open'); @@ -407,6 +408,7 @@ exports.comment = function (aReq, aRes, aNext) { // var installNameBase = scriptStorage.getInstallNameBase(aReq); var type = aReq.params.type; + var userAgent = aReq.headers['user-agent']; Script.findOne({ installName: scriptStorage.caseSensitive(installNameBase + @@ -439,7 +441,7 @@ exports.comment = function (aReq, aRes, aNext) { return; } - discussionLib.postComment(authedUser, aIssue, content, false, + discussionLib.postComment(authedUser, aIssue, content, false, userAgent, function (aErr, aDiscussion) { aRes.redirect(aDiscussion.path.split('/').map(function (aStr) { return encodeURIComponent(aStr); diff --git a/models/comment.js b/models/comment.js index a875e7f9d..e0f0addc9 100644 --- a/models/comment.js +++ b/models/comment.js @@ -18,6 +18,7 @@ var commentSchema = new Schema({ created: Date, rating: Number, updated: Date, + userAgent: String, // Moderation creator: Boolean, diff --git a/public/css/common.css b/public/css/common.css index e0154eb2f..c0e9bd126 100644 --- a/public/css/common.css +++ b/public/css/common.css @@ -373,3 +373,9 @@ ul.flaggedList { .form-inline { display: inline; } + +.user-agent { + cursor: default; + width: 16px; + height: 16px; +} diff --git a/views/includes/comment.html b/views/includes/comment.html index 4cd50466c..817a4be3e 100644 --- a/views/includes/comment.html +++ b/views/includes/comment.html @@ -15,8 +15,9 @@
{{#isUpdated}} - + {{/isUpdated}} +