mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
bug fixes
This commit is contained in:
5 files changed
+30
-33
No files matched your search
@@ -111,7 +111,7 @@ export const Types = {
|
|||||||
Float: [(v) => +v, (v) => Number.isFinite(+v)],
|
Float: [(v) => +v, (v) => Number.isFinite(+v)],
|
||||||
|
|
||||||
ObjectId: [() => { throw new Error('mongodb package not found'); }, () => true],
|
ObjectId: [() => { throw new Error('mongodb package not found'); }, () => true],
|
||||||
Boolean: [(v) => !!(v && !['false', 'off'].includes(v)), null, true],
|
Boolean: [(v) => !!(v && !['false', 'off', 'no', '0'].includes(v)), null, true],
|
||||||
Date: [
|
Date: [
|
||||||
(v) => {
|
(v) => {
|
||||||
const d = v.split('-');
|
const d = v.split('-');
|
||||||
|
|||||||
@@ -192,23 +192,35 @@ export class ProblemMainHandler extends Handler {
|
|||||||
@param('target', Types.String)
|
@param('target', Types.String)
|
||||||
@param('hidden', Types.Boolean)
|
@param('hidden', Types.Boolean)
|
||||||
async postCopy(domainId: string, pids: number[], target: string, hidden?: boolean) {
|
async postCopy(domainId: string, pids: number[], target: string, hidden?: boolean) {
|
||||||
const t = `,${this.domain.share || ''},`;
|
let t = `,${this.domain.share || ''},`;
|
||||||
if (t !== ',*,' && !t.includes(`,${target},`)) throw new PermissionError(target);
|
if (t !== ',*,' && !t.includes(`,${target},`)) throw new ProblemNotAllowCopyError(this.domain._id, target);
|
||||||
const ddoc = await domain.get(target);
|
let ddoc = await domain.get(target);
|
||||||
if (!ddoc) throw new NotFoundError(target);
|
if (!ddoc) throw new NotFoundError(target);
|
||||||
const dudoc = await user.getById(target, this.user._id);
|
const dudoc = await user.getById(target, this.user._id);
|
||||||
if (!dudoc.hasPerm(PERM.PERM_CREATE_PROBLEM)) throw new PermissionError(PERM.PERM_CREATE_PROBLEM);
|
if (!dudoc.hasPerm(PERM.PERM_CREATE_PROBLEM)) throw new PermissionError(PERM.PERM_CREATE_PROBLEM);
|
||||||
// Check if user can access all those problems
|
// Check if user can access all those problems
|
||||||
await problem.getList(
|
const pdict = await problem.getList(
|
||||||
domainId, pids, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id,
|
domainId, pids, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id,
|
||||||
true, ['docId'], true,
|
true, ['docId'], true,
|
||||||
);
|
);
|
||||||
const ids = [];
|
const ids = [];
|
||||||
for (const pid of pids) {
|
for (const pid of pids) {
|
||||||
|
let pdoc = pdict[pid];
|
||||||
|
if (pdoc.reference) {
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
[pdoc, ddoc] = await Promise.all([
|
||||||
|
problem.get(pdoc.reference.domainId, pdoc.reference.pid),
|
||||||
|
domain.get(pdoc.reference.domainId),
|
||||||
|
]);
|
||||||
|
if (!pdoc) throw new ProblemNotFoundError(pdoc.reference.domainId, pdoc.reference.pid);
|
||||||
|
t = `,${ddoc.share || ''},`;
|
||||||
|
if (t !== ',*,' && !t.includes(`,${target},`)) throw new ProblemNotAllowCopyError(ddoc._id, target);
|
||||||
|
}
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
ids.push(await problem.copy(domainId, pid, target, undefined, hidden));
|
ids.push(await problem.copy(pdoc.domainId, pdoc.docId, target, undefined, hidden));
|
||||||
}
|
}
|
||||||
this.response.body = ids;
|
this.response.body = ids;
|
||||||
|
if (ids.length === 1) this.response.redirect = this.url('problem_detail', { domainId: target, pid: ids[0] });
|
||||||
}
|
}
|
||||||
|
|
||||||
@param('pids', Types.NumericArray)
|
@param('pids', Types.NumericArray)
|
||||||
@@ -420,28 +432,6 @@ export class ProblemDetailHandler extends ContestDetailBaseHandler {
|
|||||||
this.back();
|
this.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
@param('target', Types.String)
|
|
||||||
async postCopy({ }, target: string) {
|
|
||||||
let t = `,${this.domain.share || ''},`;
|
|
||||||
if (t !== ',*,' && !t.includes(`,${target},`)) throw new ProblemNotAllowCopyError(this.domain._id, target);
|
|
||||||
let ddoc = await domain.get(target);
|
|
||||||
if (!ddoc) throw new NotFoundError(target);
|
|
||||||
const dudoc = await user.getById(target, this.user._id);
|
|
||||||
let pdoc = this.pdoc;
|
|
||||||
if (this.pdoc.reference) {
|
|
||||||
[pdoc, ddoc] = await Promise.all([
|
|
||||||
problem.get(this.pdoc.reference.domainId, this.pdoc.reference.pid),
|
|
||||||
domain.get(this.pdoc.reference.domainId),
|
|
||||||
]);
|
|
||||||
if (!pdoc) throw new ProblemNotFoundError(this.pdoc.reference.domainId, this.pdoc.reference.pid);
|
|
||||||
t = `,${ddoc.share || ''},`;
|
|
||||||
if (t !== ',*,' && !t.includes(`,${target},`)) throw new ProblemNotAllowCopyError(ddoc._id, target);
|
|
||||||
}
|
|
||||||
if (!dudoc.hasPerm(PERM.PERM_CREATE_PROBLEM)) throw new PermissionError(PERM.PERM_CREATE_PROBLEM);
|
|
||||||
const docId = await problem.copy(pdoc.domainId, pdoc.docId, target);
|
|
||||||
this.response.redirect = this.url('problem_detail', { domainId: target, pid: docId });
|
|
||||||
}
|
|
||||||
|
|
||||||
async postDelete() {
|
async postDelete() {
|
||||||
if (!this.user.own(this.pdoc, PERM.PERM_EDIT_PROBLEM_SELF)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
|
if (!this.user.own(this.pdoc, PERM.PERM_EDIT_PROBLEM_SELF)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
|
||||||
const tdocs = await contest.getRelated(this.args.domainId, this.pdoc.docId);
|
const tdocs = await contest.getRelated(this.args.domainId, this.pdoc.docId);
|
||||||
|
|||||||
@@ -31,9 +31,8 @@ class MessageModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async sendInfo(to: number, content: string) {
|
static async sendInfo(to: number, content: string) {
|
||||||
const _id = new ObjectId();
|
|
||||||
const mdoc: MessageDoc = {
|
const mdoc: MessageDoc = {
|
||||||
_id, from: 1, to, content, flag: MessageModel.FLAG_INFO | MessageModel.FLAG_I18N,
|
from: 1, to, content, flag: MessageModel.FLAG_INFO | MessageModel.FLAG_I18N,
|
||||||
};
|
};
|
||||||
bus.broadcast('user/message', [to], mdoc);
|
bus.broadcast('user/message', [to], mdoc);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export { default as moment, isMoment } from 'moment-timezone';
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
WebService, Router, HandlerCommon, httpServer,
|
WebService, Router, HandlerCommon, httpServer,
|
||||||
Query, Mutation, Subscription, Apis,
|
Query, Mutation, Subscription, Apis, APIS,
|
||||||
} from '@hydrooj/framework';
|
} from '@hydrooj/framework';
|
||||||
|
|
||||||
export * from './pipelineUtils';
|
export * from './pipelineUtils';
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/* eslint-disable react-refresh/only-export-components */
|
/* eslint-disable react-refresh/only-export-components */
|
||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom/client';
|
||||||
import { i18n, tpl } from 'vj/utils';
|
import { i18n, tpl } from 'vj/utils';
|
||||||
import DomainSelectAutoComplete from '../autocomplete/components/DomainSelectAutoComplete';
|
import DomainSelectAutoComplete from '../autocomplete/components/DomainSelectAutoComplete';
|
||||||
import UserSelectAutoComplete from '../autocomplete/components/UserSelectAutoComplete';
|
import UserSelectAutoComplete from '../autocomplete/components/UserSelectAutoComplete';
|
||||||
@@ -125,6 +126,8 @@ export async function prompt<T extends string>(title: string, fields: Record<T,
|
|||||||
const defaultValues = Object.fromEntries(Object.entries(fields)
|
const defaultValues = Object.fromEntries(Object.entries(fields)
|
||||||
.map(([name, field]: [T, Field]) => [name, field.default || ''])) as Record<T, string | number | boolean>;
|
.map(([name, field]: [T, Field]) => [name, field.default || ''])) as Record<T, string | number | boolean>;
|
||||||
|
|
||||||
|
console.log(valueCache, defaultValues);
|
||||||
|
|
||||||
const Component = () => {
|
const Component = () => {
|
||||||
const [values, setValues] = React.useState(defaultValues);
|
const [values, setValues] = React.useState(defaultValues);
|
||||||
|
|
||||||
@@ -132,7 +135,7 @@ export async function prompt<T extends string>(title: string, fields: Record<T,
|
|||||||
valueCache = values;
|
valueCache = values;
|
||||||
}, [values]);
|
}, [values]);
|
||||||
|
|
||||||
return <div style={{ display: 'none' }}>
|
return <div>
|
||||||
<div className="row"><div className="columns">
|
<div className="row"><div className="columns">
|
||||||
<h1>{title}</h1>
|
<h1>{title}</h1>
|
||||||
</div></div>
|
</div></div>
|
||||||
@@ -169,8 +172,12 @@ export async function prompt<T extends string>(title: string, fields: Record<T,
|
|||||||
</div>)}
|
</div>)}
|
||||||
</div>;
|
</div>;
|
||||||
};
|
};
|
||||||
|
const div = document.createElement('div');
|
||||||
|
const root = ReactDOM.createRoot(div);
|
||||||
|
root.render(<Component />);
|
||||||
const res = await new Dialog({
|
const res = await new Dialog({
|
||||||
$body: $(tpl(<Component />, true)),
|
$body: $(div),
|
||||||
|
$action: [buttonCancel, buttonOk].join('\n'),
|
||||||
onDispatch(action) {
|
onDispatch(action) {
|
||||||
if (action === 'ok') {
|
if (action === 'ok') {
|
||||||
for (const [name, field] of Object.entries(fields)) {
|
for (const [name, field] of Object.entries(fields)) {
|
||||||
@@ -180,6 +187,7 @@ export async function prompt<T extends string>(title: string, fields: Record<T,
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
}).open();
|
}).open();
|
||||||
|
root.unmount();
|
||||||
if (res !== 'ok') return null;
|
if (res !== 'ok') return null;
|
||||||
return valueCache;
|
return valueCache;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user