ui: problem_copy

This commit is contained in:
undefined committed 2021-10-25 15:53:21 +08:00
1 parent 42b73f36a4
commit 0aba9f8215
6 files changed
+40 -10

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "3.1.0",
"version": "3.1.1",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",
+7 -4
View File
@@ -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 });
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.26.1",
"version": "4.26.2",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.js",
@@ -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`
<div class="typo">
<label>
${i18n('Target')}
<div class="textbox-container">
<input name="target" type="text" class="textbox" data-autofocus>
</div>
</label>
</div>
`,
}).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;
-2
View File
@@ -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
@@ -91,7 +91,7 @@
<span class="icon icon-download"></span> {{ _('Download') }}
</a></li>
{% endif %}
{% if handler.user.user.hasPriv(PRIV.PRIV_CREATE_DOMAIN) %}
{% if handler.user.hasPriv(PRIV.PRIV_CREATE_DOMAIN) %}
<li class="menu__item nojs--hide"><a class="menu__link" href="javascript:;" name="problem-sidebar__copy">
<span class="icon icon-copy"></span> {{ _('Copy') }}
</a></li>