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