From 4fa9df8c9be40f02a8d20ba6da7ab35d8584a447 Mon Sep 17 00:00:00 2001 From: undefined Date: Sat, 29 Oct 2022 14:52:55 +0800 Subject: [PATCH] core&ui: allow admin view contest submissions --- packages/hydrooj/src/entry/common.ts | 6 +++--- packages/hydrooj/src/handler/record.ts | 11 +++++++++-- packages/hydrooj/src/loader.ts | 2 +- packages/ui-default/templates/layout/basic.html | 4 ++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/hydrooj/src/entry/common.ts b/packages/hydrooj/src/entry/common.ts index 5e7f0a926..20a96de90 100644 --- a/packages/hydrooj/src/entry/common.ts +++ b/packages/hydrooj/src/entry/common.ts @@ -88,7 +88,7 @@ export async function locale(pending: string[], fail: string[]) { logger.info('Locale init: %s', i); } catch (e) { fail.push(i); - app.inject('Notification', 'Locale load fail: {0}', { args: [i] }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION); + app.inject('Notification', 'Locale load fail: {0}', { args: [i], type: 'warn' }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION); logger.error('Locale Load Fail: %s', i); logger.error(e); } @@ -130,7 +130,7 @@ export async function setting(pending: string[], fail: string[], modelSetting: t } logger.info('Config load: %s', i); } catch (e) { - app.inject('Notification', 'Config load fail: {0}', { args: [i] }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION); + app.inject('Notification', 'Config load fail: {0}', { args: [i], type: 'warn' }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION); logger.error('Config Load Fail: %s', i); logger.error(e); } @@ -152,7 +152,7 @@ export async function template(pending: string[], fail: string[]) { logger.info('Template init: %s', i); } catch (e) { fail.push(i); - app.inject('Notification', 'Template load fail: {0}', { args: [i] }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION); + app.inject('Notification', 'Template load fail: {0}', { args: [i], type: 'warn' }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION); logger.error('Template Load Fail: %s', i); logger.error(e); } diff --git a/packages/hydrooj/src/handler/record.ts b/packages/hydrooj/src/handler/record.ts index eab6d24d7..6a44f698a 100644 --- a/packages/hydrooj/src/handler/record.ts +++ b/packages/hydrooj/src/handler/record.ts @@ -36,6 +36,7 @@ class RecordListHandler extends ContestDetailBaseHandler { uidOrName?: string, lang?: string, status?: number, full = false, all = false, ) { + const notification = []; let tdoc = null; let invalid = false; this.response.template = 'record_main.html'; @@ -46,8 +47,13 @@ class RecordListHandler extends ContestDetailBaseHandler { this.tdoc = tdoc; if (!tdoc) throw new ContestNotFoundError(domainId, pid); if (!contest.canShowScoreboard.call(this, tdoc, true)) throw new PermissionError(PERM.PERM_VIEW_CONTEST_HIDDEN_SCOREBOARD); - if (!this.user.own(tdoc) && !(await contest.getStatus(domainId, tid, this.user._id))?.attend) { - throw new ContestNotAttendedError(domainId, tid); + if (!(await contest.getStatus(domainId, tid, this.user._id))?.attend) { + if (contest.canShowRecord.call(this, tdoc, true)) { + const name = tdoc.rule === 'homework' + ? "You haven't claimed this homework yet." + : "You haven't attended this contest yet."; + notification.push({ name, args: { type: 'note' }, checker: () => true }); + } else throw new ContestNotAttendedError(domainId, tid); } } if (uidOrName) { @@ -98,6 +104,7 @@ class RecordListHandler extends ContestDetailBaseHandler { filterUidOrName: uidOrName, filterLang: lang, filterStatus: status, + notification, }; if (this.user.hasPriv(PRIV.PRIV_VIEW_JUDGE_STATISTICS) && !full) { this.response.body.statistics = await record.stat(all ? undefined : domainId); diff --git a/packages/hydrooj/src/loader.ts b/packages/hydrooj/src/loader.ts index 8a7e23c1d..790da9f55 100644 --- a/packages/hydrooj/src/loader.ts +++ b/packages/hydrooj/src/loader.ts @@ -97,7 +97,7 @@ export function addon(addonPath: string, prepend = false) { } catch (e) { logger.error(`Addon not found: ${addonPath}`); logger.error(e); - inject('Notification', 'Addon not found: {0}', { args: [addonPath] }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION); + inject('Notification', 'Addon not found: {0}', { args: [addonPath], type: 'warn' }, PRIV.PRIV_VIEW_SYSTEM_NOTIFICATION); } } diff --git a/packages/ui-default/templates/layout/basic.html b/packages/ui-default/templates/layout/basic.html index 4304b0c4a..0f179e580 100644 --- a/packages/ui-default/templates/layout/basic.html +++ b/packages/ui-default/templates/layout/basic.html @@ -6,8 +6,8 @@
{% if UserContext %}{% include "partials/header_mobile.html" %}{% endif %}
- {% for item in ui.getNodes('Notification') %}{% if item.checker(handler) %} -
{{ _(item.name).format(item.args.args or []) }}
+ {% for item in ui.getNodes('Notification').concat(notification or []) %}{% if item.checker(handler) %} +
{{ _(item.name).format(item.args.args or []) }}
{% endif %}{% endfor %} {% block content %}{% endblock %}