From 2328bada9d8025b5eb0f0d5649ddda4725463f52 Mon Sep 17 00:00:00 2001 From: undefined Date: Thu, 28 Jan 2021 13:26:27 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E4=BF=AE=E5=A4=8D=E6=97=A0PERM=5FVIEW?= =?UTF-8?q?=5FPROBLEM=E5=9C=A8user=5Fdetail=E8=83=BD=E5=A4=9F=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E5=88=B0=E9=A2=98=E7=9B=AE=E6=A0=87=E9=A2=98=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/hydrooj/package.json | 2 +- packages/hydrooj/src/handler/domain.ts | 3 ++- packages/hydrooj/src/handler/user.ts | 24 +++++++++++++++--------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 30b9f0066..2bb916690 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.17.5", + "version": "2.17.6", "bin": "bin/hydrooj.js", "main": "dist/loader.js", "typings": "dist/loader.d.ts", diff --git a/packages/hydrooj/src/handler/domain.ts b/packages/hydrooj/src/handler/domain.ts index 9bcfebdc7..006f84fcb 100644 --- a/packages/hydrooj/src/handler/domain.ts +++ b/packages/hydrooj/src/handler/domain.ts @@ -143,13 +143,14 @@ class DomainPermissionHandler extends ManageHandler { const roles = {}; delete this.request.body.csrfToken; for (const role in this.request.body) { + console.log(role, this.request.body[role]); const perms = this.request.body[role] instanceof Array ? this.request.body[role] : [this.request.body[role]]; // @ts-ignore roles[role] = 0n; // @ts-ignore - for (const r of perms) roles[role] += 1n << BigInt(r); + for (const r of perms) roles[role] |= 1n << BigInt(r); } await domain.setRoles(domainId, roles); this.back(); diff --git a/packages/hydrooj/src/handler/user.ts b/packages/hydrooj/src/handler/user.ts index 1afb4d14f..2686a68eb 100644 --- a/packages/hydrooj/src/handler/user.ts +++ b/packages/hydrooj/src/handler/user.ts @@ -162,16 +162,22 @@ class UserDetailHandler extends Handler { const [sdoc, rdocs, [pdocs, pcount]] = await Promise.all([ token.getMostRecentSessionByUid(uid), record.getByUid(domainId, uid, 30), - paginate( - problem.getMulti(domainId, { owner: this.user._id }), - 1, - 100, - ), + this.user.hasPerm(PERM.PERM_VIEW_PROBLEM) + ? paginate( + problem.getMulti(domainId, { owner: this.user._id }), + 1, + 100, + ) + : [[], 0, 0] as [problem.Pdoc[], number, number], ]); - const pdict = await problem.getList( - domainId, rdocs.map((rdoc) => rdoc.pid), - this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN), false, - ); + const pdict = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM) + ? await problem.getList( + domainId, rdocs.map((rdoc) => rdoc.pid), + this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN), false, + ) + : Object.fromEntries(rdocs.map( + (rdoc) => [rdoc.pid, problem.Pdoc.create(undefined, rdoc.pid.toString())], + )); // Remove sensitive data if (!isSelfProfile && sdoc) { sdoc.createIp = '';