From 72eac9875fc9a4f3207c2ae5a37825598d2e4b4f Mon Sep 17 00:00:00 2001 From: undefined Date: Tue, 19 Jan 2021 21:51:03 +0800 Subject: [PATCH] =?UTF-8?q?core:=20=E4=BF=AE=E5=A4=8D=E6=95=B0=E5=A4=84?= =?UTF-8?q?=E9=89=B4=E6=9D=83=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/problem.ts | 30 +++++++++++-------------- packages/hydrooj/src/handler/record.ts | 15 ++++++++++--- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index b40adf86b..f055991ad 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.15.24", + "version": "2.15.25", "bin": "bin/hydrooj.js", "main": "dist/loader.js", "typings": "dist/loader.d.ts", diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index a8c7b4b1d..1f112688e 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -30,10 +30,6 @@ export const parseCategory = (value: string) => flatten(value.split('+').map((e) export const parsePid = (value: string) => (isSafeInteger(value) ? parseInt(value, 10) : value); export class ProblemHandler extends Handler { - async __prepare() { - this.checkPerm(PERM.PERM_VIEW_PROBLEM); - } - async cleanup() { if (this.response.template === 'problem_main.html' && this.request.json) { const { @@ -693,24 +689,24 @@ export class ProblemImportHandler extends Handler { export async function apply() { ProblemAdd('problem_import', {}, 'copy', 'Import From Hydro'); - Route('problem_main', '/p', ProblemMainHandler); - Route('problem_category', '/p/category/:category', ProblemCategoryHandler); - Route('problem_random', '/problem/random', ProblemRandomHandler); - Route('problem_detail', '/p/:pid', ProblemDetailHandler); - Route('problem_export', '/p/:pid/export', ProblemExportHandler); + Route('problem_main', '/p', ProblemMainHandler, PERM.PERM_VIEW_PROBLEM); + Route('problem_category', '/p/category/:category', ProblemCategoryHandler, PERM.PERM_VIEW_PROBLEM); + Route('problem_random', '/problem/random', ProblemRandomHandler, PERM.PERM_VIEW_PROBLEM); + Route('problem_detail', '/p/:pid', ProblemDetailHandler, PERM.PERM_VIEW_PROBLEM); + Route('problem_export', '/p/:pid/export', ProblemExportHandler, PERM.PERM_VIEW_PROBLEM); Route('problem_submit', '/p/:pid/submit', ProblemSubmitHandler, PERM.PERM_SUBMIT_PROBLEM); - Route('problem_pretest', '/p/:pid/pretest', ProblemPretestHandler); + Route('problem_pretest', '/p/:pid/pretest', ProblemPretestHandler, PERM.PERM_SUBMIT_PROBLEM); Route('problem_settings', '/p/:pid/settings', ProblemSettingsHandler); - Route('problem_statistics', '/p/:pid/statistics', ProblemStatisticsHandler); + Route('problem_statistics', '/p/:pid/statistics', ProblemStatisticsHandler, PERM.PERM_VIEW_PROBLEM); Route('problem_edit', '/p/:pid/edit', ProblemEditHandler); - Route('problem_files', '/p/:pid/files', ProblemFilesHandler); - Route('problem_file_download', '/p/:pid/file/:filename', ProblemFileDownloadHandler); - Route('problem_solution', '/p/:pid/solution', ProblemSolutionHandler); - Route('problem_solution_raw', '/p/:pid/solution/:psid/raw', ProblemSolutionRawHandler); - Route('problem_solution_reply_raw', '/p/:pid/solution/:psid/:psrid/raw', ProblemSolutionRawHandler); + Route('problem_files', '/p/:pid/files', ProblemFilesHandler, PERM.PERM_VIEW_PROBLEM); + Route('problem_file_download', '/p/:pid/file/:filename', ProblemFileDownloadHandler, PERM.PERM_VIEW_PROBLEM); + Route('problem_solution', '/p/:pid/solution', ProblemSolutionHandler, PERM.PERM_VIEW_PROBLEM); + Route('problem_solution_raw', '/p/:pid/solution/:psid/raw', ProblemSolutionRawHandler, PERM.PERM_VIEW_PROBLEM); + Route('problem_solution_reply_raw', '/p/:pid/solution/:psid/:psrid/raw', ProblemSolutionRawHandler, PERM.PERM_VIEW_PROBLEM); Route('problem_create', '/problem/create', ProblemCreateHandler, PERM.PERM_CREATE_PROBLEM); Route('problem_import', '/problem/import', ProblemImportHandler, PERM.PERM_CREATE_PROBLEM); - Connection('problem_pretest_conn', '/conn/pretest', ProblemPretestConnectionHandler); + Connection('problem_pretest_conn', '/conn/pretest', ProblemPretestConnectionHandler, PERM.PERM_SUBMIT_PROBLEM); } global.Hydro.handler.problem = apply; diff --git a/packages/hydrooj/src/handler/record.ts b/packages/hydrooj/src/handler/record.ts index 7e6c98f62..310c000ed 100644 --- a/packages/hydrooj/src/handler/record.ts +++ b/packages/hydrooj/src/handler/record.ts @@ -41,10 +41,13 @@ class RecordListHandler extends RecordHandler { page, CONSTANT.RECORD_PER_PAGE, ); + const canViewProblem = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM); const canViewProblemHidden = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN); const [udict, pdict] = await Promise.all([ user.getList(domainId, rdocs.map((rdoc) => rdoc.uid)), - problem.getList(domainId, rdocs.map((rdoc) => rdoc.pid), canViewProblemHidden, false), + canViewProblem + ? problem.getList(domainId, rdocs.map((rdoc) => rdoc.pid), canViewProblemHidden, false) + : Object.fromEntries([rdocs.map((rdoc) => [rdoc.pid, problem.Pdoc.create(rdoc.pid, rdoc.pid)])]), ]); const path = [ ['Hydro', 'homepage'], @@ -84,6 +87,9 @@ class RecordDetailHandler extends RecordHandler { pdoc = problem.Pdoc.create(pdoc.docId, pdoc.pid); } } + if (!this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)) { + pdoc = problem.Pdoc.create(pdoc.docId, pdoc.pid); + } this.response.body = { path: [ ['Hydro', 'homepage'], @@ -170,8 +176,11 @@ class RecordMainConnectionHandler extends RecordConnectionHandler { user.getById(this.domainId, rdoc.uid), problem.get(this.domainId, rdoc.pid, null), ]); - if (pdoc && pdoc.hidden && !this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN)) pdoc = null; - else this.send({ html: await this.renderHTML('record_main_tr.html', { rdoc, udoc, pdoc }) }); + if (pdoc) { + if (pdoc.hidden && !this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN)) pdoc = null; + if (!this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)) pdoc = null; + } + this.send({ html: await this.renderHTML('record_main_tr.html', { rdoc, udoc, pdoc }) }); } }