mirror of
https://github.com/wassname/talk.git
synced 2026-08-16 10:36:48 +08:00
Implement cannot ignore staff in users service
`UsersService.ignoreUsers` now checks if any user provided is a staff member. In case it is it throws a ErrCannotIgnoreStaff error.
This commit is contained in:
+7
-1
@@ -2,6 +2,7 @@ const assert = require('assert');
|
||||
const uuid = require('uuid');
|
||||
const bcrypt = require('bcryptjs');
|
||||
const errors = require('../errors');
|
||||
const some = require('lodash/some');
|
||||
|
||||
const {
|
||||
ROOT_URL
|
||||
@@ -879,13 +880,18 @@ module.exports = class UsersService {
|
||||
* @param {String} id the id of the user that is ignoring another users
|
||||
* @param {Array<String>} usersToIgnore Array of user IDs to ignore
|
||||
*/
|
||||
static ignoreUsers(id, usersToIgnore) {
|
||||
static async ignoreUsers(id, usersToIgnore) {
|
||||
assert(Array.isArray(usersToIgnore), 'usersToIgnore is an array');
|
||||
assert(usersToIgnore.every((u) => typeof u === 'string'), 'usersToIgnore is an array of string user IDs');
|
||||
if (usersToIgnore.includes(id)) {
|
||||
throw new Error('Users cannot ignore themselves');
|
||||
}
|
||||
|
||||
const users = await UsersService.findByIdArray(usersToIgnore);
|
||||
if (some(users, (user) => user.isStaff())) {
|
||||
throw errors.ErrCannotIgnoreStaff;
|
||||
}
|
||||
|
||||
// TODO: For each usersToIgnore, make sure they exist?
|
||||
return UserModel.update({id}, {
|
||||
$addToSet: {
|
||||
|
||||
Reference in New Issue
Block a user