mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-18 09:36:08 +08:00
core&ui: add PERM_VIEW_HIDDEN_CONTEST and PERM_VIEW_HIDDEN_HOMEWORK (#571)
Co-authored-by: panda <panda_dtdyy@outlook.com>
This commit is contained in:
1 parent
4dcc2a2e78
commit
6cbb5ccfc9
5 files changed
+24
-12
No files matched your search
@@ -74,12 +74,13 @@ ScheduleModel.Worker.addHandler('contest', async (doc) => {
|
||||
export class ContestListHandler extends Handler {
|
||||
@param('rule', Types.Range(contest.RULES), true)
|
||||
@param('page', Types.PositiveInt, true)
|
||||
@param('all', Types.Boolean)
|
||||
async get(domainId: string, rule = '', page = 1, all = false) {
|
||||
async get(domainId: string, rule = '', page = 1) {
|
||||
if (rule && contest.RULES[rule].hidden) throw new BadRequestError();
|
||||
const rules = Object.keys(contest.RULES).filter((i) => !contest.RULES[i].hidden);
|
||||
if (all && !this.user.hasPerm(PERM.PERM_MOD_BADGE)) all = false;
|
||||
const q = { ...all ? { assign: { $in: [...this.user.group, null] } } : {}, ...rule ? { rule } : { rule: { $in: rules } } };
|
||||
const q = {
|
||||
...this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST) ? {} : { $or: [{ assign: { $in: this.user.group } }, { assign: { $size: 0 } }] },
|
||||
...rule ? { rule } : { rule: { $in: rules } },
|
||||
};
|
||||
const cursor = contest.getMulti(domainId, q);
|
||||
const qs = rule ? `rule=${rule}` : '';
|
||||
const [tdocs, tpcount] = await paginate<Tdoc>(cursor, page, system.get('pagination.contest'));
|
||||
@@ -104,7 +105,7 @@ export class ContestDetailBaseHandler extends Handler {
|
||||
contest.get(domainId, tid),
|
||||
contest.getStatus(domainId, tid, this.user._id),
|
||||
]);
|
||||
if (this.tdoc.assign?.length && !this.user.own(this.tdoc)) {
|
||||
if (this.tdoc.assign?.length && !this.user.own(this.tdoc) && !this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST)) {
|
||||
const groups = await user.listGroup(domainId, this.user._id);
|
||||
if (!Set.intersection(this.tdoc.assign, groups.map((i) => i.name)).size) {
|
||||
throw new NotAssignedError('contest', tid);
|
||||
@@ -163,7 +164,7 @@ export class ContestDetailHandler extends Handler {
|
||||
contest.getStatus(domainId, tid, this.user._id),
|
||||
]);
|
||||
if (contest.RULES[this.tdoc.rule].hidden) throw new ContestNotFoundError(domainId, tid);
|
||||
if (this.tdoc.assign?.length && !this.user.own(this.tdoc)) {
|
||||
if (this.tdoc.assign?.length && !this.user.own(this.tdoc) && !this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST)) {
|
||||
const groups = await user.listGroup(domainId, this.user._id);
|
||||
if (!Set.intersection(this.tdoc.assign, groups.map((i) => i.name)).size) {
|
||||
throw new NotAssignedError('contest', tid);
|
||||
@@ -413,7 +414,7 @@ export class ContestEditHandler extends Handler {
|
||||
async postUpdate(
|
||||
domainId: string, tid: ObjectId, beginAtDate: string, beginAtTime: string, duration: number,
|
||||
title: string, content: string, rule: string, _pids: string, rated = false,
|
||||
_code = '', autoHide = false, assign: string[] = null, lock: number = null,
|
||||
_code = '', autoHide = false, assign: string[] = [], lock: number = null,
|
||||
contestDuration: number = null, maintainer: number[] = [], allowViewCode = false,
|
||||
) {
|
||||
if (autoHide) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
|
||||
|
||||
@@ -22,10 +22,11 @@ const convertPenaltyRules = validatePenaltyRules;
|
||||
|
||||
class HomeworkMainHandler extends Handler {
|
||||
@param('page', Types.PositiveInt, true)
|
||||
@param('all', Types.Boolean)
|
||||
async get(domainId: string, page = 1, all = false) {
|
||||
if (all && !this.user.hasPerm(PERM.PERM_MOD_BADGE)) all = false;
|
||||
const cursor = contest.getMulti(domainId, { rule: 'homework', ...all ? { assign: { $in: [...this.user.group, null] } } : {} });
|
||||
async get(domainId: string, page = 1) {
|
||||
const cursor = contest.getMulti(domainId, {
|
||||
rule: 'homework',
|
||||
...this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_HOMEWORK) ? {} : { $or: [{ assign: { $in: this.user.group } }, { assign: { $size: 0 } }] },
|
||||
});
|
||||
const [tdocs, tpcount] = await paginate<Tdoc>(cursor, page, system.get('pagination.contest'));
|
||||
const calendar = [];
|
||||
for (const tdoc of tdocs) {
|
||||
@@ -48,7 +49,7 @@ class HomeworkDetailHandler extends Handler {
|
||||
async prepare(domainId: string, tid: ObjectId) {
|
||||
const tdoc = await contest.get(domainId, tid);
|
||||
if (tdoc.rule !== 'homework') throw new ContestNotFoundError(domainId, tid);
|
||||
if (tdoc.assign?.length && !this.user.own(tdoc)) {
|
||||
if (tdoc.assign?.length && !this.user.own(tdoc) && !this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_HOMEWORK)) {
|
||||
if (!Set.intersection(tdoc.assign, this.user.group).size) {
|
||||
throw new NotAssignedError('homework', tdoc.docId);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user