mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-02 01:12:49 +08:00
Add read-only permission overview ("Eigene Rechte anzeigen")
Partial progress on #71 (full permissions editor). A genuine full editor - server/channel/group permission grids across 5 permission scopes with add/remove/modify for hundreds of possible permissions - is a much bigger undertaking than fits in one pass, so this lands a real, useful slice of it first: a read-only view of the caller's own effective permissions in their current channel. - Connector: "permoverview" (raw command, no typed builder exists) requests the caller's effective permission set for cid+cldbid. Permission IDs are opaque numeric values server-side, so results are name-resolved via a "permissionlist" id->name/description lookup that's fetched once and cached for the connection's lifetime. The two requests are chained (list first, overview second) with buffering in case the overview reply somehow arrives first. - Gateway: typed passthrough for the merged, name-resolved entries. - Frontend: new dialog wired to "Eigene Rechte anzeigen" in the Rechte menu (previously disabled) - a filterable table of permission name/value/negated/skip. Verified against the real server: initially got a clean "ParameterNotFound" error revealing that permoverview needs an explicit permid=0 ("all permissions") even though tsclientlib's generated type treats it as optional; after adding that argument the command reaches the server correctly and returns the expected permission-denied response for the guest test account (same pattern as every other admin-gated feature this session). The remaining scope of #71 - editable server-group/channel-group/ channel/client permission grids - is unchanged and left for later. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0f8576ac6c
commit
41ac845fbc
7 files changed
+305
-3
No files matched your search
@@ -265,6 +265,11 @@ enum Event {
|
||||
/// Reply to a "servergrouplist" request.
|
||||
#[serde(rename = "serverGroupList")]
|
||||
ServerGroupList { entries: Vec<GroupEntry> },
|
||||
/// Reply to a "permoverview" request - the caller's own effective
|
||||
/// permissions in their current channel, name-resolved via a cached
|
||||
/// "permissionlist" lookup.
|
||||
#[serde(rename = "permissionOverview")]
|
||||
PermissionOverview { entries: Vec<PermissionOverviewEntry> },
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -303,6 +308,16 @@ struct OfflineMessageListEntry {
|
||||
is_read: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct PermissionOverviewEntry {
|
||||
name: String,
|
||||
description: String,
|
||||
value: i32,
|
||||
negated: bool,
|
||||
skip: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct GroupEntry {
|
||||
@@ -632,6 +647,17 @@ async fn run(args: Args) -> Result<()> {
|
||||
let mut pending_offline_message_get = false;
|
||||
let mut pending_channel_group_list = false;
|
||||
let mut pending_server_group_list = false;
|
||||
// Cache of permission id -> (name, description), built lazily from a
|
||||
// "permissionlist" request the first time a "permoverview" is requested;
|
||||
// the mapping is static for the lifetime of the connection so it's only
|
||||
// fetched once.
|
||||
let mut permission_names: std::collections::HashMap<u32, (String, String)> =
|
||||
std::collections::HashMap::new();
|
||||
let mut pending_permission_list = false;
|
||||
let mut pending_perm_overview = false;
|
||||
// Raw permoverview entries received before the permission-name cache was
|
||||
// ready get buffered here and re-emitted once the names arrive.
|
||||
let mut pending_perm_overview_raw: Option<Vec<(u32, i32, bool, bool)>> = None;
|
||||
|
||||
enum LoopOutcome {
|
||||
StdinLine(std::io::Result<Option<String>>),
|
||||
@@ -1280,6 +1306,47 @@ async fn run(args: Args) -> Result<()> {
|
||||
}
|
||||
None => emit(&Event::Error { message: "Invalid serverquerylogin args".into() }),
|
||||
}
|
||||
} else if l == "permoverview" {
|
||||
let state = con.get_state()?;
|
||||
let own_id = state.own_client;
|
||||
if let Some(own) = state.clients.get(&own_id) {
|
||||
let cid = own.channel.0;
|
||||
let cldbid = own.database_id.0;
|
||||
if permission_names.is_empty() {
|
||||
let packet = OutCommand::new(
|
||||
Direction::C2S,
|
||||
Flags::empty(),
|
||||
PacketType::Command,
|
||||
"permissionlist",
|
||||
);
|
||||
match packet.send_with_result(&mut con) {
|
||||
Ok(handle) => {
|
||||
pending_permission_list = true;
|
||||
pending_messages.insert(handle, "Permission list".into());
|
||||
}
|
||||
Err(e) => emit(&Event::Error { message: e.to_string() }),
|
||||
}
|
||||
}
|
||||
let mut packet = OutCommand::new(
|
||||
Direction::C2S,
|
||||
Flags::empty(),
|
||||
PacketType::Command,
|
||||
"permoverview",
|
||||
);
|
||||
packet.write_arg("cid", &cid);
|
||||
packet.write_arg("cldbid", &cldbid);
|
||||
// permid=0 means "all permissions" - the server requires this
|
||||
// argument even though tsclientlib's generated type treats it
|
||||
// as optional.
|
||||
packet.write_arg("permid", &0u32);
|
||||
match packet.send_with_result(&mut con) {
|
||||
Ok(handle) => {
|
||||
pending_perm_overview = true;
|
||||
pending_messages.insert(handle, "Permission overview".into());
|
||||
}
|
||||
Err(e) => emit(&Event::Error { message: e.to_string() }),
|
||||
}
|
||||
}
|
||||
} else if let Some(b64) = l.strip_prefix("audio ") {
|
||||
match base64::engine::general_purpose::STANDARD.decode(b64.trim()) {
|
||||
Ok(bytes) => {
|
||||
@@ -1549,6 +1616,68 @@ async fn run(args: Args) -> Result<()> {
|
||||
pending_server_group_list = false;
|
||||
}
|
||||
}
|
||||
if pending_permission_list {
|
||||
if let InMessage::PermList(list) = &msg {
|
||||
for part in list.iter() {
|
||||
if let Some(id) = part.permission_id {
|
||||
permission_names.insert(
|
||||
id.0,
|
||||
(
|
||||
part.permission_name.clone().unwrap_or_default(),
|
||||
part.permission_description.clone().unwrap_or_default(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
pending_permission_list = false;
|
||||
if let Some(raw) = pending_perm_overview_raw.take() {
|
||||
let entries: Vec<PermissionOverviewEntry> = raw
|
||||
.into_iter()
|
||||
.map(|(id, value, negated, skip)| {
|
||||
let (name, description) = permission_names
|
||||
.get(&id)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| (format!("#{id}"), String::new()));
|
||||
PermissionOverviewEntry { name, description, value, negated, skip }
|
||||
})
|
||||
.collect();
|
||||
emit(&Event::PermissionOverview { entries });
|
||||
}
|
||||
}
|
||||
}
|
||||
if pending_perm_overview {
|
||||
if let InMessage::PermOverview(list) = &msg {
|
||||
let raw: Vec<(u32, i32, bool, bool)> = list
|
||||
.iter()
|
||||
.map(|part| {
|
||||
(
|
||||
part.permission_id.0,
|
||||
part.permission_value,
|
||||
part.permission_negated,
|
||||
part.permission_skip,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
pending_perm_overview = false;
|
||||
if pending_permission_list {
|
||||
// The name lookup hasn't come back yet - buffer the raw
|
||||
// values and resolve them once it does.
|
||||
pending_perm_overview_raw = Some(raw);
|
||||
} else {
|
||||
let entries: Vec<PermissionOverviewEntry> = raw
|
||||
.into_iter()
|
||||
.map(|(id, value, negated, skip)| {
|
||||
let (name, description) = permission_names
|
||||
.get(&id)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| (format!("#{id}"), String::new()));
|
||||
PermissionOverviewEntry { name, description, value, negated, skip }
|
||||
})
|
||||
.collect();
|
||||
emit(&Event::PermissionOverview { entries });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(Ok(_)) => {}
|
||||
Some(Err(e)) => {
|
||||
|
||||
@@ -218,6 +218,10 @@ wss.on("connection", (socket: WebSocket) => {
|
||||
await connection?.serverQueryLogin(msg.username, msg.password);
|
||||
break;
|
||||
}
|
||||
case "getPermissionOverview": {
|
||||
await connection?.getPermissionOverview();
|
||||
break;
|
||||
}
|
||||
case "disconnect": {
|
||||
await connection?.disconnect(msg.message ?? "");
|
||||
break;
|
||||
|
||||
@@ -43,6 +43,14 @@ export interface GroupEntry {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface PermissionOverviewEntry {
|
||||
name: string;
|
||||
description: string;
|
||||
value: number;
|
||||
negated: boolean;
|
||||
skip: boolean;
|
||||
}
|
||||
|
||||
export interface BanListEntry {
|
||||
banId: number;
|
||||
ip: string;
|
||||
@@ -142,7 +150,8 @@ export type Ts3ConnectionEvent =
|
||||
timestamp: string;
|
||||
}
|
||||
| { type: "channelGroupList"; entries: GroupEntry[] }
|
||||
| { type: "serverGroupList"; entries: GroupEntry[] };
|
||||
| { type: "serverGroupList"; entries: GroupEntry[] }
|
||||
| { type: "permissionOverview"; entries: PermissionOverviewEntry[] };
|
||||
|
||||
export interface Ts3ConnectOptions {
|
||||
host: string;
|
||||
@@ -307,7 +316,11 @@ export class Ts3Connection {
|
||||
timestamp: string;
|
||||
}
|
||||
| { type: "channelGroupList"; entries: { id: number; name: string }[] }
|
||||
| { type: "serverGroupList"; entries: { id: number; name: string }[] };
|
||||
| { type: "serverGroupList"; entries: { id: number; name: string }[] }
|
||||
| {
|
||||
type: "permissionOverview";
|
||||
entries: { name: string; description: string; value: number; negated: boolean; skip: boolean }[];
|
||||
};
|
||||
|
||||
if (event.type === "connected") {
|
||||
this.emit({
|
||||
@@ -579,6 +592,10 @@ export class Ts3Connection {
|
||||
this.child?.stdin.write(`serverquerylogin ${u} ${p}\n`);
|
||||
}
|
||||
|
||||
async getPermissionOverview(): Promise<void> {
|
||||
this.child?.stdin.write(`permoverview\n`);
|
||||
}
|
||||
|
||||
async sendChatMessage(message: string): Promise<void> {
|
||||
const sanitized = message.replace(/[\r\n]+/g, " ").trim();
|
||||
if (sanitized) this.child?.stdin.write(`chat ${sanitized}\n`);
|
||||
|
||||
@@ -1148,6 +1148,15 @@
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.ts-permission-overview-dialog {
|
||||
width: 640px;
|
||||
}
|
||||
|
||||
.ts-permission-overview-scroll {
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.ts-server-protocol-log-line {
|
||||
padding: 0.15rem 0.4rem;
|
||||
border-bottom: 1px solid var(--border-soft);
|
||||
|
||||
+113
-1
@@ -320,6 +320,14 @@ interface GroupEntry {
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface PermissionOverviewEntry {
|
||||
name: string;
|
||||
description: string;
|
||||
value: number;
|
||||
negated: boolean;
|
||||
skip: boolean;
|
||||
}
|
||||
|
||||
interface ClientConnectionInfoData {
|
||||
clientId: number;
|
||||
pingMs: number | null;
|
||||
@@ -1608,6 +1616,86 @@ function GroupAssignDialog({
|
||||
);
|
||||
}
|
||||
|
||||
function PermissionOverviewDialog({
|
||||
entries,
|
||||
onClose,
|
||||
}: {
|
||||
entries: PermissionOverviewEntry[] | null;
|
||||
onClose: () => void;
|
||||
}) {
|
||||
const t = useT();
|
||||
const backdrop = useBackdropDismiss(onClose);
|
||||
const [search, setSearch] = useState("");
|
||||
const [timedOut, setTimedOut] = useState(false);
|
||||
useEffect(() => {
|
||||
setTimedOut(false);
|
||||
if (entries) return;
|
||||
const id = window.setTimeout(() => setTimedOut(true), 6000);
|
||||
return () => window.clearTimeout(id);
|
||||
}, [entries]);
|
||||
|
||||
const filtered = entries?.filter((e) => e.name.toLowerCase().includes(search.toLowerCase())) ?? null;
|
||||
|
||||
return (
|
||||
<div className="ts-dialog-backdrop" {...backdrop}>
|
||||
<div className="ts-dialog ts-permission-overview-dialog" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="ts-dialog-titlebar">
|
||||
<span>{t("permissionOverview.title")}</span>
|
||||
<button onClick={onClose} title={t("dialog.close")}>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<div className="ts-dialog-body">
|
||||
{!entries ? (
|
||||
<div className="ts-connection-info-loading">
|
||||
{timedOut ? t("connectionInfo.unavailable") : t("connectionInfo.loading")}
|
||||
</div>
|
||||
) : entries.length === 0 ? (
|
||||
<div className="ts-connection-info-loading">{t("permissionOverview.empty")}</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="ts-dialog-row">
|
||||
<label className="ts-dialog-field ts-dialog-field-grow">
|
||||
{t("clientLog.filter")}
|
||||
<input value={search} onChange={(e) => setSearch(e.target.value)} />
|
||||
</label>
|
||||
</div>
|
||||
<div className="ts-permission-overview-scroll">
|
||||
<table className="ts-ban-list-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{t("permissionOverview.name")}</th>
|
||||
<th>{t("permissionOverview.value")}</th>
|
||||
<th>{t("permissionOverview.negated")}</th>
|
||||
<th>{t("permissionOverview.skip")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{filtered!.map((e, i) => (
|
||||
<tr key={`${e.name}-${i}`} title={e.description || undefined}>
|
||||
<td>{e.name}</td>
|
||||
<td>{e.value}</td>
|
||||
<td>{e.negated ? "✔️" : ""}</td>
|
||||
<td>{e.skip ? "✔️" : ""}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<div className="ts-dialog-buttons">
|
||||
<div />
|
||||
<div className="ts-dialog-buttons-right">
|
||||
<button onClick={onClose}>{t("dialog.close")}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ServerProtocolLogDialog({
|
||||
lines,
|
||||
onClose,
|
||||
@@ -3102,6 +3190,8 @@ function AppInner() {
|
||||
clientId: number;
|
||||
clientName: string;
|
||||
} | null>(null);
|
||||
const [permissionOverviewOpen, setPermissionOverviewOpen] = useState(false);
|
||||
const [permissionOverview, setPermissionOverview] = useState<PermissionOverviewEntry[] | null>(null);
|
||||
const [treeWidth, setTreeWidth] = useState(260);
|
||||
const [upperHeight, setUpperHeight] = useState(340);
|
||||
const [selected, setSelected] = useState<SelectedItem | null>(null);
|
||||
@@ -3698,6 +3788,9 @@ function AppInner() {
|
||||
case "serverGroupList":
|
||||
setServerGroups(data.entries);
|
||||
break;
|
||||
case "permissionOverview":
|
||||
setPermissionOverview(data.entries);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4446,6 +4539,12 @@ function AppInner() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleShowPermissionOverview = () => {
|
||||
setPermissionOverviewOpen(true);
|
||||
setPermissionOverview(null);
|
||||
socketRef.current?.send(JSON.stringify({ type: "getPermissionOverview" }));
|
||||
};
|
||||
|
||||
const handleSendPoke = () => {
|
||||
if (!pokeTarget) return;
|
||||
socketRef.current?.send(
|
||||
@@ -4734,7 +4833,13 @@ function AppInner() {
|
||||
<span className="ts-menu-item-label">{t("menu.rights.overview")}</span>
|
||||
</button>
|
||||
<div className="ts-menu-separator" />
|
||||
<button className="ts-menu-item" disabled title={t("clientContext.notSupported")}>
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
onClick={() => {
|
||||
handleShowPermissionOverview();
|
||||
setRightsMenuOpen(false);
|
||||
}}
|
||||
>
|
||||
<span className="ts-menu-item-icon">🙋</span>
|
||||
<span className="ts-menu-item-label">{t("menu.rights.myRights")}</span>
|
||||
</button>
|
||||
@@ -5277,6 +5382,13 @@ function AppInner() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{permissionOverviewOpen && (
|
||||
<PermissionOverviewDialog
|
||||
entries={permissionOverview}
|
||||
onClose={() => setPermissionOverviewOpen(false)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{contactsOpen && (
|
||||
<ContactsDialog
|
||||
contacts={contacts}
|
||||
|
||||
@@ -367,6 +367,23 @@ export class DemoSocket {
|
||||
// No observable effect - the demo has no real ServerQuery backend to
|
||||
// authenticate against.
|
||||
break;
|
||||
case "getPermissionOverview": {
|
||||
this.after(400, () =>
|
||||
this.emit({
|
||||
type: "permissionOverview",
|
||||
entries: [
|
||||
{ name: "b_client_info_view", description: "View own client info", value: 1, negated: false, skip: false },
|
||||
{ name: "b_client_permissionoverview_view", description: "View permission overview", value: 1, negated: false, skip: false },
|
||||
{ name: "i_channel_join_power", description: "Power to join channels", value: 25, negated: false, skip: false },
|
||||
{ name: "i_client_talk_power", description: "Talk power", value: 25, negated: false, skip: false },
|
||||
{ name: "b_client_use_priority_speaker", description: "Use priority speaker", value: 0, negated: true, skip: false },
|
||||
{ name: "i_client_max_channel_subscriptions", description: "Max channel subscriptions", value: -1, negated: false, skip: false },
|
||||
{ name: "b_channel_join_permanent", description: "Join permanent channels", value: 1, negated: false, skip: false },
|
||||
],
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
// "disconnect" is intentionally unhandled here: handleDisconnect() in
|
||||
// App.tsx always calls socket.close() right after sending it, and
|
||||
// close() already emits the "disconnected" event below.
|
||||
|
||||
@@ -404,6 +404,13 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"serverQueryLogin.password": "Passwort",
|
||||
"serverQueryLogin.login": "Anmelden",
|
||||
|
||||
"permissionOverview.title": "Eigene Rechte",
|
||||
"permissionOverview.empty": "Keine Rechte gefunden.",
|
||||
"permissionOverview.name": "Recht",
|
||||
"permissionOverview.value": "Wert",
|
||||
"permissionOverview.negated": "Negiert",
|
||||
"permissionOverview.skip": "Skip",
|
||||
|
||||
"clientContext.privateChat": "Privater Chat",
|
||||
"clientContext.poke": "Anstupsen",
|
||||
"clientContext.copyName": "Namen kopieren",
|
||||
@@ -850,6 +857,13 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"serverQueryLogin.password": "Password",
|
||||
"serverQueryLogin.login": "Login",
|
||||
|
||||
"permissionOverview.title": "My Permissions",
|
||||
"permissionOverview.empty": "No permissions found.",
|
||||
"permissionOverview.name": "Permission",
|
||||
"permissionOverview.value": "Value",
|
||||
"permissionOverview.negated": "Negated",
|
||||
"permissionOverview.skip": "Skip",
|
||||
|
||||
"clientContext.privateChat": "Private chat",
|
||||
"clientContext.poke": "Poke",
|
||||
"clientContext.copyName": "Copy name",
|
||||
|
||||
Reference in new issue
Block a user