黑名单功能

This commit is contained in:
masnn committed 2020-06-10 12:20:07 +08:00
1 parent 55912b087d
commit 160b4482cc
11 files changed
+282 -158

No files matched your search

+9 -5
View File
@@ -37,12 +37,12 @@ function edit(domainId, did, title, content, highlight) {
}
function del(domainId, did) {
// TODO(masnn) delete status
return Promise.all([
document.deleteOne(domainId, document.TYPE_DISCUSSION, did),
document.deleteMulti(domainId, document.TYPE_DISCUSSION_REPLY, {
parentType: document.TYPE_DISCUSSION, parentId: did,
}),
document.deleteMultiStatus(domainId, document.TYPE_DISCUSSION, { docId: did }),
]);
}
@@ -167,12 +167,16 @@ async function getVnode(domainId, ddoc, handler) {
}
async function getListVnodes(domainId, ddocs, handler) {
const tasks = [];
const res = {};
for (const ddoc of ddocs) {
if (!res[ddoc.parentType]) res[ddoc.parentType] = {};
// FIXME no-await-in-loop
res[ddoc.parentType][ddoc.parentId] = await getVnode(domainId, ddoc, handler); // eslint-disable-line no-await-in-loop
function task(ddoc) {
return getVnode(domainId, ddoc, handler).then((vnode) => {
if (!res[ddoc.parentType]) res[ddoc.parentType] = {};
res[ddoc.parentType][ddoc.parentId] = vnode;
});
}
for (const ddoc of ddocs) tasks.push(task(ddoc));
await Promise.all(tasks);
return res;
}
+10
View File
@@ -1,6 +1,7 @@
const builtin = require('./builtin');
const document = require('./document');
const system = require('./system');
const token = require('./token');
const { UserNotFoundError, UserAlreadyExistError } = require('../error');
const perm = require('../permission');
const pwhash = require('../lib/hash.hydro');
@@ -25,6 +26,7 @@ class USER {
this.loginat = udoc.loginat;
this.bio = udoc.bio || '';
this.gravatar = udoc.gravatar || '';
this.ban = udoc.ban || false;
this.nAccept = dudoc.nAccept || 0;
this.nSubmit = dudoc.nSubmit || 0;
this.rating = dudoc.rating || 1500;
@@ -215,6 +217,13 @@ function deleteRoles(domainId, roles) {
]);
}
function ban(uid) {
return Promise.all([
coll.updateOne({ _id: uid }, { $set: { ban: true } }),
token.deleteByUid(uid),
]);
}
function ensureIndexes() {
return Promise.all([
coll.createIndex('unameLower', { unique: true }),
@@ -246,5 +255,6 @@ global.Hydro.model.user = module.exports = {
getInDomain,
addRole,
deleteRoles,
ban,
ensureIndexes,
};