core: 修复PERM键值重复导致无法正常设置权限的问题

This commit is contained in:
undefined committed 2020-11-04 22:23:51 +08:00
1 parent d7b02baeaf
commit f570ef70a0
3 files changed
+14 -15

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.13.37",
"version": "2.13.38",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+10 -11
View File
@@ -126,10 +126,7 @@ class DomainPermissionHandler extends ManageHandler {
const roles = await domain.getRoles(domainId);
const log2 = (val: bigint) => {
// @ts-ignore
for (let i = 0n; ; i++) {
// @ts-ignore
if ((val >> i) === 0n) return parseInt(i.toString(), 10) - 1;
}
for (let i = 0n; ; i++) if (!(val >> i)) return +i.toString() - 1;
};
const path = [
['Hydro', 'homepage'],
@@ -144,14 +141,16 @@ class DomainPermissionHandler extends ManageHandler {
async post({ domainId }) {
const roles = {};
delete this.request.body.csrfToken;
for (const role in this.request.body) {
if (this.request.body[role] instanceof Array) {
const perms = this.request.body[role];
// @ts-ignore
roles[role] = 0n;
// @ts-ignore
for (const r of perms) roles[role] += 1n << BigInt(r);
}
const perms = this.request.body[role] instanceof Array
? this.request.body[role]
: [this.request.body[role]];
// @ts-ignore
roles[role] = 0n;
console.log(role, perms);
// @ts-ignore
for (const r of perms) roles[role] += 1n << BigInt(r);
}
await domain.setRoles(domainId, roles);
this.back();
+3 -3
View File
@@ -45,7 +45,7 @@ export const PERM = {
PERM_VIEW_DISCUSSION: 1n << 27n,
PERM_CREATE_DISCUSSION: 1n << 28n,
PERM_HIGHLIGHT_DISCUSSION: 1n << 29n,
PERM_PIN_DISCUSSION: 1n << 59n,
PERM_PIN_DISCUSSION: 1n << 61n,
PERM_EDIT_DISCUSSION: 1n << 30n,
PERM_EDIT_DISCUSSION_SELF: 1n << 31n,
PERM_DELETE_DISCUSSION: 1n << 32n,
@@ -81,7 +81,7 @@ export const PERM = {
PERM_EDIT_TRAINING_SELF: 1n << 49n,
// Ranking
PERM_VIEW_RANKING: 1n << 50n,
PERM_VIEW_RANKING: 1n << 59n,
// Placeholder
PERM_ALL: -1n,
@@ -89,7 +89,7 @@ export const PERM = {
PERM_DEFAULT: 0n,
PERM_ADMIN: -1n,
PERM_NEVER: 1n << 59n,
PERM_NEVER: 1n << 60n,
};
export const Permission = (family: string, key: BigInt, desc: string) => ({ family, key, desc });