mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
core: record_list: getHidden by uid
This commit is contained in:
1 parent
a33708cd21
commit
791877098b
7 files changed
+9
-9
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.29.3",
|
"version": "2.29.4",
|
||||||
"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",
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ export class ContestEditHandler extends Handler {
|
|||||||
const endAt = beginAtMoment.clone().add(duration, 'hours').toDate();
|
const endAt = beginAtMoment.clone().add(duration, 'hours').toDate();
|
||||||
if (beginAtMoment.isSameOrAfter(endAt)) throw new ValidationError('duration');
|
if (beginAtMoment.isSameOrAfter(endAt)) throw new ValidationError('duration');
|
||||||
const beginAt = beginAtMoment.toDate();
|
const beginAt = beginAtMoment.toDate();
|
||||||
await problem.getList(domainId, pids, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN), true);
|
await problem.getList(domainId, pids, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id, true);
|
||||||
if (tid) {
|
if (tid) {
|
||||||
await contest.edit(domainId, tid, {
|
await contest.edit(domainId, tid, {
|
||||||
title, content, rule, beginAt, endAt, pids, rated,
|
title, content, rule, beginAt, endAt, pids, rated,
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ class HomeworkEditHandler extends Handler {
|
|||||||
const endAt = penaltySince.clone().add(extensionDays, 'days');
|
const endAt = penaltySince.clone().add(extensionDays, 'days');
|
||||||
if (beginAt.isSameOrAfter(penaltySince)) throw new ValidationError('endAtDate', 'endAtTime');
|
if (beginAt.isSameOrAfter(penaltySince)) throw new ValidationError('endAtDate', 'endAtTime');
|
||||||
if (penaltySince.isAfter(endAt)) throw new ValidationError('extensionDays');
|
if (penaltySince.isAfter(endAt)) throw new ValidationError('extensionDays');
|
||||||
await problem.getList(domainId, pids, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN), true);
|
await problem.getList(domainId, pids, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id, true);
|
||||||
if (!tid) {
|
if (!tid) {
|
||||||
tid = await contest.add(domainId, title, content, this.user._id,
|
tid = await contest.add(domainId, title, content, this.user._id,
|
||||||
'homework', beginAt.toDate(), endAt.toDate(), pids, rated,
|
'homework', beginAt.toDate(), endAt.toDate(), pids, rated,
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class RecordListHandler extends Handler {
|
|||||||
canViewProblem
|
canViewProblem
|
||||||
? problem.getList(domainId, rdocs.map(
|
? problem.getList(domainId, rdocs.map(
|
||||||
(rdoc) => (rdoc.domainId === domainId ? rdoc.pid : `${rdoc.pdomain}:${rdoc.pid}`),
|
(rdoc) => (rdoc.domainId === domainId ? rdoc.pid : `${rdoc.pdomain}:${rdoc.pid}`),
|
||||||
), canViewProblemHidden, false)
|
), canViewProblemHidden || this.user._id, false)
|
||||||
: Object.fromEntries([rdocs.map((rdoc) => [rdoc.pid, { ...problem.default, pid: rdoc.pid }])]),
|
: Object.fromEntries([rdocs.map((rdoc) => [rdoc.pid, { ...problem.default, pid: rdoc.pid }])]),
|
||||||
]);
|
]);
|
||||||
this.response.body = {
|
this.response.body = {
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class TrainingDetailHandler extends Handler {
|
|||||||
const pids = training.getPids(tdoc.dag);
|
const pids = training.getPids(tdoc.dag);
|
||||||
const [owner, pdict] = await Promise.all([
|
const [owner, pdict] = await Promise.all([
|
||||||
user.getById(domainId, tdoc.owner),
|
user.getById(domainId, tdoc.owner),
|
||||||
problem.getList(domainId, pids, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN)),
|
problem.getList(domainId, pids, this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id),
|
||||||
]);
|
]);
|
||||||
const psdict = await problem.getListStatus(domainId, this.user._id, pids);
|
const psdict = await problem.getListStatus(domainId, this.user._id, pids);
|
||||||
const donePids = new Set<number>();
|
const donePids = new Set<number>();
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ class UserDetailHandler extends Handler {
|
|||||||
const pdict = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)
|
const pdict = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)
|
||||||
? await problem.getList(
|
? await problem.getList(
|
||||||
domainId, rdocs.map((rdoc) => rdoc.pid),
|
domainId, rdocs.map((rdoc) => rdoc.pid),
|
||||||
this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN), false,
|
this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id, false,
|
||||||
)
|
)
|
||||||
: Object.fromEntries(rdocs.map(
|
: Object.fromEntries(rdocs.map(
|
||||||
(rdoc) => [rdoc.pid, { ...problem.default, pid: rdoc.pid }],
|
(rdoc) => [rdoc.pid, { ...problem.default, pid: rdoc.pid }],
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ export class ProblemModel {
|
|||||||
|
|
||||||
static async getList(
|
static async getList(
|
||||||
domainId: string, pids: ProblemId[],
|
domainId: string, pids: ProblemId[],
|
||||||
getHidden = false, doThrow = true, projection = ProblemModel.PROJECTION_PUBLIC,
|
getHidden: number | boolean = false, doThrow = true, projection = ProblemModel.PROJECTION_PUBLIC,
|
||||||
): Promise<ProblemDict> {
|
): Promise<ProblemDict> {
|
||||||
const parsed = groupBy(
|
const parsed = groupBy(
|
||||||
Array.from(new Set(pids)).map((i) => ({
|
Array.from(new Set(pids)).map((i) => ({
|
||||||
@@ -266,10 +266,10 @@ export class ProblemModel {
|
|||||||
for (const task in parsed) {
|
for (const task in parsed) {
|
||||||
const range = { $in: parsed[task].map((i) => i.pid) };
|
const range = { $in: parsed[task].map((i) => i.pid) };
|
||||||
const q: any = { $or: [{ docId: range }, { pid: range }] };
|
const q: any = { $or: [{ docId: range }, { pid: range }] };
|
||||||
if (!getHidden) q.hidden = false;
|
|
||||||
tasks.push(document.getMulti(task, document.TYPE_PROBLEM, q).project(buildProjection(projection)).toArray());
|
tasks.push(document.getMulti(task, document.TYPE_PROBLEM, q).project(buildProjection(projection)).toArray());
|
||||||
}
|
}
|
||||||
const pdocs = flatten(await Promise.all(tasks));
|
let pdocs = flatten(await Promise.all(tasks));
|
||||||
|
if (getHidden !== true) pdocs = pdocs.filter((i) => !i.hidden || i.owner === getHidden);
|
||||||
for (const pdoc of pdocs) {
|
for (const pdoc of pdocs) {
|
||||||
try {
|
try {
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
|||||||
Reference in new issue
Block a user