diff --git a/app.js b/app.js old mode 100644 new mode 100755 index f03046711b..a40b25f074 --- a/app.js +++ b/app.js @@ -470,6 +470,11 @@ app.post( storyController.commentOnCommentSubmit ); +app.put( + '/stories/comment/:id/edit', + storyController.commentEdit +); + app.get( '/stories/submit', storyController.submitNew diff --git a/controllers/story.js b/controllers/story.js old mode 100644 new mode 100755 index c434e4752a..94d99444f8 --- a/controllers/story.js +++ b/controllers/story.js @@ -441,6 +441,43 @@ exports.commentOnCommentSubmit = function(req, res, next) { commentSave(comment, Comment, res, next); }; +exports.commentEdit = function(req, res, next) { + + Comment.find({'_id': req.params.id}, function(err, cmt) { + if (err) { + return next(err); + } + cmt = cmt.pop(); + + if (!req.user && cmt.author.userId !== req.user._id) { + return next(new Error('Not authorized')); + } + + + var sanitizedBody = sanitizeHtml(req.body.body, { + allowedTags: [], + allowedAttributes: [] + }).replace(/"/g, '"'); + if (req.body.body !== sanitizedBody) { + req.flash('errors', { + msg: 'HTML is not allowed' + }); + return res.send(true); + } + + cmt.body = sanitizedBody; + cmt.commentOn = Date.now(); + cmt.save(function (err) { + if (err) { + return next(err); + } + res.send(true); + }); + + }); + +}; + function commentSave(comment, Context, res, next) { comment.save(function(err, data) { if (err) { diff --git a/public/js/main.js b/public/js/main.js index 8a7be2aa82..59905c18e3 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -298,7 +298,6 @@ $(document).ready(function() { { data: { associatedPost: storyId, - originalStoryLink: originalStoryLink, body: data } }) @@ -314,7 +313,7 @@ $(document).ready(function() { }); var profileValidation = angular.module('profileValidation', - ['ui.bootstrap', 'ngLodash']); + ['ui.bootstrap']); profileValidation.controller('profileValidationController', ['$scope', '$http', function($scope, $http) { $http.get('/account/api').success(function(data) { @@ -393,12 +392,12 @@ profileValidation.directive('uniqueUsername', ['$http', function($http) { }]); profileValidation.directive('existingUsername', - ['$http', 'lodash', function($http, lodash) { + ['$http', function($http) { return { restrict: 'A', require: 'ngModel', link: function (scope, element, attrs, ngModel) { - element.bind("keyup", function (event) { + element.bind('keyup', function (event) { if (element.val().length > 0) { ngModel.$setValidity('exists', false); } else { @@ -406,14 +405,11 @@ profileValidation.directive('existingUsername', ngModel.$setPristine(); } if (element.val()) { - var debo = lodash.debounce(function() { - $http - .get('/api/checkExistingUsername/' + element.val()) - .success(function (data) { - ngModel.$setValidity('exists', data); - }); - }, 2000); - debo(); + $http + .get('/api/checkExistingUsername/' + element.val()) + .success(function (data) { + ngModel.$setValidity('exists', data); + }); } }); } diff --git a/views/stories/comments.jade b/views/stories/comments.jade old mode 100644 new mode 100755 index 3d8b424271..07412b59be --- a/views/stories/comments.jade +++ b/views/stories/comments.jade @@ -21,7 +21,13 @@ success: function (data, textStatus, xhr) { commentDetails = data; var div = document.createElement('div'); - + var editButton = ""; + // todo + if (commentDetails.author.username === DF105CFA89562196E702912B3818C6A5B46E80D262442FDF29976621E5AF0D23) { + if ((Date.now() - commentDetails.commentOn) < 600000){ + editButton = "Edit · "; + } + } $(div) .html( '