mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: fix scoreboard_export PERM_VIEW_DISPLAYNAME (#793)
This commit is contained in:
1 parent
a2ed84a4be
commit
87adfd288c
5 files changed
+16
-12
No files matched your search
@@ -314,7 +314,7 @@ export class ContestScoreboardHandler extends ContestDetailBaseHandler {
|
||||
await this.exportScoreboard(domainId, tid, ext);
|
||||
return;
|
||||
}
|
||||
const config: ScoreboardConfig = { isExport: false };
|
||||
const config: ScoreboardConfig = { isExport: false, showDisplayName: this.user.hasPerm(PERM.PERM_VIEW_DISPLAYNAME) };
|
||||
if (!realtime && this.tdoc.lockAt && !this.tdoc.unlocked) {
|
||||
config.lockAt = this.tdoc.lockAt;
|
||||
}
|
||||
@@ -388,7 +388,9 @@ export class ContestScoreboardHandler extends ContestDetailBaseHandler {
|
||||
csv: async (rows) => `\uFEFF${rows.map((c) => (c.map((i) => i.value?.toString().replace(/\n/g, ' ')).join(','))).join('\n')}`,
|
||||
html: (rows, tdoc) => this.renderHTML('contest_scoreboard_download_html.html', { rows, tdoc }),
|
||||
};
|
||||
const [, rows] = await contest.getScoreboard.call(this, domainId, tid, { isExport: true, lockAt: this.tdoc.lockAt });
|
||||
const [, rows] = await contest.getScoreboard.call(this, domainId, tid, {
|
||||
isExport: true, lockAt: this.tdoc.lockAt, showDisplayName: this.user.hasPerm(PERM.PERM_VIEW_DISPLAYNAME),
|
||||
});
|
||||
this.binary(await getContent[ext](rows, this.tdoc), `${this.tdoc.title}.${ext}`);
|
||||
}
|
||||
|
||||
@@ -588,7 +590,7 @@ export class ContestManagementHandler extends ContestManagementBaseHandler {
|
||||
owner_udoc: await user.getById(domainId, this.tdoc.owner),
|
||||
pdict: await problem.getList(domainId, this.tdoc.pids, true, true, [...problem.PROJECTION_CONTEST_LIST, 'tag']),
|
||||
files: sortFiles(this.tdoc.files || []),
|
||||
udict: await user.getListForRender(domainId, tcdocs.map((i) => i.owner)),
|
||||
udict: await user.getListForRender(domainId, tcdocs.map((i) => i.owner), this.user.hasPerm(PERM.PERM_VIEW_DISPLAYNAME)),
|
||||
tcdocs,
|
||||
urlForFile: (filename: string) => this.url('contest_file_download', { tid, filename }),
|
||||
};
|
||||
@@ -693,7 +695,8 @@ export class ContestUserHandler extends ContestManagementBaseHandler {
|
||||
for (const tsdoc of tsdocs) {
|
||||
tsdoc.endAt = (this.tdoc.duration && tsdoc.startAt) ? moment(tsdoc.startAt).add(this.tdoc.duration, 'hours').toDate() : null;
|
||||
}
|
||||
const udict = await user.getListForRender(domainId, [this.tdoc.owner, ...tsdocs.map((i) => i.uid)]);
|
||||
const udict = await user.getListForRender(domainId,
|
||||
[this.tdoc.owner, ...tsdocs.map((i) => i.uid)], this.user.hasPerm(PERM.PERM_VIEW_DISPLAYNAME));
|
||||
this.response.body = { tdoc: this.tdoc, tsdocs, udict };
|
||||
this.response.pjax = 'partials/contest_user.html';
|
||||
this.response.template = 'contest_user.html';
|
||||
@@ -733,7 +736,7 @@ export class ContestBalloonHandler extends ContestManagementBaseHandler {
|
||||
owner_udoc: await user.getById(domainId, this.tdoc.owner),
|
||||
pdict: await problem.getList(domainId, this.tdoc.pids, true, true, problem.PROJECTION_CONTEST_LIST),
|
||||
bdocs,
|
||||
udict: await user.getListForRender(domainId, uids),
|
||||
udict: await user.getListForRender(domainId, uids, this.user.hasPerm(PERM.PERM_VIEW_DISPLAYNAME)),
|
||||
};
|
||||
this.response.pjax = 'partials/contest_balloon.html';
|
||||
this.response.template = 'contest_balloon.html';
|
||||
|
||||
@@ -112,7 +112,7 @@ class TrainingDetailHandler extends Handler {
|
||||
const canViewHidden = this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN) || this.user._id;
|
||||
const [udoc, udict, pdict, psdict, selfPsdict] = await Promise.all([
|
||||
user.getById(domainId, tdoc.owner),
|
||||
user.getListForRender(domainId, enrollUsers),
|
||||
user.getListForRender(domainId, enrollUsers, this.user.hasPerm(PERM.PERM_VIEW_DISPLAYNAME)),
|
||||
problem.getList(domainId, pids, canViewHidden, true),
|
||||
problem.getListStatus(domainId, uid, pids),
|
||||
shouldCompare ? problem.getListStatus(domainId, this.user._id, pids) : {},
|
||||
|
||||
@@ -530,6 +530,7 @@ export interface ContestStat extends Record<string, any> {
|
||||
|
||||
export interface ScoreboardConfig {
|
||||
isExport: boolean;
|
||||
showDisplayName: boolean;
|
||||
lockAt?: Date;
|
||||
}
|
||||
|
||||
|
||||
@@ -222,7 +222,7 @@ const acm = buildContestRule({
|
||||
async scoreboard(config, _, tdoc, pdict, cursor) {
|
||||
const rankedTsdocs = await ranked(cursor, (a, b) => a.score === b.score && a.time === b.time);
|
||||
const uids = rankedTsdocs.map(([, tsdoc]) => tsdoc.uid);
|
||||
const udict = await user.getListForRender(tdoc.domainId, uids);
|
||||
const udict = await user.getListForRender(tdoc.domainId, uids, config.showDisplayName);
|
||||
// Find first accept
|
||||
const first = {};
|
||||
const data = await document.collStatus.aggregate([
|
||||
@@ -388,7 +388,7 @@ const oi = buildContestRule({
|
||||
async scoreboard(config, _, tdoc, pdict, cursor) {
|
||||
const rankedTsdocs = await ranked(cursor, (a, b) => a.score === b.score);
|
||||
const uids = rankedTsdocs.map(([, tsdoc]) => tsdoc.uid);
|
||||
const udict = await user.getListForRender(tdoc.domainId, uids);
|
||||
const udict = await user.getListForRender(tdoc.domainId, uids, config.showDisplayName);
|
||||
const psdict = {};
|
||||
const first = {};
|
||||
await Promise.all(tdoc.pids.map(async (pid) => {
|
||||
@@ -726,7 +726,7 @@ const homework = buildContestRule({
|
||||
async scoreboard(config, _, tdoc, pdict, cursor) {
|
||||
const rankedTsdocs = await ranked(cursor, (a, b) => a.score === b.score);
|
||||
const uids = rankedTsdocs.map(([, tsdoc]) => tsdoc.uid);
|
||||
const udict = await user.getListForRender(tdoc.domainId, uids);
|
||||
const udict = await user.getListForRender(tdoc.domainId, uids, config.showDisplayName);
|
||||
const columns = await this.scoreboardHeader(config, _, tdoc, pdict);
|
||||
const rows: ScoreboardRow[] = [
|
||||
columns,
|
||||
|
||||
@@ -384,16 +384,16 @@ class UserModel {
|
||||
return projection ? coll.find(params).project<Udoc>(buildProjection(projection)) : coll.find(params);
|
||||
}
|
||||
|
||||
static async getListForRender(domainId: string, uids: number[]) {
|
||||
static async getListForRender(domainId: string, uids: number[], showDisplayName = true) {
|
||||
const [udocs, vudocs, dudocs] = await Promise.all([
|
||||
UserModel.getMulti({ _id: { $in: uids } }, ['_id', 'uname', 'mail', 'avatar', 'school', 'studentId']).toArray(),
|
||||
collV.find({ _id: { $in: uids } }).toArray(),
|
||||
domain.getDomainUserMulti(domainId, uids).project({ uid: true, displayName: true }).toArray(),
|
||||
domain.getDomainUserMulti(domainId, uids).project({ uid: true, displayName: showDisplayName }).toArray(),
|
||||
]);
|
||||
const udict = {};
|
||||
for (const udoc of udocs) udict[udoc._id] = udoc;
|
||||
for (const udoc of vudocs) udict[udoc._id] = udoc;
|
||||
for (const dudoc of dudocs) udict[dudoc.uid].displayName = dudoc.displayName;
|
||||
if (showDisplayName) for (const dudoc of dudocs) udict[dudoc.uid].displayName = dudoc.displayName;
|
||||
for (const uid of uids) udict[uid] ||= { ...UserModel.defaultUser };
|
||||
for (const key in udict) {
|
||||
udict[key].school ||= '';
|
||||
|
||||
Reference in new issue
Block a user