mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-26 16:37:13 +09:00
4 files changed
+91
-67
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";
|
||||||
|
|
||||||
@@ -21,6 +21,9 @@ import { formatLastSeen, sortLastSeen, useUser } from "../model/user";
|
|||||||
const strcmp = new Intl.Collator(undefined, { numerice: "true", sensitivity: "base" }).compare;
|
const strcmp = new Intl.Collator(undefined, { numerice: "true", sensitivity: "base" }).compare;
|
||||||
|
|
||||||
|
|
||||||
|
// The user page has a lot of optional elements, that does not make it
|
||||||
|
// praticularly complicated.
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
export default function UserViewPage() {
|
export default function UserViewPage() {
|
||||||
let params = useParams();
|
let params = useParams();
|
||||||
let userName = params.name;
|
let userName = params.name;
|
||||||
@@ -30,13 +33,13 @@ export default function UserViewPage() {
|
|||||||
let account = useAccount();
|
let account = useAccount();
|
||||||
let control = useContext(ControlContext);
|
let control = useContext(ControlContext);
|
||||||
let [instanceList] = useInstanceList();
|
let [instanceList] = useInstanceList();
|
||||||
let [user, updateUser] = useUser(userName);
|
let [user] = useUser(userName);
|
||||||
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 +49,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}>
|
||||||
@@ -151,7 +164,7 @@ export default function UserViewPage() {
|
|||||||
<Form.Item
|
<Form.Item
|
||||||
label="Roles"
|
label="Roles"
|
||||||
>
|
>
|
||||||
<Row gutter={8}>
|
<Row gutter={[8, 8]}>
|
||||||
<Col flex="auto">
|
<Col flex="auto">
|
||||||
{account.hasPermission("core.user.update_roles")
|
{account.hasPermission("core.user.update_roles")
|
||||||
? roleSelector
|
? roleSelector
|
||||||
@@ -185,105 +198,100 @@ export default function UserViewPage() {
|
|||||||
</Col>}
|
</Col>}
|
||||||
</Row>
|
</Row>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item label="In-game Admin">
|
{account.hasPermission("core.user.set_admin") && <Form.Item label="In-game Admin">
|
||||||
<Switch
|
<Switch
|
||||||
checked={user["is_admin"]}
|
checked={user["is_admin"]}
|
||||||
disabled={!account.hasPermission("core.user.set_admin")}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
libLink.messages.setUserAdmin.send(control, {
|
libLink.messages.setUserAdmin.send(control, {
|
||||||
name: userName,
|
name: userName,
|
||||||
admin: !user["is_admin"],
|
admin: !user["is_admin"],
|
||||||
create: false,
|
create: false,
|
||||||
}).then(() => {
|
|
||||||
updateUser();
|
|
||||||
}).catch(notifyErrorHandler("Error toggling user admin status"));
|
}).catch(notifyErrorHandler("Error toggling user admin status"));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>}
|
||||||
<Form.Item label="Whitelisted">
|
{account.hasPermission("core.user.set_whitelisted") && <Form.Item label="Whitelisted">
|
||||||
<Switch
|
<Switch
|
||||||
checked={user["is_whitelisted"]}
|
checked={user["is_whitelisted"]}
|
||||||
disabled={!account.hasPermission("core.user.set_whitelisted")}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
libLink.messages.setUserWhitelisted.send(control, {
|
libLink.messages.setUserWhitelisted.send(control, {
|
||||||
name: userName,
|
name: userName,
|
||||||
whitelisted: !user["is_whitelisted"],
|
whitelisted: !user["is_whitelisted"],
|
||||||
create: false,
|
create: false,
|
||||||
}).then(() => {
|
|
||||||
updateUser();
|
|
||||||
}).catch(notifyErrorHandler("Error toggling user whitelisted status"));
|
}).catch(notifyErrorHandler("Error toggling user whitelisted status"));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</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 }}>
|
||||||
<Descriptions.Item label="Total play time">
|
<Descriptions.Item label="Total play time">
|
||||||
{user["player_stats"]["online_time_ms"] && formatDuration(user["player_stats"]["online_time_ms"])}
|
{formatDuration(user["player_stats"]["online_time_ms"] || 0)}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="Total join count">
|
<Descriptions.Item label="Total join count">
|
||||||
{user["player_stats"]["join_count"]}
|
{user["player_stats"]["join_count"] || 0}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
<Descriptions.Item label="Last seen">
|
<Descriptions.Item label="Last seen">
|
||||||
{formatLastSeen(user)}
|
{formatLastSeen(user) || " "}
|
||||||
</Descriptions.Item>
|
</Descriptions.Item>
|
||||||
</Descriptions>
|
</Descriptions>
|
||||||
<SectionHeader title="Instance stats" />
|
<SectionHeader title="Instance stats" />
|
||||||
|
|||||||
@@ -480,6 +480,10 @@ describe("Integration of Clusterio", function() {
|
|||||||
return new Map(result.list.map(user => [user.name, user]));
|
return new Map(result.list.map(user => [user.name, user]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getUser(name) {
|
||||||
|
return await libLink.messages.getUser.send(getControl(), { name });
|
||||||
|
}
|
||||||
|
|
||||||
let lists = ["admin", "whitelisted", "banned"];
|
let lists = ["admin", "whitelisted", "banned"];
|
||||||
it("should add and remove the given user to the list", async function() {
|
it("should add and remove the given user to the list", async function() {
|
||||||
slowTest(this);
|
slowTest(this);
|
||||||
@@ -522,6 +526,15 @@ describe("Integration of Clusterio", function() {
|
|||||||
}
|
}
|
||||||
assert.equal(getControl().userUpdates.length, 3);
|
assert.equal(getControl().userUpdates.length, 3);
|
||||||
});
|
});
|
||||||
|
it("should send ban reason", async function() {
|
||||||
|
slowTest(this);
|
||||||
|
getControl().userUpdates = [];
|
||||||
|
await execCtl("user set-banned --create test_ban_reason --reason a-reason");
|
||||||
|
assert.equal(getControl().userUpdates.length, 1);
|
||||||
|
assert.equal(getControl().userUpdates[0].ban_reason, "a-reason");
|
||||||
|
let user = await getUser("test_ban_reason");
|
||||||
|
assert.equal(user["ban_reason"], "a-reason");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("instance extract-players", function() {
|
describe("instance extract-players", function() {
|
||||||
|
|||||||
Reference in new issue
Block a user