diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index ac58466f8..d9ce75298 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "3.1.0", + "version": "3.1.1", "bin": "bin/hydrooj.js", "main": "src/loader", "module": "src/loader", diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index dbb0b55a5..d9b649947 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -5,9 +5,10 @@ import { lookup } from 'mime-types'; import { FilterQuery, ObjectID } from 'mongodb'; import { sortFiles } from '@hydrooj/utils/lib/utils'; import { - BadRequestError, ContestNotAttendedError, ContestNotFoundError, ContestNotLiveError, ForbiddenError, NoProblemError, - PermissionError, ProblemNotFoundError, SolutionNotFoundError, - ValidationError, + BadRequestError, ContestNotAttendedError, ContestNotFoundError, + ContestNotLiveError, ForbiddenError, NoProblemError, + NotFoundError, PermissionError, ProblemNotFoundError, + SolutionNotFoundError, ValidationError, } from '../error'; import { ProblemDoc, ProblemStatusDoc, Tdoc, User, @@ -293,8 +294,10 @@ export class ProblemDetailHandler extends ProblemHandler { @param('target', Types.String) @param('pid', Types.String, true) async postCopy(domainId: string, target: string, pid: string) { + const ddoc = await domain.get(target); + if (!ddoc) throw new NotFoundError(target); const dudoc = await user.getById(target, this.user._id); - dudoc.checkPerm(PERM.PERM_CREATE_PROBLEM); + if (!dudoc.hasPerm(PERM.PERM_CREATE_PROBLEM)) throw new PermissionError(PERM.PERM_CREATE_PROBLEM); const docId = await problem.copy(domainId, this.user.docId, target, pid); this.response.redirect = this.url('problem_detail', { domainId: target, pid: docId }); } diff --git a/packages/ui-default/package.json b/packages/ui-default/package.json index 7454b7c4c..b2231e66f 100644 --- a/packages/ui-default/package.json +++ b/packages/ui-default/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/ui-default", - "version": "4.26.1", + "version": "4.26.2", "author": "undefined ", "license": "AGPL-3.0", "main": "hydro.js", diff --git a/packages/ui-default/pages/problem_sidebar.page.ts b/packages/ui-default/pages/problem_sidebar.page.ts index 9de87123f..e92d54ca7 100644 --- a/packages/ui-default/pages/problem_sidebar.page.ts +++ b/packages/ui-default/pages/problem_sidebar.page.ts @@ -1,7 +1,9 @@ import { NamedPage } from 'vj/misc/Page'; import tpl from 'vj/utils/tpl'; import i18n from 'vj/utils/i18n'; -import { ConfirmDialog } from 'vj/components/dialog'; +import request from 'vj/utils/request'; +import { ActionDialog, ConfirmDialog } from 'vj/components/dialog'; +import Notification from 'vj/components/notification'; const page = new NamedPage([ 'problem_create', 'problem_edit', 'problem_solution', 'problem_submit', @@ -20,6 +22,33 @@ const page = new NamedPage([ $(ev.currentTarget).closest('form').trigger('submit'); }); }); + $(document).on('click', '[name="problem-sidebar__copy"]', () => { + new ActionDialog({ + $body: tpl` +
+ +
+ `, + }).open().then(async (action) => { + if (action !== 'ok') return; + const target = $('[name="target"]').val(); + if (!target) return; + try { + const res = await request.post('', { + operation: 'copy', + target, + }); + window.location.href = res.url; + } catch (error) { + Notification.error(error.message); + } + }); + }); }); export default page; diff --git a/packages/ui-default/static/robots.txt b/packages/ui-default/static/robots.txt index 731c63e6d..7cf4d17c4 100644 --- a/packages/ui-default/static/robots.txt +++ b/packages/ui-default/static/robots.txt @@ -19,5 +19,3 @@ Disallow: /p/*/edit Disallow: /d/*/p/*/edit Disallow: /p/*/file/ Disallow: /d/*/p/*/file/ -Disallow: /contest/*/p/*/submit -Disallow: /d/*/contest/*/p/*/submit diff --git a/packages/ui-default/templates/partials/problem_sidebar_normal.html b/packages/ui-default/templates/partials/problem_sidebar_normal.html index cb120de06..7ff933232 100644 --- a/packages/ui-default/templates/partials/problem_sidebar_normal.html +++ b/packages/ui-default/templates/partials/problem_sidebar_normal.html @@ -91,7 +91,7 @@ {{ _('Download') }} {% endif %} - {% if handler.user.user.hasPriv(PRIV.PRIV_CREATE_DOMAIN) %} + {% if handler.user.hasPriv(PRIV.PRIV_CREATE_DOMAIN) %}