mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 08:13:12 +09:00
Show ban reason in Web UI
Show and update live the reason given for someone being banned in the Web UI.
This commit is contained in:
1 parent
d184b9db81
commit
9fa41e37f3
3 files changed
+66
-52
No files matched your search
@@ -801,6 +801,7 @@ const userProperties = {
|
|||||||
"is_admin": { type: "boolean" },
|
"is_admin": { type: "boolean" },
|
||||||
"is_banned": { type: "boolean" },
|
"is_banned": { type: "boolean" },
|
||||||
"is_whitelisted": { type: "boolean" },
|
"is_whitelisted": { type: "boolean" },
|
||||||
|
"ban_reason": { type: "string" },
|
||||||
"instances": { type: "array", items: { type: "integer" }},
|
"instances": { type: "array", items: { type: "integer" }},
|
||||||
"is_deleted": { type: "boolean" },
|
"is_deleted": { type: "boolean" },
|
||||||
"player_stats": PlayerStats.jsonSchema,
|
"player_stats": PlayerStats.jsonSchema,
|
||||||
|
|||||||
@@ -577,6 +577,7 @@ class ControlConnection extends BaseConnection {
|
|||||||
is_admin: user.isAdmin,
|
is_admin: user.isAdmin,
|
||||||
is_banned: user.isBanned,
|
is_banned: user.isBanned,
|
||||||
is_whitelisted: user.isWhitelisted,
|
is_whitelisted: user.isWhitelisted,
|
||||||
|
ban_reason: user.banReason,
|
||||||
instances: [...user.instances],
|
instances: [...user.instances],
|
||||||
player_stats: user.playerStats,
|
player_stats: user.playerStats,
|
||||||
instance_stats: [...user.instanceStats],
|
instance_stats: [...user.instanceStats],
|
||||||
@@ -614,6 +615,7 @@ class ControlConnection extends BaseConnection {
|
|||||||
is_admin: user.isAdmin,
|
is_admin: user.isAdmin,
|
||||||
is_banned: user.isBanned,
|
is_banned: user.isBanned,
|
||||||
is_whitelisted: user.isWhitelisted,
|
is_whitelisted: user.isWhitelisted,
|
||||||
|
ban_reason: user.banReason,
|
||||||
instances: [...user.instances],
|
instances: [...user.instances],
|
||||||
player_stats: user.playerStats,
|
player_stats: user.playerStats,
|
||||||
instance_stats: [...user.instanceStats],
|
instance_stats: [...user.instanceStats],
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React, { useEffect, useContext, useState } from "react";
|
|||||||
import { useHistory, useParams } from "react-router-dom";
|
import { useHistory, useParams } from "react-router-dom";
|
||||||
import {
|
import {
|
||||||
Button, Col, Descriptions, Form, Input, PageHeader, Popconfirm,
|
Button, Col, Descriptions, Form, Input, PageHeader, Popconfirm,
|
||||||
Popover, Row, Table, Tag, Select, Space, Spin, Switch,
|
Row, Table, Tag, Select, Space, Spin, Switch,
|
||||||
} from "antd";
|
} from "antd";
|
||||||
import DeleteOutlined from "@ant-design/icons/DeleteOutlined";
|
import DeleteOutlined from "@ant-design/icons/DeleteOutlined";
|
||||||
|
|
||||||
@@ -34,9 +34,9 @@ export default function UserViewPage() {
|
|||||||
let [roles, setRoles] = useState(null);
|
let [roles, setRoles] = useState(null);
|
||||||
let [form] = Form.useForm();
|
let [form] = Form.useForm();
|
||||||
let [rolesDirty, setRolesDirty] = useState(false);
|
let [rolesDirty, setRolesDirty] = useState(false);
|
||||||
|
let [banReasonDirty, setBanReasonDirty] = useState(false);
|
||||||
let [applyingRoles, setApplyingRoles] = useState(false);
|
let [applyingRoles, setApplyingRoles] = useState(false);
|
||||||
let [rolesError, setRolesError] = useState();
|
let [rolesError, setRolesError] = useState();
|
||||||
let [banUserPopover, setBanUserPopover] = useState(false);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
libLink.messages.listRoles.send(control).then(result => {
|
libLink.messages.listRoles.send(control).then(result => {
|
||||||
@@ -46,6 +46,16 @@ export default function UserViewPage() {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
account.hasPermission("core.user.set_banned")
|
||||||
|
&& !banReasonDirty
|
||||||
|
&& user["ban_reason"] !== form.getFieldValue("ban_reason")
|
||||||
|
) {
|
||||||
|
form.setFieldsValue({ "ban_reason": user["ban_reason"] });
|
||||||
|
}
|
||||||
|
}, [account, form, user, banReasonDirty]);
|
||||||
|
|
||||||
let nav = [{ name: "Users", path: "/users" }, { name: userName }];
|
let nav = [{ name: "Users", path: "/users" }, { name: userName }];
|
||||||
if (user.loading) {
|
if (user.loading) {
|
||||||
return <PageLayout nav={nav}>
|
return <PageLayout nav={nav}>
|
||||||
@@ -215,64 +225,65 @@ export default function UserViewPage() {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item label="Banned">
|
{account.hasPermission("core.user.set_banned")
|
||||||
<Space>
|
? <Form.Item label="Ban reason">
|
||||||
{user["is_banned"] ? "Yes" : "No"}
|
<Row gutter={[8, 8]} justify={"end"}>
|
||||||
{account.hasPermission("core.user.set_banned") && <Popover
|
<Col flex="auto" style={{ minWidth: "20em" }}>
|
||||||
title="Ban user"
|
<Form.Item noStyle name="ban_reason" initialValue={user["ban_reason"]}>
|
||||||
visible={banUserPopover}
|
<Input
|
||||||
trigger="click"
|
onChange={e => {
|
||||||
onVisibleChange={() => {
|
setBanReasonDirty(e.target.value !== user["ban_reason"]);
|
||||||
if (!user["is_banned"]) {
|
}}
|
||||||
setBanUserPopover(!banUserPopover);
|
/>
|
||||||
}
|
</Form.Item>
|
||||||
}}
|
</Col>
|
||||||
content={<Form.Item label="Reason">
|
<Col flex="0 0 auto">
|
||||||
<Row gutter={8}>
|
{user["is_banned"]
|
||||||
<Col flex="auto">
|
? <Space>
|
||||||
<Form.Item noStyle name="reason">
|
|
||||||
<Input/>
|
|
||||||
</Form.Item>
|
|
||||||
</Col>
|
|
||||||
<Col flex="0 0 auto">
|
|
||||||
<Button
|
<Button
|
||||||
type="primary"
|
type={banReasonDirty ? "primary" : "default"}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
let reason = form.getFieldValue("reason");
|
|
||||||
libLink.messages.setUserBanned.send(control, {
|
libLink.messages.setUserBanned.send(control, {
|
||||||
name: userName,
|
name: userName,
|
||||||
create: false,
|
create: false,
|
||||||
banned: true,
|
banned: true,
|
||||||
reason,
|
reason: form.getFieldValue("ban_reason"),
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
setBanUserPopover(false);
|
setBanReasonDirty(false);
|
||||||
updateUser();
|
}).catch(notifyErrorHandler("Error updating ban"));
|
||||||
}).catch(notifyErrorHandler("Error banning user"));
|
|
||||||
}}
|
}}
|
||||||
>Ban</Button>
|
>Update</Button>
|
||||||
</Col>
|
<Button
|
||||||
</Row>
|
onClick={() => {
|
||||||
</Form.Item>}
|
libLink.messages.setUserBanned.send(control, {
|
||||||
>
|
name: userName,
|
||||||
<Button
|
create: false,
|
||||||
type="primary"
|
banned: false,
|
||||||
size="small"
|
reason: "",
|
||||||
onClick={() => {
|
}).catch(notifyErrorHandler("Error unbanning user"));
|
||||||
if (user["is_banned"]) {
|
}}
|
||||||
libLink.messages.setUserBanned.send(control, {
|
>Unban</Button>
|
||||||
name: userName,
|
</Space>
|
||||||
create: false,
|
: <Button
|
||||||
banned: false,
|
type={banReasonDirty ? "primary" : "default"}
|
||||||
reason: "",
|
onClick={() => {
|
||||||
}).then(() => {
|
libLink.messages.setUserBanned.send(control, {
|
||||||
updateUser();
|
name: userName,
|
||||||
}).catch(notifyErrorHandler("Error pardoning user"));
|
create: false,
|
||||||
}
|
banned: true,
|
||||||
}}
|
reason: form.getFieldValue("ban_reason"),
|
||||||
>{user["is_banned"] ? "Pardon User" : "Ban User"}</Button>
|
}).then(() => {
|
||||||
</Popover>}
|
setBanReasonDirty(false);
|
||||||
</Space>
|
}).catch(notifyErrorHandler("Error banning user"));
|
||||||
</Form.Item>
|
}}
|
||||||
|
>Ban</Button>
|
||||||
|
}
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
</Form.Item>
|
||||||
|
: user["is_banned"]
|
||||||
|
&& <Form.Item label="Ban reason">{user["ban_reason"]}</Form.Item>
|
||||||
|
}
|
||||||
</Form>
|
</Form>
|
||||||
<SectionHeader title="Player stats" />
|
<SectionHeader title="Player stats" />
|
||||||
<Descriptions size="small" bordered column={{ xs: 1, sm: 2, lg: 3 }}>
|
<Descriptions size="small" bordered column={{ xs: 1, sm: 2, lg: 3 }}>
|
||||||
|
|||||||
Reference in new issue
Block a user