fix: #11044, allow banned users to post

if given privileges
isekai-main
Barış Soner Uşaklı 2 years ago
parent 6109061501
commit abcfb63126

@ -18,7 +18,7 @@ module.exports = function (User) {
return; return;
} }
const [userData, isAdminOrMod] = await Promise.all([ 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), privileges.categories.isAdminOrMod(cid, uid),
]); ]);
@ -30,10 +30,6 @@ module.exports = function (User) {
return; return;
} }
if (userData.banned) {
throw new Error('[[error:user-banned]]');
}
const now = Date.now(); const now = Date.now();
if (userData.mutedUntil > now) { if (userData.mutedUntil > now) {
let muteLeft = ((userData.mutedUntil - now) / (1000 * 60)); let muteLeft = ((userData.mutedUntil - now) / (1000 * 60));

@ -24,6 +24,7 @@ const file = require('../src/file');
const socketUser = require('../src/socket.io/user'); const socketUser = require('../src/socket.io/user');
const apiUser = require('../src/api/users'); const apiUser = require('../src/api/users');
const utils = require('../src/utils'); const utils = require('../src/utils');
const privileges = require('../src/privileges');
describe('User', () => { describe('User', () => {
let userData; let userData;
@ -1434,6 +1435,32 @@ describe('User', () => {
assert.strictEqual(membership.get('verified-users'), true); assert.strictEqual(membership.get('verified-users'), true);
assert.strictEqual(membership.get('unverified-users'), false); 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', () => { describe('Digest.getSubscribers', () => {
@ -1899,7 +1926,7 @@ describe('User', () => {
it('should get unread count for user', async () => { it('should get unread count for user', async () => {
const count = await socketUser.getUnreadCount({ uid: testUid }); 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 () => { it('should get unread chat count 0 for guest', async () => {
@ -1922,15 +1949,15 @@ describe('User', () => {
assert.deepStrictEqual(counts, { assert.deepStrictEqual(counts, {
unreadChatCount: 0, unreadChatCount: 0,
unreadCounts: { unreadCounts: {
'': 2, '': 3,
new: 2, new: 3,
unreplied: 2, unreplied: 3,
watched: 0, watched: 0,
}, },
unreadNewTopicCount: 2, unreadNewTopicCount: 3,
unreadNotificationCount: 0, unreadNotificationCount: 0,
unreadTopicCount: 2, unreadTopicCount: 3,
unreadUnrepliedTopicCount: 2, unreadUnrepliedTopicCount: 3,
unreadWatchedTopicCount: 0, unreadWatchedTopicCount: 0,
}); });
}); });

Loading…
Cancel
Save