mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
core: record_main: allow allDomain option
This commit is contained in:
1 parent
8965a87910
commit
6385a7355b
7 files changed
+35
-18
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.32.19",
|
||||
"version": "2.32.20",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "src/loader",
|
||||
"module": "src/loader",
|
||||
|
||||
@@ -4,7 +4,7 @@ import AdmZip from 'adm-zip';
|
||||
import { Time } from '@hydrooj/utils/lib/utils';
|
||||
import {
|
||||
ContestNotLiveError, ValidationError, ProblemNotFoundError,
|
||||
ContestNotAttendedError, PermissionError, BadRequestError, ContestNotFoundError, InvalidTokenError,
|
||||
ContestNotAttendedError, PermissionError, BadRequestError, ContestNotFoundError, InvalidTokenError, RecordNotFoundError,
|
||||
} from '../error';
|
||||
import { ProblemDoc, Tdoc, User } from '../interface';
|
||||
import paginate from '../lib/paginate';
|
||||
@@ -363,6 +363,7 @@ export class ContestDetailProblemSubmitHandler extends ContestProblemHandler {
|
||||
const pdomainId = typeof pid === 'string' ? pid.split(':')[0] : domainId;
|
||||
const ppid = typeof pid === 'number' ? pid : +pid.split(':')[1];
|
||||
const rdoc = await record.get(domainId, rid);
|
||||
if (!rdoc) throw new RecordNotFoundError(domainId, rid);
|
||||
if (!pretest) {
|
||||
await Promise.all([
|
||||
(this.tsdoc.journal || []).filter((i) => i.pid === pid).length ? Promise.resolve() : problem.inc(pdomainId, ppid, 'nSubmit', 1),
|
||||
|
||||
@@ -53,6 +53,10 @@ class RecordListHandler extends Handler {
|
||||
else invalid = true;
|
||||
}
|
||||
if (status) q.status = status;
|
||||
if (all) {
|
||||
this.checkPriv(PRIV.PRIV_MANAGE_ALL_DOMAIN);
|
||||
q.domainId = { $exists: true };
|
||||
}
|
||||
let cursor = record.getMulti(domainId, q).sort('_id', -1);
|
||||
if (!full) cursor = cursor.project(buildProjection(record.PROJECTION_LIST));
|
||||
const [rdocs] = invalid ? [[]] : await paginate(cursor, page, full ? 10 : system.get('pagination.record'));
|
||||
@@ -73,6 +77,7 @@ class RecordListHandler extends Handler {
|
||||
tdoc,
|
||||
pdict,
|
||||
udict,
|
||||
all,
|
||||
filterPid: pid,
|
||||
filterTid: tid,
|
||||
filterUidOrName: uidOrName,
|
||||
@@ -161,19 +166,24 @@ class RecordDetailHandler extends Handler {
|
||||
|
||||
class RecordMainConnectionHandler extends ConnectionHandler {
|
||||
cleanup: bus.Disposable = () => { };
|
||||
all = false;
|
||||
tid: string;
|
||||
uid: number;
|
||||
pdomain: string;
|
||||
pid: number;
|
||||
status: number;
|
||||
pretest: boolean;
|
||||
pretest = false;
|
||||
|
||||
@param('tid', Types.ObjectID, true)
|
||||
@param('pid', Types.Name, true)
|
||||
@param('uidOrName', Types.Name, true)
|
||||
@param('status', Types.Int, true)
|
||||
@param('pretest', Types.Boolean)
|
||||
async prepare(domainId: string, tid?: ObjectID, pid?: string, uidOrName?: string, status?: number, pretest = false) {
|
||||
@param('allDomain', Types.Boolean)
|
||||
async prepare(
|
||||
domainId: string, tid?: ObjectID, pid?: string, uidOrName?: string,
|
||||
status?: number, pretest = false, all = false,
|
||||
) {
|
||||
if (tid) {
|
||||
const tdoc = await contest.get(domainId, tid, -1);
|
||||
if (!tdoc) throw new ContestNotFoundError(domainId, tid);
|
||||
@@ -202,6 +212,10 @@ class RecordMainConnectionHandler extends ConnectionHandler {
|
||||
} else throw new ProblemNotFoundError(domainId, pid);
|
||||
}
|
||||
if (status) this.status = status;
|
||||
if (all) {
|
||||
this.checkPriv(PRIV.PRIV_MANAGE_ALL_DOMAIN);
|
||||
this.all = true;
|
||||
}
|
||||
this.cleanup = bus.on('record/change', this.onRecordChange.bind(this));
|
||||
}
|
||||
|
||||
@@ -213,9 +227,9 @@ class RecordMainConnectionHandler extends ConnectionHandler {
|
||||
}
|
||||
|
||||
async onRecordChange(rdoc: RecordDoc) {
|
||||
if (!this.pretest && rdoc.input) return;
|
||||
if (rdoc.domainId !== this.domainId) return;
|
||||
if (rdoc.contest && rdoc.contest.tid.toString() !== this.tid) return;
|
||||
if (!this.all && !this.pretest && rdoc.input) return;
|
||||
if (!this.all && rdoc.domainId !== this.domainId) return;
|
||||
if (!this.all && rdoc.contest && rdoc.contest.tid.toString() !== this.tid) return;
|
||||
if (this.uid && rdoc.uid !== this.uid) return;
|
||||
|
||||
// eslint-disable-next-line prefer-const
|
||||
@@ -223,7 +237,7 @@ class RecordMainConnectionHandler extends ConnectionHandler {
|
||||
user.getById(this.domainId, rdoc.uid),
|
||||
problem.get(rdoc.pdomain, rdoc.pid),
|
||||
]);
|
||||
const tdoc = this.tid ? await contest.get(this.domainId, new ObjectID(this.tid), -1) : null;
|
||||
const tdoc = this.tid ? await contest.get(rdoc.domainId, new ObjectID(this.tid), -1) : null;
|
||||
if (pdoc && !rdoc.contest) {
|
||||
if (pdoc.hidden && !this.user.own(pdoc) && !this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN)) pdoc = null;
|
||||
if (!this.user.hasPerm(PERM.PERM_VIEW_PROBLEM)) pdoc = null;
|
||||
|
||||
@@ -36,8 +36,7 @@ export class StorageModel {
|
||||
|
||||
static async get(path: string, savePath?: string) {
|
||||
const { value } = await StorageModel.coll.findOneAndUpdate({ path }, { $set: { lastUsage: new Date() } }, { returnDocument: 'after' });
|
||||
if (value) return await storage.get(value._id, savePath);
|
||||
return await storage.get(path, savePath);
|
||||
return await storage.get(value?._id || path, savePath);
|
||||
}
|
||||
|
||||
static async rename(path: string, newPath: string) {
|
||||
|
||||
@@ -800,8 +800,8 @@ export class ConnectionHandler extends HandlerCommon {
|
||||
const parts = cookie.split('=');
|
||||
cookies[parts[0].trim()] = (parts[1] || '').trim();
|
||||
}
|
||||
this.session = await token.get(cookies.sid || '', token.TYPE_SESSION);
|
||||
if (!this.session) this.session = { uid: 0, domainId: 'system' };
|
||||
this.session = await token.get(cookies.sid || '', token.TYPE_SESSION)
|
||||
|| { uid: 0, domainId: 'system' };
|
||||
}
|
||||
|
||||
@param('cookie', Types.String)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/ui-default",
|
||||
"version": "4.17.3",
|
||||
"version": "4.17.4",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"license": "AGPL-3.0",
|
||||
"main": "hydro.js",
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
{% extends "layout/basic.html" %}
|
||||
{% block content %}
|
||||
{% if filterTid %}
|
||||
{{ set(UiContext, 'socketUrl', "/record-conn?domainId=" + handler.domainId + "&tid=" + filterTid) }}
|
||||
{% else %}
|
||||
{{ set(UiContext, 'socketUrl', "/record-conn?domainId=" + handler.domainId) }}
|
||||
{% endif %}
|
||||
{{ set(
|
||||
UiContext, 'socketUrl',
|
||||
"/record-conn?domainId=" + handler.domainId
|
||||
+ (("&tid=" + filterTid) if filterTid else "")
|
||||
+ (("&uidOrName=" + filterUidOrName) if filterUidOrName else "")
|
||||
+ (("&pid=" + filterPid) if filterPid else "")
|
||||
+ ("&allDomain=1" if all else "")
|
||||
) }}
|
||||
{{ set(UiContext, 'rids', rdocs.map(eval("rdoc=>rdoc._id.toString()"))) }}
|
||||
<div class="row">
|
||||
<div class="medium-12 columns">
|
||||
|
||||
Reference in new issue
Block a user