修复一些错误

This commit is contained in:
masnn committed 2020-06-02 13:41:49 +08:00
1 parent bc50913e6e
commit 2b6a510c1e
23 files changed
+321 -191

No files matched your search

+18
View File
@@ -16,6 +16,8 @@ class USER {
this.salt = () => user.salt;
this.hash = () => user.hash;
this.perm = user.perm;
this.priv = user.priv;
this.role = user.role;
this.viewLang = user.language || 'zh_CN';
this.codeLang = user.codeLang || 'c';
this.codeTemplate = user.codeTemplate || '';
@@ -161,6 +163,16 @@ function setRole(domainId, uid, role) {
return document.setStatus(domainId, document.TYPE_DOMAIN_ROLE, 0, uid, { role });
}
function setRoles(domainId, roles) {
const tasks = [];
for (const role in roles) {
tasks.push(document.set(
domainId, document.TYPE_DOMAIN_ROLE, role, { content: roles[role] },
));
}
return Promise.all(tasks);
}
async function getRoles(domainId) {
const docs = await document.getMulti(domainId, document.TYPE_DOMAIN_ROLE).sort('_id', 1).toArray();
const roles = [];
@@ -174,6 +186,10 @@ function getRole(domainId, name) {
return document.get(domainId, document.TYPE_DOMAIN_ROLE, name);
}
function getInDomain(domainId) {
return document.getMultiStatus(domainId, document.TYPE_DOMAIN_ROLE).toArray();
}
function addRole(domainId, name, permission) {
return document.add(domainId, permission, 1, document.TYPE_DOMAIN_ROLE, name);
}
@@ -205,9 +221,11 @@ global.Hydro.model.user = module.exports = {
setPassword,
getPrefixList,
setRole,
setRoles,
getRole,
getList,
getRoles,
getInDomain,
addRole,
deleteRoles,
ensureIndexes,