mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user