mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
@@ -18,7 +18,7 @@ module.exports = function (User) {
|
||||
return;
|
||||
}
|
||||
const [userData, isAdminOrMod] = await Promise.all([
|
||||
User.getUserFields(uid, ['uid', 'banned', 'mutedUntil', 'joindate', 'email', 'reputation'].concat([field])),
|
||||
User.getUserFields(uid, ['uid', 'mutedUntil', 'joindate', 'email', 'reputation'].concat([field])),
|
||||
privileges.categories.isAdminOrMod(cid, uid),
|
||||
]);
|
||||
|
||||
@@ -30,10 +30,6 @@ module.exports = function (User) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (userData.banned) {
|
||||
throw new Error('[[error:user-banned]]');
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
if (userData.mutedUntil > now) {
|
||||
let muteLeft = ((userData.mutedUntil - now) / (1000 * 60));
|
||||
|
||||
41
test/user.js
41
test/user.js
@@ -24,6 +24,7 @@ const file = require('../src/file');
|
||||
const socketUser = require('../src/socket.io/user');
|
||||
const apiUser = require('../src/api/users');
|
||||
const utils = require('../src/utils');
|
||||
const privileges = require('../src/privileges');
|
||||
|
||||
describe('User', () => {
|
||||
let userData;
|
||||
@@ -1434,6 +1435,32 @@ describe('User', () => {
|
||||
assert.strictEqual(membership.get('verified-users'), true);
|
||||
assert.strictEqual(membership.get('unverified-users'), false);
|
||||
});
|
||||
|
||||
it('should be able to post in category for banned users', async () => {
|
||||
const { cid } = await Categories.create({
|
||||
name: 'Test Category',
|
||||
description: 'A test',
|
||||
order: 1,
|
||||
});
|
||||
const testUid = await User.create({ username: userData.username });
|
||||
await User.bans.ban(testUid);
|
||||
let _err;
|
||||
try {
|
||||
await Topics.post({ title: 'banned topic', content: 'tttttttttttt', cid: cid, uid: testUid });
|
||||
} catch (err) {
|
||||
_err = err;
|
||||
}
|
||||
assert.strictEqual(_err && _err.message, '[[error:no-privileges]]');
|
||||
|
||||
await Promise.all([
|
||||
privileges.categories.give(['groups:topics:create', 'groups:topics:reply'], cid, 'banned-users'),
|
||||
privileges.categories.rescind(['groups:topics:create', 'groups:topics:reply'], cid, 'registered-users'),
|
||||
]);
|
||||
|
||||
const result = await Topics.post({ title: 'banned topic', content: 'tttttttttttt', cid: cid, uid: testUid });
|
||||
assert(result);
|
||||
assert.strictEqual(result.topicData.title, 'banned topic');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Digest.getSubscribers', () => {
|
||||
@@ -1899,7 +1926,7 @@ describe('User', () => {
|
||||
|
||||
it('should get unread count for user', async () => {
|
||||
const count = await socketUser.getUnreadCount({ uid: testUid });
|
||||
assert.strictEqual(count, 2);
|
||||
assert.strictEqual(count, 3);
|
||||
});
|
||||
|
||||
it('should get unread chat count 0 for guest', async () => {
|
||||
@@ -1922,15 +1949,15 @@ describe('User', () => {
|
||||
assert.deepStrictEqual(counts, {
|
||||
unreadChatCount: 0,
|
||||
unreadCounts: {
|
||||
'': 2,
|
||||
new: 2,
|
||||
unreplied: 2,
|
||||
'': 3,
|
||||
new: 3,
|
||||
unreplied: 3,
|
||||
watched: 0,
|
||||
},
|
||||
unreadNewTopicCount: 2,
|
||||
unreadNewTopicCount: 3,
|
||||
unreadNotificationCount: 0,
|
||||
unreadTopicCount: 2,
|
||||
unreadUnrepliedTopicCount: 2,
|
||||
unreadTopicCount: 3,
|
||||
unreadUnrepliedTopicCount: 3,
|
||||
unreadWatchedTopicCount: 0,
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user