core&ui: fix defaultPriv edit (#444)

Co-authored-by: undefined <i@undefined.moe>
This commit is contained in:
pandaandundefined authored and GitHub committed 2022-10-18 11:45:00 +08:00
1 parent e964eec099
commit a230d1c7c3
5 files changed
+39 -38

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "4.1.0",
"version": "4.1.1",
"bin": "bin/hydrooj.js",
"main": "src/plugin-api",
"module": "src/plugin-api",
+4 -3
View File
@@ -286,10 +286,11 @@ class SystemUserPrivHandler extends SystemHandler {
}
@requireSudo
@param('uid', Types.Int, true)
@param('uid', Types.Int)
@param('priv', Types.UnsignedInt)
async post(domainId: string, uid: number, priv: number) {
if (typeof uid === 'number') {
@param('system', Types.Boolean, true)
async post(domainId: string, uid: number, priv: number, editSystem: boolean) {
if (!editSystem) {
const udoc = await user.getById(domainId, uid);
if (!udoc) throw new UserNotFoundError(uid);
if (udoc.priv === -1 || priv === -1 || priv === allPriv) throw new ForbiddenError('you can not edit user as SU in web.');
+27 -28
View File
@@ -4,37 +4,36 @@ import i18n from 'vj/utils/i18n';
import tpl from 'vj/utils/tpl';
import createHint from './hint';
let inserted = false;
let hintInserted = false;
$(tpl`<div style="display: none" class="dialog__body--user-select">
<div class="row"><div class="columns">
<h1 name="select_user_hint">${i18n('Select User')}</h1>
</div></div>
<div class="row">
<div class="columns">
<label>${i18n('Username / UID')}
<input name="user" type="text" class="textbox" autocomplete="off" data-autofocus>
</label>
</div>
</div>
</div>`).appendTo(document.body);
const userSelector = UserSelectAutoComplete.getOrConstruct($('.dialog__body--user-select [name="user"]')) as any;
const userSelectDialog = new ActionDialog({
$body: $('.dialog__body--user-select > div'),
onDispatch(action) {
if (action === 'ok' && userSelector.value() === null) {
userSelector.focus();
return false;
}
return true;
},
});
export default async function selectUser(hint?: string) {
if (!inserted) {
const el = $(tpl`<div style="display: none" class="dialog__body--user-select">
<div class="row"><div class="columns">
<h1 name="select_user_hint">${i18n('Select User')}</h1>
</div></div>
<div class="row">
<div class="columns">
<label>${i18n('Username / UID')}
<input name="user" type="text" class="textbox" autocomplete="off" data-autofocus>
</label>
</div>
</div>
</div>`);
el.appendTo(document.body);
if (hint) createHint(hint, $('[name="select_user_hint"]'));
inserted = true;
if (hint && !hintInserted) {
createHint(hint, $('[name="select_user_hint"]'));
hintInserted = true;
}
const userSelector = UserSelectAutoComplete.getOrConstruct($('.dialog__body--user-select [name="user"]')) as any;
const userSelectDialog = new ActionDialog({
$body: $('.dialog__body--user-select > div'),
onDispatch(action) {
if (action === 'ok' && userSelector.value() === null) {
userSelector.focus();
return false;
}
return true;
},
});
userSelector.clear();
const action = await userSelectDialog.open();
if (action !== 'ok') return null;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.41.16",
"version": "4.41.17",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "index.ts",
@@ -20,10 +20,11 @@ const page = new NamedPage('manage_user_priv', () => {
async function changeUserPriv(uid, priv) {
try {
const res = await request.post('', uid !== 'default' ? {
uid,
const res = await request.post('', {
uid: uid !== 'default' ? uid : 0,
priv,
} : { priv });
system: uid === 'default',
});
if (res.url && res.url !== window.location.href) window.location.href = res.url;
else {
Notification.success(i18n('Priv has been updated to {0}.', priv));
@@ -54,8 +55,8 @@ const page = new NamedPage('manage_user_priv', () => {
handleOpenUserPrivDialog(user.udoc);
}
$('[name="select_user"]').on('click', () => handleClickSelectUser());
$('[name="set_priv"]').on('click', (ev) => handleOpenUserPrivDialog(ev));
$(document).on('click', '[name="select_user"]', () => handleClickSelectUser());
$(document).on('click', '[name="set_priv"]', (ev) => handleOpenUserPrivDialog(ev));
});
export default page;