core: 修正problem_send鉴权

This commit is contained in:
undefined committed 2021-03-06 15:44:41 +08:00
1 parent 4c37aedfff
commit 454afbcb08
2 files changed
+5 -3

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.19.5", "version": "2.19.6",
"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",
+4 -2
View File
@@ -18,12 +18,14 @@ const logger = new Logger('remote');
export class ProblemSendHandler extends Handler { export class ProblemSendHandler extends Handler {
async get() { async get() {
this.checkPerm(PERM.PERM_VIEW_PROBLEM);
this.response.template = 'problem_send.html'; this.response.template = 'problem_send.html';
} }
@post('target', Types.String) @post('target', Types.String)
@post('pids', Types.Array) @post('pids', Types.Array)
async postSend(domainId: string, target: any, _pids: (number | string)[]) { async postSend(domainId: string, target: any, _pids: (number | string)[]) {
this.checkPerm(PERM.PERM_VIEW_PROBLEM);
target = target.split('@'); target = target.split('@');
const getHidden = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN); const getHidden = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
const getData = this.user.hasPerm(PERM.PERM_READ_PROBLEM_DATA); const getData = this.user.hasPerm(PERM.PERM_READ_PROBLEM_DATA);
@@ -64,7 +66,7 @@ export class ProblemSendHandler extends Handler {
const pdocs = await problem.getMulti(domainId, { docId: { $in: pids } }, problem.PROJECTION_PUBLIC).toArray(); const pdocs = await problem.getMulti(domainId, { docId: { $in: pids } }, problem.PROJECTION_PUBLIC).toArray();
const data = await token.get(tokenId, token.TYPE_EXPORT); const data = await token.get(tokenId, token.TYPE_EXPORT);
if (!data) throw new InvalidTokenError(tokenId); if (!data) throw new InvalidTokenError(tokenId);
for (const pid of pids) if (!data.pids.includes(pid)) throw new InvalidTokenError(tokenId); if (pids.filter((pid) => !data.pids.includes(pid)).length) throw new InvalidTokenError(tokenId);
const links = []; const links = [];
for (const pdoc of pdocs) { for (const pdoc of pdocs) {
const files = await storage.list(`problem/${domainId}/${pdoc.docId}/`, true); const files = await storage.list(`problem/${domainId}/${pdoc.docId}/`, true);
@@ -152,7 +154,7 @@ export class ProblemReceiveHandler extends Handler {
export async function apply() { export async function apply() {
ProblemAdd('problem_receive', {}, 'copy', 'Import From Hydro'); ProblemAdd('problem_receive', {}, 'copy', 'Import From Hydro');
Route('problem_receive', '/problem/receive', ProblemReceiveHandler); Route('problem_receive', '/problem/receive', ProblemReceiveHandler);
Route('problem_send', '/problem/send', ProblemSendHandler, PERM.PERM_VIEW_PROBLEM); Route('problem_send', '/problem/send', ProblemSendHandler);
} }
global.Hydro.handler.remote = apply; global.Hydro.handler.remote = apply;