core: fullStatus

This commit is contained in:
undefined committed 2021-06-20 11:48:31 +08:00
1 parent 5153a7a871
commit b2fe14ffe7
5 files changed
+23 -41

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.28.43",
"version": "2.28.44",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+19 -20
View File
@@ -25,10 +25,15 @@ class RecordListHandler extends Handler {
@param('tid', Types.ObjectID, true)
@param('uidOrName', Types.Name, true)
@param('status', Types.Int, true)
@param('fullStatus', Types.Boolean)
@param('allDomain', Types.Boolean, true)
async get(domainId: string, page = 1, pid?: string, tid?: ObjectID, uidOrName?: string, status?: number, all = false) {
async get(
domainId: string, page = 1, pid?: string, tid?: ObjectID,
uidOrName?: string, status?: number, full = false, all = false,
) {
this.response.template = 'record_main.html';
const q: FilterQuery<RecordDoc> = { 'contest.tid': tid, hidden: false };
if (full) uidOrName = this.user._id.toString();
if (tid) {
const tdoc = await contest.get(domainId, tid, -1);
if (!tdoc) throw new ContestNotFoundError(domainId, pid);
@@ -49,27 +54,21 @@ class RecordListHandler extends Handler {
else q.pid = null;
}
if (status) q.status = status;
const [rdocs] = await paginate(
record.getMulti(domainId, q).sort('_id', -1).project(buildProjection(record.PROJECTION_LIST)),
page,
system.get('pagination.record'),
);
let cursor = record.getMulti(domainId, q).sort('_id', -1);
if (!full) cursor = cursor.project(buildProjection(record.PROJECTION_LIST));
const [rdocs] = await paginate(cursor, page, full ? 10 : system.get('pagination.record'));
const canViewProblem = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM);
const canViewProblemHidden = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
const [udict, pdict] = await Promise.all([
user.getList(domainId, rdocs.map((rdoc) => rdoc.uid)),
canViewProblem
? problem.getList(domainId, rdocs.map(
(rdoc) => (rdoc.domainId === domainId ? rdoc.pid : `${rdoc.pdomain}:${rdoc.pid}`),
), canViewProblemHidden, false)
: Object.fromEntries([rdocs.map((rdoc) => [rdoc.pid, { ...problem.default, pid: rdoc.pid }])]),
]);
const path = [
['Hydro', 'homepage'],
['record_main', null],
];
const [udict, pdict] = full ? [{}, {}]
: await Promise.all([
user.getList(domainId, rdocs.map((rdoc) => rdoc.uid)),
canViewProblem
? problem.getList(domainId, rdocs.map(
(rdoc) => (rdoc.domainId === domainId ? rdoc.pid : `${rdoc.pdomain}:${rdoc.pid}`),
), canViewProblemHidden, false)
: Object.fromEntries([rdocs.map((rdoc) => [rdoc.pid, { ...problem.default, pid: rdoc.pid }])]),
]);
this.response.body = {
path,
page,
rdocs,
pdict,
@@ -79,7 +78,7 @@ class RecordListHandler extends Handler {
filterUidOrName: uidOrName,
filterStatus: status,
};
if (this.user.hasPriv(PRIV.PRIV_VIEW_JUDGE_STATISTICS)) {
if (this.user.hasPriv(PRIV.PRIV_VIEW_JUDGE_STATISTICS) && !full) {
this.response.body.statistics = {
...await record.stat(all ? undefined : domainId),
delay: await TaskModel.getDelay({ type: 'judge' }),
-17
View File
@@ -202,23 +202,6 @@ class RecordModel {
return r;
}
@ArgMethod
static getUserInProblemMulti(domainId: string, uid: number, pid: ExternalProblemId | number, contestInfo?: ContestInfo) {
let pdomain = domainId;
if (typeof pid === 'string') {
pdomain = pid.split(':')[0];
pid = +pid.split(':')[1];
}
if (!contestInfo) {
return RecordModel.coll.find({
domainId, uid, pdomain, pid, contest: null,
});
}
return RecordModel.coll.find({
domainId, uid, pdomain, pid, contest: contestInfo,
});
}
@ArgMethod
static getByUid(domainId: string, uid: number, limit: number): Promise<RecordDoc[]> {
return RecordModel.coll.find({ domainId, uid, hidden: false }).sort({ _id: -1 }).limit(limit).toArray();