mirror of
https://github.com/wassname/talk.git
synced 2026-07-24 13:20:47 +08:00
Backend for the tags staff on staff users.
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user