Commit 6e8f97e6 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Server API requests for adding/removing comments.

parent 656fb6b7
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -206,6 +206,20 @@ app.post('/auth/:sdk/:version/comments/:commentId/undo_delete', Auth.isLoggedIn,
    });
});

// Tags a comment
app.post('/auth/:sdk/:version/comments/:commentId/add_tag', Auth.isLoggedIn, Auth.isModerator, function(req, res) {
    new Request(req).addTag(req.params.commentId, req.body.tagname, function() {
        res.send({ success: true });
    });
});

// Removes tag from a comment
app.post('/auth/:sdk/:version/comments/:commentId/remove_tag', Auth.isLoggedIn, Auth.isModerator, function(req, res) {
    new Request(req).removeTag(req.params.commentId, req.body.tagname, function() {
        res.send({ success: true });
    });
});

// Marks a comment 'read'
app.post('/auth/:sdk/:version/comments/:commentId/read', Auth.isLoggedIn, function(req, res) {
    new Request(req).markRead(req.params.commentId, function() {
+12 −0
Original line number Diff line number Diff line
@@ -46,6 +46,18 @@ var Auth = {
        });
    },

    /**
     * Throws error when logged in user isn't moderator.
     */
    isModerator: function(req, res, next) {
        if (new Request(req).isModerator()) {
            next();
        }
        else {
            res.json({ success: false, reason: 'Forbidden' }, 403);
        }
    },

    /**
     * Throws error when logged in user can't vote on the comment in
     * question.
+21 −0
Original line number Diff line number Diff line
@@ -198,6 +198,27 @@ Request.prototype = {
        });
    },

    /**
     * Adds tag to comment.
     */
    addTag: function(comment_id, tagname, callback) {
        this.db.comments().addTag({
            user_id: this.getUserId(),
            comment_id: comment_id,
            tagname: tagname
        }, callback);
    },

    /**
     * Removes tag from comment.
     */
    removeTag: function(comment_id, tagname, callback) {
        this.db.comments().removeTag({
            comment_id: comment_id,
            tagname: tagname
        }, callback);
    },

    /**
     * Marks comment as read.
     */