mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 00:42: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)) => {
|
||||
|
||||
Reference in new issue
Block a user