mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
core: drop problem-assign
This commit is contained in:
1 parent
7a4681f1e5
commit
8561ce6cd1
10 files changed
+29
-60
No files matched your search
@@ -169,7 +169,7 @@ export class ContestDetailHandler extends ContestDetailBaseHandler {
|
||||
&& !this.user.own(this.tdoc)
|
||||
&& !this.user.hasPerm(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD)
|
||||
) return;
|
||||
const pdict = await problem.getList(domainId, this.tdoc.pids, true, undefined, undefined, problem.PROJECTION_CONTEST_LIST);
|
||||
const pdict = await problem.getList(domainId, this.tdoc.pids, true, true, problem.PROJECTION_CONTEST_LIST);
|
||||
let psdict = {};
|
||||
let rdict = {};
|
||||
if (this.tsdoc) {
|
||||
@@ -252,7 +252,7 @@ export class ContestScoreboardHandler extends ContestDetailBaseHandler {
|
||||
const tdoc = await contest.get(domainId, tid);
|
||||
if (!contest.canShowScoreboard.call(this, tdoc)) throw new ContestScoreboardHiddenError(tid);
|
||||
const [pdict, teams] = await Promise.all([
|
||||
problem.getList(domainId, tdoc.pids, true, undefined, false, undefined, true),
|
||||
problem.getList(domainId, tdoc.pids, true, false, undefined, true),
|
||||
contest.getMultiStatus(domainId, { docId: tid }).toArray(),
|
||||
]);
|
||||
const udict = await user.getList(domainId, teams.map((i) => i.uid));
|
||||
@@ -373,7 +373,7 @@ export class ContestEditHandler extends Handler {
|
||||
if (beginAtMoment.isSameOrAfter(endAt)) throw new ValidationError('duration');
|
||||
const beginAt = beginAtMoment.toDate();
|
||||
const lockAt = lock ? moment(endAt).add(-lock, 'minutes').toDate() : null;
|
||||
await problem.getList(domainId, pids, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id, this.user.group, true);
|
||||
await problem.getList(domainId, pids, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id, true);
|
||||
if (tid) {
|
||||
await contest.edit(domainId, tid, {
|
||||
title, content, rule, beginAt, endAt, pids, rated, duration: contestDuration,
|
||||
|
||||
@@ -64,7 +64,6 @@ registerValue('Problem', [
|
||||
['difficulty', 'Int'],
|
||||
['tag', '[String]'],
|
||||
['hidden', 'Boolean'],
|
||||
['assign', '[String]'],
|
||||
]);
|
||||
|
||||
registerResolver(
|
||||
@@ -74,11 +73,6 @@ registerResolver(
|
||||
const pdoc = await problem.get(ctx.args.domainId, arg.pid || arg.id);
|
||||
if (!pdoc) return null;
|
||||
if (pdoc.hidden) ctx.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||
if (pdoc.assign.length && !ctx.user.own(pdoc)) {
|
||||
if (!Set.intersection(new Set(pdoc.assign), new Set(ctx.user.group)).size) {
|
||||
throw new PermissionError(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||
}
|
||||
}
|
||||
ctx.pdoc = pdoc;
|
||||
return pdoc;
|
||||
},
|
||||
@@ -86,7 +80,7 @@ registerResolver(
|
||||
registerResolver('Query', 'problems(ids: [Int])', '[Problem]', async (arg, ctx) => {
|
||||
ctx.checkPerm(PERM.PERM_VIEW);
|
||||
const res = await problem.getList(ctx.args.domainId, arg.ids, ctx.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || ctx.user._id,
|
||||
ctx.user.group, undefined, undefined, true);
|
||||
undefined, undefined, true);
|
||||
return Object.keys(res).map((id) => res[+id]);
|
||||
}, 'Get a list of problem by ids');
|
||||
registerResolver(
|
||||
@@ -105,7 +99,7 @@ registerResolver(
|
||||
},
|
||||
);
|
||||
registerResolver(
|
||||
'ProblemManage', 'edit(title: String, content: String, tag: [String], hidden: Boolean, assign: [String])', 'Problem!',
|
||||
'ProblemManage', 'edit(title: String, content: String, tag: [String], hidden: Boolean)', 'Problem!',
|
||||
(arg, ctx) => problem.edit(ctx.args.domainId, ctx.pdoc.docId, arg),
|
||||
);
|
||||
|
||||
@@ -640,14 +634,13 @@ export class ProblemEditHandler extends ProblemManageHandler {
|
||||
@post('hidden', Types.Boolean)
|
||||
@post('tag', Types.Content, true, null, parseCategory)
|
||||
@post('difficulty', Types.PositiveInt, (i) => +i <= 10, true)
|
||||
@post('assign', Types.CommaSeperatedArray, true)
|
||||
async post(
|
||||
domainId: string, pid: string | number, title: string, content: string,
|
||||
newPid: string = '', hidden = false, tag: string[] = [], difficulty = 0, assign: string[] = [],
|
||||
newPid: string = '', hidden = false, tag: string[] = [], difficulty = 0,
|
||||
) {
|
||||
if (newPid !== this.pdoc.pid && await problem.get(domainId, newPid)) throw new BadRequestError('new pid exists');
|
||||
const $update: Partial<ProblemDoc> = {
|
||||
title, content, pid: newPid, hidden, assign, tag: tag ?? [], difficulty, html: false,
|
||||
title, content, pid: newPid, hidden, tag: tag ?? [], difficulty, html: false,
|
||||
};
|
||||
const pdoc = await problem.edit(domainId, this.pdoc.docId, $update);
|
||||
this.response.redirect = this.url('problem_detail', { pid: newPid || pdoc.docId });
|
||||
@@ -972,13 +965,12 @@ export class ProblemCreateHandler extends Handler {
|
||||
@post('hidden', Types.Boolean)
|
||||
@post('difficulty', Types.PositiveInt, (i) => +i <= 10, true)
|
||||
@post('tag', Types.Content, true, null, parseCategory)
|
||||
@post('assign', Types.CommaSeperatedArray, true)
|
||||
async post(
|
||||
domainId: string, title: string, content: string, pid: string,
|
||||
hidden = false, difficulty = 0, tag: string[] = [], assign: string[] = [],
|
||||
hidden = false, difficulty = 0, tag: string[] = [],
|
||||
) {
|
||||
if (pid && await problem.get(domainId, pid)) throw new BadRequestError('ProblemID already exists');
|
||||
const docId = await problem.add(domainId, pid, title, content, this.user._id, tag ?? [], hidden, assign);
|
||||
const docId = await problem.add(domainId, pid, title, content, this.user._id, tag ?? [], hidden);
|
||||
const files = new Set(Array.from(content.matchAll(/file:\/\/([a-zA-Z0-9_-]+\.[a-zA-Z0-9]+)/g)).map((i) => i[1]));
|
||||
const tasks = [];
|
||||
for (const file of files) {
|
||||
|
||||
@@ -89,7 +89,7 @@ class RecordListHandler extends ContestDetailBaseHandler {
|
||||
: await Promise.all([
|
||||
user.getList(domainId, rdocs.map((rdoc) => rdoc.uid)),
|
||||
canViewProblem
|
||||
? problem.getList(domainId, rdocs.map((rdoc) => rdoc.pid), canViewHiddenProblem, this.user.group, false)
|
||||
? problem.getList(domainId, rdocs.map((rdoc) => rdoc.pid), canViewHiddenProblem, false)
|
||||
: Object.fromEntries([rdocs.map((rdoc) => [rdoc.pid, { ...problem.default, pid: rdoc.pid }])]),
|
||||
]);
|
||||
this.response.body = {
|
||||
|
||||
@@ -98,7 +98,7 @@ class TrainingDetailHandler extends Handler {
|
||||
const canViewHidden = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id;
|
||||
const [owner, pdict] = await Promise.all([
|
||||
user.getById(domainId, tdoc.owner),
|
||||
problem.getList(domainId, pids, canViewHidden, this.user.group, true),
|
||||
problem.getList(domainId, pids, canViewHidden, true),
|
||||
]);
|
||||
const psdict = await problem.getListStatus(domainId, this.user._id, pids);
|
||||
const donePids = new Set<number>();
|
||||
|
||||
@@ -344,7 +344,7 @@ class UserDetailHandler extends Handler {
|
||||
pdocs.push(...Object.values(
|
||||
await problem.getList(
|
||||
did, psdocs.map((i) => i.docId), canViewHidden,
|
||||
this.user.group, false, problem.PROJECTION_LIST, true,
|
||||
false, problem.PROJECTION_LIST, true,
|
||||
),
|
||||
));
|
||||
}));
|
||||
@@ -366,7 +366,7 @@ class UserDetailHandler extends Handler {
|
||||
if (this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)) {
|
||||
this.response.body.pdict = await problem.getList(
|
||||
domainId, psdocs.map((i) => i.parentId), canViewHidden,
|
||||
this.user.group, false, problem.PROJECTION_LIST,
|
||||
false, problem.PROJECTION_LIST,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,7 +229,6 @@ declare module './model/problem' {
|
||||
data: FileInfo[];
|
||||
additional_file: FileInfo[];
|
||||
hidden?: boolean;
|
||||
assign: string[];
|
||||
html?: boolean;
|
||||
stats?: any;
|
||||
difficulty?: number;
|
||||
|
||||
@@ -726,7 +726,7 @@ export async function getScoreboard(
|
||||
const tdoc = await get(domainId, tid);
|
||||
if (!canShowScoreboard.call(this, tdoc)) throw new ContestScoreboardHiddenError(tid);
|
||||
const tsdocsCursor = getMultiStatus(domainId, { docId: tid }).sort(RULES[tdoc.rule].statusSort);
|
||||
const pdict = await problem.getList(domainId, tdoc.pids, true, problem.PROJECTION_CONTEST_DETAIL);
|
||||
const pdict = await problem.getList(domainId, tdoc.pids, true, true, problem.PROJECTION_CONTEST_DETAIL);
|
||||
const [rows, udict] = await RULES[tdoc.rule].scoreboard(
|
||||
isExport, this.translate.bind(this),
|
||||
tdoc, pdict, tsdocsCursor,
|
||||
|
||||
@@ -28,7 +28,7 @@ function sortable(source: string) {
|
||||
export class ProblemModel {
|
||||
static PROJECTION_CONTEST_LIST: Field[] = [
|
||||
'_id', 'domainId', 'docType', 'docId', 'pid',
|
||||
'owner', 'title', 'assign',
|
||||
'owner', 'title',
|
||||
];
|
||||
|
||||
static PROJECTION_LIST: Field[] = [
|
||||
@@ -66,7 +66,6 @@ export class ProblemModel {
|
||||
additional_file: [],
|
||||
stats: {},
|
||||
hidden: true,
|
||||
assign: [],
|
||||
config: '',
|
||||
difficulty: 0,
|
||||
};
|
||||
@@ -88,31 +87,30 @@ export class ProblemModel {
|
||||
additional_file: [],
|
||||
stats: {},
|
||||
hidden: true,
|
||||
assign: [],
|
||||
config: '',
|
||||
difficulty: 0,
|
||||
};
|
||||
|
||||
static async add(
|
||||
domainId: string, pid: string = '', title: string, content: string, owner: number,
|
||||
tag: string[] = [], hidden = false, assign: string[] = [],
|
||||
tag: string[] = [], hidden = false,
|
||||
) {
|
||||
const [doc] = await ProblemModel.getMulti(domainId, {})
|
||||
.sort({ docId: -1 }).limit(1).project({ docId: 1 })
|
||||
.toArray();
|
||||
const result = await ProblemModel.addWithId(
|
||||
domainId, (doc?.docId || 0) + 1, pid,
|
||||
title, content, owner, tag, hidden, assign,
|
||||
title, content, owner, tag, hidden,
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
static async addWithId(
|
||||
domainId: string, docId: number, pid: string = '', title: string,
|
||||
content: string, owner: number, tag: string[] = [], hidden = false, assign: string[] = [],
|
||||
content: string, owner: number, tag: string[] = [], hidden = false,
|
||||
) {
|
||||
const args: Partial<ProblemDoc> = {
|
||||
title, tag, hidden, assign, nSubmit: 0, nAccept: 0, sort: sortable(pid || `P${docId}`),
|
||||
title, tag, hidden, nSubmit: 0, nAccept: 0, sort: sortable(pid || `P${docId}`),
|
||||
};
|
||||
if (pid) args.pid = pid;
|
||||
await bus.parallel('problem/before-add', domainId, content, owner, docId, args);
|
||||
@@ -298,8 +296,7 @@ export class ProblemModel {
|
||||
|
||||
static async getList(
|
||||
domainId: string, pids: number[], canViewHidden: number | boolean = false,
|
||||
group: string[] = [], doThrow = true, projection = ProblemModel.PROJECTION_PUBLIC,
|
||||
indexByDocIdOnly = false,
|
||||
doThrow = true, projection = ProblemModel.PROJECTION_PUBLIC, indexByDocIdOnly = false,
|
||||
): Promise<ProblemDict> {
|
||||
if (!pids?.length) return [];
|
||||
const r: Record<number, ProblemDoc> = {};
|
||||
@@ -307,9 +304,6 @@ export class ProblemModel {
|
||||
const q: any = { docId: { $in: pids } };
|
||||
let pdocs = await document.getMulti(domainId, document.TYPE_PROBLEM, q)
|
||||
.project(buildProjection(projection)).toArray();
|
||||
if (group.length > 0 && canViewHidden !== true) {
|
||||
pdocs = pdocs.filter((i) => !i.assign?.length || Set.intersection(group, i.assign).size);
|
||||
}
|
||||
if (canViewHidden !== true) {
|
||||
pdocs = pdocs.filter((i) => i.owner === canViewHidden || i.maintainer?.includes(canViewHidden as any) || !i.hidden);
|
||||
}
|
||||
@@ -383,8 +377,7 @@ export class ProblemModel {
|
||||
if (udoc.own(pdoc)) return true;
|
||||
if (udoc.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN)) return true;
|
||||
if (pdoc.hidden) return false;
|
||||
if (!pdoc.assign.length) return true;
|
||||
return !!Set.intersection(pdoc.assign, udoc.group).size;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -385,14 +385,7 @@ const scripts: UpgradeScript[] = [
|
||||
await db.collection('oplog').deleteMany({ type: 'user.login' });
|
||||
return true;
|
||||
},
|
||||
async function _57_58() {
|
||||
const _FRESH_INSTALL_IGNORE = 1;
|
||||
await db.collection('document').updateMany(
|
||||
{ docType: document.TYPE_PROBLEM, assign: null },
|
||||
{ $set: { assign: [] } },
|
||||
);
|
||||
return true;
|
||||
},
|
||||
null,
|
||||
async function _58_59() {
|
||||
const _FRESH_INSTALL_IGNORE = 1;
|
||||
const tasks = await db.collection('task').find({ type: 'schedule', subType: 'contest.problemHide' }).toArray();
|
||||
|
||||
@@ -6,12 +6,6 @@
|
||||
<div class="section__body">
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="medium-7 columns">
|
||||
<label>
|
||||
{{ _('Title') }}
|
||||
<input name="title" placeholder="{{ _('title') }}" value="{{ pdoc['title']|default('') }}" class="textbox"{% if page_name == 'problem_create' %} autofocus{% endif %}>
|
||||
</label>
|
||||
</div>
|
||||
<div class="medium-3 columns">
|
||||
<label>
|
||||
{{ _('pid') }}
|
||||
@@ -21,6 +15,12 @@
|
||||
</label>
|
||||
</label>
|
||||
</div>
|
||||
<div class="medium-7 columns">
|
||||
<label>
|
||||
{{ _('Title') }}
|
||||
<input name="title" placeholder="{{ _('title') }}" value="{{ pdoc['title']|default('') }}" class="textbox"{% if page_name == 'problem_create' %} autofocus{% endif %}>
|
||||
</label>
|
||||
</div>
|
||||
<div class="medium-2 columns">
|
||||
<label>
|
||||
<br>
|
||||
@@ -33,20 +33,12 @@
|
||||
<div class="row">
|
||||
{{ form.form_text({
|
||||
row:false,
|
||||
columns:6,
|
||||
columns:9,
|
||||
label:'Tags',
|
||||
help_text:'Split by \', \'.',
|
||||
name:'tag',
|
||||
value:pdoc['tag']|default([])|join(', ')
|
||||
}) }}
|
||||
{{ form.form_text({
|
||||
row:false,
|
||||
columns:3,
|
||||
label:'Assign',
|
||||
placeholder:_('Group / UID'),
|
||||
name:'assign',
|
||||
value:pdoc.assign|default([])|join(', ')
|
||||
}) }}
|
||||
{{ form.form_text({
|
||||
row:false,
|
||||
columns:3,
|
||||
|
||||
Reference in new issue
Block a user