core: list all domains for users with PRIV_VIEW_ALL_DOMAIN

This commit is contained in:
undefined committed 2021-05-11 23:38:34 +08:00
1 parent ced60e6567
commit 29965f323b
16 files changed
+53 -26

No files matched your search

+5 -2
View File
@@ -227,8 +227,6 @@ export const PRIV = {
PRIV_USER_PROFILE: 1 << 2,
PRIV_REGISTER_USER: 1 << 3,
PRIV_READ_PROBLEM_DATA: 1 << 4,
PRIV_READ_PRETEST_DATA: 1 << 5, // deprecated
PRIV_READ_PRETEST_DATA_SELF: 1 << 6, // deprecated
PRIV_READ_RECORD_CODE: 1 << 7,
PRIV_VIEW_HIDDEN_RECORD: 1 << 8,
PRIV_JUDGE: 1 << 9, // (renamed)
@@ -239,11 +237,16 @@ export const PRIV = {
PRIV_VIEW_USER_SECRET: 1 << 14,
PRIV_VIEW_JUDGE_STATISTICS: 1 << 15,
PRIV_UNLIMITED_ACCESS: 1 << 22,
PRIV_VIEW_SYSTEM_NOTIFICATION: 1 << 23,
PRIV_ALL: -1,
PRIV_DEFAULT: 0,
PRIV_NEVER: 1 << 20,
/** @deprecated */
PRIV_READ_PRETEST_DATA: 1 << 5,
/** @deprecated */
PRIV_READ_PRETEST_DATA_SELF: 1 << 6,
/** @deprecated */
PRIV_CREATE_FILE: 1 << 16,
/** @deprecated */
+7 -2
View File
@@ -4,13 +4,13 @@ import {
ObjectID, Cursor, FilterQuery, UpdateQuery, OnlyFieldsOfType,
} from 'mongodb';
import {
Pdoc, Ddoc, Drdoc, Tdoc, TrainingDoc, ProblemStatusDoc,
Pdoc, Ddoc, Drdoc, Tdoc, TrainingDoc,
ProblemStatusDoc, User, Content,
} from '../interface';
import { buildProjection } from '../utils';
import { NumberKeys, ArrayKeys, Projection, MaybeArray } from '../typeutils';
import db from '../service/db';
import * as bus from '../service/bus';
import { Content } from '../loader';
type DocID = ObjectID | string | number;
@@ -44,6 +44,11 @@ export interface DocStatusType {
[key: number]: any
}
export async function canView<T extends keyof DocType>(doc: DocType[T], user: User): Promise<boolean> {
if (doc.owner === user._id || doc.maintainers.includes(user._id) || doc.participants.includes(user._id)) return true;
if ()
}
export async function add<T extends keyof DocType, K extends DocType[T]['docId']>(
domainId: string, content: Content, owner: number,
docType: T, docId: K,
+5 -1
View File
@@ -303,7 +303,11 @@ class UserModel {
@ArgMethod
static async setJudge(uid: number) {
return await UserModel.setPriv(uid, PRIV.PRIV_USER_PROFILE | PRIV.PRIV_JUDGE);
return await UserModel.setPriv(
uid,
PRIV.PRIV_USER_PROFILE | PRIV.PRIV_JUDGE | PRIV.PRIV_VIEW_ALL_DOMAIN
| PRIV.PRIV_READ_PROBLEM_DATA,
);
}
@ArgMethod