core: feat: problem_send

This commit is contained in:
undefined committed 2021-01-24 11:32:35 +08:00
1 parent 62a5bc319b
commit 6fbb7588e1
4 files changed
+35 -4

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.15.31",
"version": "2.15.32",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+31
View File
@@ -2,6 +2,7 @@ import { isSafeInteger, flatten, pick } from 'lodash';
import yaml from 'js-yaml';
import fs from 'fs-extra';
import { FilterQuery, ObjectID } from 'mongodb';
import superagent from 'superagent';
import AdmZip from 'adm-zip';
import {
NoProblemError, BadRequestError, PermissionError,
@@ -17,6 +18,8 @@ import { ProblemAdd } from '../lib/ui';
import * as problem from '../model/problem';
import * as record from '../model/record';
import * as domain from '../model/domain';
import * as system from '../model/system';
import * as token from '../model/token';
import * as user from '../model/user';
import * as solution from '../model/solution';
import { PERM, PRIV, CONSTANT } from '../model/builtin';
@@ -687,6 +690,33 @@ export class ProblemImportHandler extends Handler {
}
}
export class ProblemSendHandler extends Handler {
async get() {
this.response.template = 'problem_send.html';
}
@post('target', Types.String)
@post('pids', Types.Array)
async post(domainId: string, target: any, pids: number[]) {
target = target.split('@');
const getHidden = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
const pdocs = await problem.getList(domainId, pids, getHidden, true);
const getData = this.user.hasPerm(PERM.PERM_READ_PROBLEM_DATA);
if (!getData) {
for (const pid in pdocs) {
if (pdocs[pid].owner !== this.user._id) {
throw new PermissionError(PERM.PERM_READ_PROBLEM_DATA);
}
}
}
const [source, expire] = system.getMany(['server.url', 'session.expire_seconds']);
const tokenId = await token.createOrUpdate(token.TYPE_EXPORT, expire, { domainId, pids });
await superagent.post(`${target[1]}/d/${target[0]}/problem/receive`)
.send({ source, domainId, tokenId });
this.back();
}
}
export async function apply() {
ProblemAdd('problem_import', {}, 'copy', 'Import From Hydro');
Route('problem_main', '/p', ProblemMainHandler, PERM.PERM_VIEW_PROBLEM);
@@ -706,6 +736,7 @@ export async function apply() {
Route('problem_solution_reply_raw', '/p/:pid/solution/:psid/:psrid/raw', ProblemSolutionRawHandler, PERM.PERM_VIEW_PROBLEM);
Route('problem_create', '/problem/create', ProblemCreateHandler, PERM.PERM_CREATE_PROBLEM);
Route('problem_import', '/problem/import', ProblemImportHandler, PERM.PERM_CREATE_PROBLEM);
Route('problem_send', '/problem/send', ProblemSendHandler, PERM.PERM_VIEW_PROBLEM);
Connection('problem_pretest_conn', '/conn/pretest', ProblemPretestConnectionHandler, PERM.PERM_SUBMIT_PROBLEM);
}
+2 -3
View File
@@ -2,6 +2,7 @@ import { Dictionary } from 'lodash';
import { FilterQuery } from 'mongodb';
import { BUILTIN_ROLES, PRIV } from './builtin';
import { DomainDoc } from '../interface';
import { NumberKeys } from '../typeutils';
import * as bus from '../service/bus';
import db from '../service/db';
@@ -56,9 +57,7 @@ export async function get(domainId: string): Promise<DomainDoc | null> {
export async function getByHost(host: string): Promise<DomainDoc | null> {
const query: FilterQuery<DomainDoc> = { host };
await bus.serial('domain/before-get', query);
console.log(query);
const result = await coll.findOne(query);
console.log(result);
await bus.serial('domain/get', result);
return result;
}
@@ -74,7 +73,7 @@ export async function edit(domainId: string, $set: Partial<DomainDoc>) {
return result.value;
}
export async function inc(domainId: string, field: keyof DomainDoc, n: number): Promise<number | null> {
export async function inc(domainId: string, field: NumberKeys<DomainDoc>, n: number): Promise<number | null> {
const res = await coll.findOneAndUpdate(
{ _id: domainId },
// FIXME
+1
View File
@@ -9,6 +9,7 @@ export const TYPE_REGISTRATION = 2;
export const TYPE_CHANGEMAIL = 3;
export const TYPE_OAUTH = 4;
export const TYPE_LOSTPASS = 5;
export const TYPE_EXPORT = 6;
function ensureIndexes() {
return Promise.all([