Skip to content

Commit 1232e8f

Browse files
committed
bug fixes
1 parent d4271b3 commit 1232e8f

5 files changed

Lines changed: 30 additions & 33 deletions

File tree

framework/framework/validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export const Types = {
111111
Float: [(v) => +v, (v) => Number.isFinite(+v)],
112112

113113
ObjectId: [() => { throw new Error('mongodb package not found'); }, () => true],
114-
Boolean: [(v) => !!(v && !['false', 'off'].includes(v)), null, true],
114+
Boolean: [(v) => !!(v && !['false', 'off', 'no', '0'].includes(v)), null, true],
115115
Date: [
116116
(v) => {
117117
const d = v.split('-');

packages/hydrooj/src/handler/problem.ts

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -192,23 +192,35 @@ export class ProblemMainHandler extends Handler {
192192
@param('target', Types.String)
193193
@param('hidden', Types.Boolean)
194194
async postCopy(domainId: string, pids: number[], target: string, hidden?: boolean) {
195-
const t = `,${this.domain.share || ''},`;
196-
if (t !== ',*,' && !t.includes(`,${target},`)) throw new PermissionError(target);
197-
const ddoc = await domain.get(target);
195+
let t = `,${this.domain.share || ''},`;
196+
if (t !== ',*,' && !t.includes(`,${target},`)) throw new ProblemNotAllowCopyError(this.domain._id, target);
197+
let ddoc = await domain.get(target);
198198
if (!ddoc) throw new NotFoundError(target);
199199
const dudoc = await user.getById(target, this.user._id);
200200
if (!dudoc.hasPerm(PERM.PERM_CREATE_PROBLEM)) throw new PermissionError(PERM.PERM_CREATE_PROBLEM);
201201
// Check if user can access all those problems
202-
await problem.getList(
202+
const pdict = await problem.getList(
203203
domainId, pids, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id,
204204
true, ['docId'], true,
205205
);
206206
const ids = [];
207207
for (const pid of pids) {
208+
let pdoc = pdict[pid];
209+
if (pdoc.reference) {
210+
// eslint-disable-next-line no-await-in-loop
211+
[pdoc, ddoc] = await Promise.all([
212+
problem.get(pdoc.reference.domainId, pdoc.reference.pid),
213+
domain.get(pdoc.reference.domainId),
214+
]);
215+
if (!pdoc) throw new ProblemNotFoundError(pdoc.reference.domainId, pdoc.reference.pid);
216+
t = `,${ddoc.share || ''},`;
217+
if (t !== ',*,' && !t.includes(`,${target},`)) throw new ProblemNotAllowCopyError(ddoc._id, target);
218+
}
208219
// eslint-disable-next-line no-await-in-loop
209-
ids.push(await problem.copy(domainId, pid, target, undefined, hidden));
220+
ids.push(await problem.copy(pdoc.domainId, pdoc.docId, target, undefined, hidden));
210221
}
211222
this.response.body = ids;
223+
if (ids.length === 1) this.response.redirect = this.url('problem_detail', { domainId: target, pid: ids[0] });
212224
}
213225

214226
@param('pids', Types.NumericArray)
@@ -420,28 +432,6 @@ export class ProblemDetailHandler extends ContestDetailBaseHandler {
420432
this.back();
421433
}
422434

423-
@param('target', Types.String)
424-
async postCopy({ }, target: string) {
425-
let t = `,${this.domain.share || ''},`;
426-
if (t !== ',*,' && !t.includes(`,${target},`)) throw new ProblemNotAllowCopyError(this.domain._id, target);
427-
let ddoc = await domain.get(target);
428-
if (!ddoc) throw new NotFoundError(target);
429-
const dudoc = await user.getById(target, this.user._id);
430-
let pdoc = this.pdoc;
431-
if (this.pdoc.reference) {
432-
[pdoc, ddoc] = await Promise.all([
433-
problem.get(this.pdoc.reference.domainId, this.pdoc.reference.pid),
434-
domain.get(this.pdoc.reference.domainId),
435-
]);
436-
if (!pdoc) throw new ProblemNotFoundError(this.pdoc.reference.domainId, this.pdoc.reference.pid);
437-
t = `,${ddoc.share || ''},`;
438-
if (t !== ',*,' && !t.includes(`,${target},`)) throw new ProblemNotAllowCopyError(ddoc._id, target);
439-
}
440-
if (!dudoc.hasPerm(PERM.PERM_CREATE_PROBLEM)) throw new PermissionError(PERM.PERM_CREATE_PROBLEM);
441-
const docId = await problem.copy(pdoc.domainId, pdoc.docId, target);
442-
this.response.redirect = this.url('problem_detail', { domainId: target, pid: docId });
443-
}
444-
445435
async postDelete() {
446436
if (!this.user.own(this.pdoc, PERM.PERM_EDIT_PROBLEM_SELF)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
447437
const tdocs = await contest.getRelated(this.args.domainId, this.pdoc.docId);

packages/hydrooj/src/model/message.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ class MessageModel {
3131
}
3232

3333
static async sendInfo(to: number, content: string) {
34-
const _id = new ObjectId();
3534
const mdoc: MessageDoc = {
36-
_id, from: 1, to, content, flag: MessageModel.FLAG_INFO | MessageModel.FLAG_I18N,
35+
from: 1, to, content, flag: MessageModel.FLAG_INFO | MessageModel.FLAG_I18N,
3736
};
3837
bus.broadcast('user/message', [to], mdoc);
3938
}

packages/hydrooj/src/plugin-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export { default as moment, isMoment } from 'moment-timezone';
66

77
export {
88
WebService, Router, HandlerCommon, httpServer,
9-
Query, Mutation, Subscription, Apis,
9+
Query, Mutation, Subscription, Apis, APIS,
1010
} from '@hydrooj/framework';
1111

1212
export * from './pipelineUtils';

packages/ui-default/components/dialog/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable react-refresh/only-export-components */
22
import $ from 'jquery';
33
import React from 'react';
4+
import ReactDOM from 'react-dom/client';
45
import { i18n, tpl } from 'vj/utils';
56
import DomainSelectAutoComplete from '../autocomplete/components/DomainSelectAutoComplete';
67
import UserSelectAutoComplete from '../autocomplete/components/UserSelectAutoComplete';
@@ -125,14 +126,16 @@ export async function prompt<T extends string>(title: string, fields: Record<T,
125126
const defaultValues = Object.fromEntries(Object.entries(fields)
126127
.map(([name, field]: [T, Field]) => [name, field.default || ''])) as Record<T, string | number | boolean>;
127128

129+
console.log(valueCache, defaultValues);
130+
128131
const Component = () => {
129132
const [values, setValues] = React.useState(defaultValues);
130133

131134
React.useEffect(() => {
132135
valueCache = values;
133136
}, [values]);
134137

135-
return <div style={{ display: 'none' }}>
138+
return <div>
136139
<div className="row"><div className="columns">
137140
<h1>{title}</h1>
138141
</div></div>
@@ -169,8 +172,12 @@ export async function prompt<T extends string>(title: string, fields: Record<T,
169172
</div>)}
170173
</div>;
171174
};
175+
const div = document.createElement('div');
176+
const root = ReactDOM.createRoot(div);
177+
root.render(<Component />);
172178
const res = await new Dialog({
173-
$body: $(tpl(<Component />, true)),
179+
$body: $(div),
180+
$action: [buttonCancel, buttonOk].join('\n'),
174181
onDispatch(action) {
175182
if (action === 'ok') {
176183
for (const [name, field] of Object.entries(fields)) {
@@ -180,6 +187,7 @@ export async function prompt<T extends string>(title: string, fields: Record<T,
180187
return true;
181188
},
182189
}).open();
190+
root.unmount();
183191
if (res !== 'ok') return null;
184192
return valueCache;
185193
}

0 commit comments

Comments
 (0)