mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: fix defaultPriv edit (#444)
Co-authored-by: undefined <i@undefined.moe>
This commit is contained in:
1 parent
e964eec099
commit
a230d1c7c3
5 files changed
+39
-38
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "4.1.0",
|
"version": "4.1.1",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/plugin-api",
|
"main": "src/plugin-api",
|
||||||
"module": "src/plugin-api",
|
"module": "src/plugin-api",
|
||||||
|
|||||||
@@ -286,10 +286,11 @@ class SystemUserPrivHandler extends SystemHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@requireSudo
|
@requireSudo
|
||||||
@param('uid', Types.Int, true)
|
@param('uid', Types.Int)
|
||||||
@param('priv', Types.UnsignedInt)
|
@param('priv', Types.UnsignedInt)
|
||||||
async post(domainId: string, uid: number, priv: number) {
|
@param('system', Types.Boolean, true)
|
||||||
if (typeof uid === 'number') {
|
async post(domainId: string, uid: number, priv: number, editSystem: boolean) {
|
||||||
|
if (!editSystem) {
|
||||||
const udoc = await user.getById(domainId, uid);
|
const udoc = await user.getById(domainId, uid);
|
||||||
if (!udoc) throw new UserNotFoundError(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.');
|
if (udoc.priv === -1 || priv === -1 || priv === allPriv) throw new ForbiddenError('you can not edit user as SU in web.');
|
||||||
|
|||||||
@@ -4,37 +4,36 @@ import i18n from 'vj/utils/i18n';
|
|||||||
import tpl from 'vj/utils/tpl';
|
import tpl from 'vj/utils/tpl';
|
||||||
import createHint from './hint';
|
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) {
|
export default async function selectUser(hint?: string) {
|
||||||
if (!inserted) {
|
if (hint && !hintInserted) {
|
||||||
const el = $(tpl`<div style="display: none" class="dialog__body--user-select">
|
createHint(hint, $('[name="select_user_hint"]'));
|
||||||
<div class="row"><div class="columns">
|
hintInserted = true;
|
||||||
<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;
|
|
||||||
}
|
}
|
||||||
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();
|
userSelector.clear();
|
||||||
const action = await userSelectDialog.open();
|
const action = await userSelectDialog.open();
|
||||||
if (action !== 'ok') return null;
|
if (action !== 'ok') return null;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/ui-default",
|
"name": "@hydrooj/ui-default",
|
||||||
"version": "4.41.16",
|
"version": "4.41.17",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
|
|||||||
@@ -20,10 +20,11 @@ const page = new NamedPage('manage_user_priv', () => {
|
|||||||
|
|
||||||
async function changeUserPriv(uid, priv) {
|
async function changeUserPriv(uid, priv) {
|
||||||
try {
|
try {
|
||||||
const res = await request.post('', uid !== 'default' ? {
|
const res = await request.post('', {
|
||||||
uid,
|
uid: uid !== 'default' ? uid : 0,
|
||||||
priv,
|
priv,
|
||||||
} : { priv });
|
system: uid === 'default',
|
||||||
|
});
|
||||||
if (res.url && res.url !== window.location.href) window.location.href = res.url;
|
if (res.url && res.url !== window.location.href) window.location.href = res.url;
|
||||||
else {
|
else {
|
||||||
Notification.success(i18n('Priv has been updated to {0}.', priv));
|
Notification.success(i18n('Priv has been updated to {0}.', priv));
|
||||||
@@ -54,8 +55,8 @@ const page = new NamedPage('manage_user_priv', () => {
|
|||||||
handleOpenUserPrivDialog(user.udoc);
|
handleOpenUserPrivDialog(user.udoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
$('[name="select_user"]').on('click', () => handleClickSelectUser());
|
$(document).on('click', '[name="select_user"]', () => handleClickSelectUser());
|
||||||
$('[name="set_priv"]').on('click', (ev) => handleOpenUserPrivDialog(ev));
|
$(document).on('click', '[name="set_priv"]', (ev) => handleOpenUserPrivDialog(ev));
|
||||||
});
|
});
|
||||||
|
|
||||||
export default page;
|
export default page;
|
||||||
Reference in new issue
Block a user