Commit 2d9e53ee authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Add log entries when comments are deleted.

Previously only editing the comment was logged, but logging the deletion
and undo of deletion are quite important too.
parent 8b44f7b1
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -293,11 +293,7 @@ app.post('/auth/:sdk/:version/comments/:commentId', util.requireLoggedInUser, ut
            comment.content = req.body.content;
            comment.contentHtml = util.markdown(req.body.content);

            comment.updates = comment.updates || [];
            comment.updates.push({
                updatedAt: String(new Date()),
                author: req.session.user.username
            });
            util.logUpdate(comment, req.session.user.username);

            comment.save(function(err) {
                res.json({ success: true, content: comment.contentHtml });
@@ -311,6 +307,7 @@ app.post('/auth/:sdk/:version/comments/:commentId', util.requireLoggedInUser, ut
 */
app.post('/auth/:sdk/:version/comments/:commentId/delete', util.requireLoggedInUser, util.findComment, util.requireOwner, function(req, res) {
    req.comment.deleted = true;
    util.logUpdate(req.comment, req.session.user.username, "delete");
    req.comment.save(function(err) {
        res.send({ success: true });
    });
@@ -321,6 +318,7 @@ app.post('/auth/:sdk/:version/comments/:commentId/delete', util.requireLoggedInU
 */
app.post('/auth/:sdk/:version/comments/:commentId/undo_delete', util.requireLoggedInUser, util.findComment, util.requireOwner, util.getCommentReads, function(req, res) {
    req.comment.deleted = false;
    util.logUpdate(req.comment, req.session.user.username, "undo_delete");
    req.comment.save(function(err) {
        res.send({ success: true, comment: util.scoreComments([req.comment], req)[0] });
    });
+21 −0
Original line number Diff line number Diff line
@@ -134,6 +134,27 @@ exports.vote = function(req, res, comment) {
    });
};

/**
 * Appends update record to comment updates log.
 *
 * @param {Object} comment The comment we're updating
 * @param {String} author Author of the update
 * @param {String} [action] The user action we're recording.
 * Leaving this empty, means normal update. Other currently used
 * actions are "delete" and "undo_delete".
 */
exports.logUpdate = function(comment, author, action) {
    var up = {
        updatedAt: String(new Date()),
        author: author
    };
    if (action) {
        up.action = action;
    }
    comment.updates = comment.updates || [];
    comment.updates.push(up);
};

/**
 * Ensures that user is logged in.
 *