mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: PERM_VIEW_PROBLEM check for domain_union
This commit is contained in:
1 parent
40edf15782
commit
10e0600b0b
3 files changed
+12
-4
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "3.2.29",
|
"version": "3.2.30",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -154,8 +154,9 @@ export class ProblemMainHandler extends ProblemHandler {
|
|||||||
let [pdocs, ppcount, pcount] = fail
|
let [pdocs, ppcount, pcount] = fail
|
||||||
? [[], 0, 0]
|
? [[], 0, 0]
|
||||||
: await problem.list(
|
: await problem.list(
|
||||||
domainId, query, undefined,
|
domainId, query,
|
||||||
page, system.get('pagination.problem'),
|
page, system.get('pagination.problem'),
|
||||||
|
undefined, this.user._id,
|
||||||
);
|
);
|
||||||
if (sort) pdocs = pdocs.sort((a, b) => sort.indexOf(`${a.domainId}/${a.docId}`) - sort.indexOf(`${b.domainId}/${b.docId}`));
|
if (sort) pdocs = pdocs.sort((a, b) => sort.indexOf(`${a.domainId}/${a.docId}`) - sort.indexOf(`${b.domainId}/${b.docId}`));
|
||||||
if (q) {
|
if (q) {
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ import {
|
|||||||
ArrayKeys, MaybeArray, NumberKeys, Projection,
|
ArrayKeys, MaybeArray, NumberKeys, Projection,
|
||||||
} from '../typeutils';
|
} from '../typeutils';
|
||||||
import { buildProjection } from '../utils';
|
import { buildProjection } from '../utils';
|
||||||
import { STATUS } from './builtin';
|
import { PERM, STATUS } from './builtin';
|
||||||
import * as document from './document';
|
import * as document from './document';
|
||||||
import DomainModel from './domain';
|
import DomainModel from './domain';
|
||||||
import storage from './storage';
|
import storage from './storage';
|
||||||
|
import user from './user';
|
||||||
|
|
||||||
export interface ProblemDoc extends Document { }
|
export interface ProblemDoc extends Document { }
|
||||||
export type Field = keyof ProblemDoc;
|
export type Field = keyof ProblemDoc;
|
||||||
@@ -136,7 +137,8 @@ export class ProblemModel {
|
|||||||
|
|
||||||
static async list(
|
static async list(
|
||||||
domainId: string, query: FilterQuery<ProblemDoc>,
|
domainId: string, query: FilterQuery<ProblemDoc>,
|
||||||
projection = ProblemModel.PROJECTION_LIST, page: number, pageSize: number,
|
page: number, pageSize: number,
|
||||||
|
projection = ProblemModel.PROJECTION_LIST, uid?: number,
|
||||||
): Promise<[ProblemDoc[], number, number]> {
|
): Promise<[ProblemDoc[], number, number]> {
|
||||||
const union = await DomainModel.getUnion(domainId);
|
const union = await DomainModel.getUnion(domainId);
|
||||||
const domainIds = [domainId];
|
const domainIds = [domainId];
|
||||||
@@ -145,6 +147,11 @@ export class ProblemModel {
|
|||||||
const pdocs = [];
|
const pdocs = [];
|
||||||
for (const id of domainIds) {
|
for (const id of domainIds) {
|
||||||
// TODO enhance performance
|
// TODO enhance performance
|
||||||
|
if (uid) {
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
const udoc = await user.getById(id, uid);
|
||||||
|
if (!udoc.hasPerm(PERM.PERM_VIEW_PROBLEM)) continue;
|
||||||
|
}
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
const ccount = await document.getMulti(id, document.TYPE_PROBLEM, query).count();
|
const ccount = await document.getMulti(id, document.TYPE_PROBLEM, query).count();
|
||||||
if (pdocs.length < pageSize && (page - 1) * pageSize - count <= ccount) {
|
if (pdocs.length < pageSize && (page - 1) * pageSize - count <= ccount) {
|
||||||
|
|||||||
Reference in new issue
Block a user