mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
更新权限节点
This commit is contained in:
1 parent
e092efca20
commit
b22082beba
16 files changed
+88
-87
No files matched your search
@@ -73,6 +73,9 @@ const PERM = {
|
||||
PERM_CREATE_TRAINING: 't',
|
||||
PERM_EDIT_TRAINING: 'u',
|
||||
PERM_EDIT_TRAINING_SELF: 'v',
|
||||
|
||||
// Ranking
|
||||
PERM_VIEW_RANKING: 'w',
|
||||
};
|
||||
|
||||
const Permission = (family, key, desc) => ({ family, key, desc });
|
||||
@@ -206,7 +209,7 @@ PERM.PERM_ADMIN = PERM.PERM_ALL;
|
||||
|
||||
const PRIV = {
|
||||
PRIV_NONE: 0,
|
||||
PRIV_SET_PRIV: 1 << 0,
|
||||
PRIV_EDIT_SYSTEM: 1 << 0, // renamed from PRIV_SET_PRIV
|
||||
PRIV_SET_PERM: 1 << 1,
|
||||
PRIV_USER_PROFILE: 1 << 2,
|
||||
PRIV_REGISTER_USER: 1 << 3,
|
||||
|
||||
+17
-6
@@ -15,12 +15,23 @@ const coll = db.collection('domain');
|
||||
* @param {string} domainId
|
||||
* @param {number} owner
|
||||
*/
|
||||
function add(domainId, owner, name) {
|
||||
const tasks = [
|
||||
coll.insertOne({
|
||||
_id: domainId, owner, name, bulletin: '',
|
||||
}),
|
||||
];
|
||||
function add(domainId, owner, name, isEnsure = false) {
|
||||
const tasks = [];
|
||||
if (isEnsure) {
|
||||
tasks.push(
|
||||
coll.updateOne(
|
||||
{ _id: domainId },
|
||||
{ $set: { owner }, $setOnInsert: { name, bulletin: '' } },
|
||||
{ upsert: true },
|
||||
),
|
||||
);
|
||||
} else {
|
||||
tasks.push(
|
||||
coll.insertOne({
|
||||
_id: domainId, owner, name, bulletin: '',
|
||||
}),
|
||||
);
|
||||
}
|
||||
for (const id in builtin.BUILTIN_ROLES) {
|
||||
tasks.push(
|
||||
document.add(
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
const { ObjectId } = require('bson');
|
||||
const { STATUS_ACCEPTED } = require('./builtin').STATUS;
|
||||
const file = require('./file');
|
||||
const document = require('./document');
|
||||
const domain = require('./domain');
|
||||
const { ProblemNotFoundError } = require('../error');
|
||||
const readConfig = require('../lib/readConfig');
|
||||
const { ObjectId } = require('bson');
|
||||
|
||||
/**
|
||||
* @typedef {import('../interface').Pdoc} Pdoc
|
||||
|
||||
+13
-2
@@ -12,18 +12,20 @@ const timezones = Array.from(tzs).sort().map((tz) => [tz, tz]);
|
||||
const PREFERENCE_SETTINGS = [];
|
||||
const ACCOUNT_SETTINGS = [];
|
||||
const DOMAIN_SETTINGS = [];
|
||||
const DOMAIN_USER_SETTINGS = [];
|
||||
const SYSTEM_SETTINGS = [];
|
||||
const SETTINGS = [];
|
||||
const SETTINGS_BY_KEY = {};
|
||||
const DOMAIN_USER_SETTINGS_BY_KEY = {};
|
||||
const DOMAIN_SETTINGS_BY_KEY = {};
|
||||
const SYSTEM_SETTINGS_BY_KEY = {};
|
||||
|
||||
const Setting = (
|
||||
family, key, range = null,
|
||||
value = null, ui = 'text', name = '',
|
||||
desc = '',
|
||||
desc = '', hidden = false,
|
||||
) => ({
|
||||
family, key, range, value, ui, name, desc,
|
||||
family, key, range, value, ui, name, desc, hidden,
|
||||
});
|
||||
|
||||
const PreferenceSetting = (...settings) => {
|
||||
@@ -40,6 +42,12 @@ const AccountSetting = (...settings) => {
|
||||
SETTINGS_BY_KEY[setting.key] = setting;
|
||||
}
|
||||
};
|
||||
const DomainUserSetting = (...settings) => {
|
||||
for (const setting of settings) {
|
||||
DOMAIN_USER_SETTINGS.push(setting);
|
||||
DOMAIN_USER_SETTINGS_BY_KEY[setting.key] = setting;
|
||||
}
|
||||
};
|
||||
const DomainSetting = (...settings) => {
|
||||
for (const setting of settings) {
|
||||
DOMAIN_SETTINGS.push(setting);
|
||||
@@ -119,6 +127,7 @@ global.Hydro.model.setting = module.exports = {
|
||||
PreferenceSetting,
|
||||
AccountSetting,
|
||||
DomainSetting,
|
||||
DomainUserSetting,
|
||||
SystemSetting,
|
||||
PREFERENCE_SETTINGS,
|
||||
ACCOUNT_SETTINGS,
|
||||
@@ -128,4 +137,6 @@ global.Hydro.model.setting = module.exports = {
|
||||
SYSTEM_SETTINGS_BY_KEY,
|
||||
DOMAIN_SETTINGS,
|
||||
DOMAIN_SETTINGS_BY_KEY,
|
||||
DOMAIN_USER_SETTINGS,
|
||||
DOMAIN_USER_SETTINGS_BY_KEY,
|
||||
};
|
||||
+8
-14
@@ -1,4 +1,4 @@
|
||||
const builtin = require('./builtin');
|
||||
const { BUILTIN_ROLES, BUILTIN_USERS, PRIV } = require('./builtin');
|
||||
const document = require('./document');
|
||||
const system = require('./system');
|
||||
const token = require('./token');
|
||||
@@ -6,7 +6,6 @@ const setting = require('./setting');
|
||||
const { UserNotFoundError, UserAlreadyExistError, LoginError } = require('../error');
|
||||
const pwhash = require('../lib/hash.hydro');
|
||||
const db = require('../service/db');
|
||||
const { PRIV } = require('./builtin');
|
||||
|
||||
const coll = db.collection('user');
|
||||
|
||||
@@ -63,13 +62,13 @@ async function getInDomain(domainId, udoc) {
|
||||
// eslint-disable-next-line no-bitwise
|
||||
if (udoc.priv & PRIV.PRIV_MANAGE_ALL_DOMAIN) dudoc.role = 'admin';
|
||||
const p = await document.get(domainId, document.TYPE_DOMAIN_USER, dudoc.role || 'default');
|
||||
dudoc.perm = p ? p.content : builtin.BUILTIN_ROLES[dudoc.role || 'default'].perm;
|
||||
dudoc.perm = p ? p.content : BUILTIN_ROLES[dudoc.role || 'default'].perm;
|
||||
return dudoc;
|
||||
}
|
||||
|
||||
async function getById(domainId, _id, throwError = false) {
|
||||
const udoc = _id === 0 || _id === 1
|
||||
? builtin.BUILTIN_USERS[_id]
|
||||
? BUILTIN_USERS[_id]
|
||||
: await coll.findOne({ _id });
|
||||
if (!udoc) {
|
||||
if (throwError) throw new UserNotFoundError(_id);
|
||||
@@ -90,9 +89,9 @@ async function getList(domainId, uids) {
|
||||
async function getByUname(domainId, uname, ignoreMissing = false) {
|
||||
const unameLower = uname.trim().toLowerCase();
|
||||
const udoc = (unameLower === 'guest')
|
||||
? builtin.BUILTIN_USERS[0]
|
||||
? BUILTIN_USERS[0]
|
||||
: unameLower === 'hydro'
|
||||
? builtin.BUILTIN_USERS[1]
|
||||
? BUILTIN_USERS[1]
|
||||
: await coll.findOne({ unameLower });
|
||||
if (!udoc) {
|
||||
if (ignoreMissing) return null;
|
||||
@@ -105,9 +104,9 @@ async function getByUname(domainId, uname, ignoreMissing = false) {
|
||||
async function getByEmail(domainId, mail, ignoreMissing = false) {
|
||||
const mailLower = mail.trim().toLowerCase();
|
||||
const udoc = (mailLower === 'guest@hydro.local')
|
||||
? builtin.BUILTIN_USERS[0]
|
||||
? BUILTIN_USERS[0]
|
||||
: mailLower === 'hydro@hydro.local'
|
||||
? builtin.BUILTIN_USERS[1]
|
||||
? BUILTIN_USERS[1]
|
||||
: await coll.findOne({ mailLower });
|
||||
if (!udoc) {
|
||||
if (ignoreMissing) return null;
|
||||
@@ -259,15 +258,11 @@ function deleteRoles(domainId, roles) {
|
||||
|
||||
function ban(uid) {
|
||||
return Promise.all([
|
||||
coll.updateOne({ _id: uid }, { $set: { ban: true } }),
|
||||
setPriv(uid, PRIV.PRIV_NONE),
|
||||
token.delByUid(uid),
|
||||
]);
|
||||
}
|
||||
|
||||
function setSuperAdmin(uid) {
|
||||
return setById(uid, { priv: 1 });
|
||||
}
|
||||
|
||||
function ensureIndexes() {
|
||||
return Promise.all([
|
||||
coll.createIndex('unameLower', { unique: true }),
|
||||
@@ -300,7 +295,6 @@ global.Hydro.model.user = module.exports = {
|
||||
getInDomain,
|
||||
addRole,
|
||||
deleteRoles,
|
||||
setSuperAdmin,
|
||||
ban,
|
||||
ensureIndexes,
|
||||
};
|
||||
Reference in new issue
Block a user