From fc880de9bf7b6ae25280ba9fde193b80d5ab315c Mon Sep 17 00:00:00 2001 From: gaba Date: Tue, 7 Feb 2017 16:31:39 -0800 Subject: [PATCH] Backend for the tags staff on staff users. --- models/comment.js | 9 +++++++++ services/comments.js | 3 +++ services/users.js | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/models/comment.js b/models/comment.js index b656f9238..a2733f551 100644 --- a/models/comment.js +++ b/models/comment.js @@ -9,6 +9,11 @@ const STATUSES = [ null ]; +const TAGS = [ + 'STAFF', + null +]; + /** * The Mongo schema for a Comment Status. * @type {Schema} @@ -49,6 +54,10 @@ const CommentSchema = new Schema({ author_id: String, status_history: [StatusSchema], status: {type: String, default: null}, + tag: { + type: String, + enum: TAGS, + }, parent_id: String }, { timestamps: { diff --git a/services/comments.js b/services/comments.js index 5d39a129e..9055afcfa 100644 --- a/services/comments.js +++ b/services/comments.js @@ -3,6 +3,8 @@ const CommentModel = require('../models/comment'); const ActionModel = require('../models/action'); const ActionsService = require('./actions'); +const UsersService = require('./users'); + module.exports = class CommentsService { /** @@ -34,6 +36,7 @@ module.exports = class CommentsService { created_at: new Date() }] : [], status, + tag: UsersService.isStaff(author_id) ? 'STAFF' : null, author_id }); diff --git a/services/users.js b/services/users.js index 408d5c618..e7049a347 100644 --- a/services/users.js +++ b/services/users.js @@ -687,4 +687,15 @@ module.exports = class UsersService { Promise.reject(new Error('You do not have permission to update your username.')); }); } + + /** + * Returns true if the user is staff. + * @param {String} id the id of the user to be enabled. + * @return {Promise} + */ + static isStaff(id) { + return UserModel.findById(id).then((user) => { + return user.hasRoles('ADMIN'); + }); + } };