fix(host,gui): the Connect page's keys: never replaced, no admin, revoked by id, a quoted command, a leftover file said
Make the key asks the server first and never replaces: a live key whose copy is missing here may be in use, so it is said in words and left alone. A page-made key carries read, write and post, not admin (the connect command keeps its scopes). Revoke names the key's id, so a stale row cannot end a newer key of the same name; a revoke that leaves the token file says the key is dead and where the file is. The copyable command is single-quoted for a POSIX shell and PowerShell, and refused when cmd.exe would act on a part. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
e34b18ec73
commit
fd847701e8
8 files changed
+588
-55
No files matched your search
@@ -442,7 +442,9 @@ impl State {
|
||||
if let Some((what, rx)) = &self.job
|
||||
&& let Ok(result) = rx.try_recv()
|
||||
{
|
||||
if what.starts_with("Revoke") && result.is_ok() {
|
||||
// Whatever came of it (a key already gone, a file left behind),
|
||||
// the list is read again.
|
||||
if what.starts_with("Revoke") {
|
||||
self.refresh = true;
|
||||
}
|
||||
self.done = Some((what.clone(), result));
|
||||
@@ -587,7 +589,7 @@ impl State {
|
||||
);
|
||||
return;
|
||||
}
|
||||
let mut revoke: Option<String> = None;
|
||||
let mut revoke: Option<(String, String)> = None;
|
||||
for row in &rows {
|
||||
Frame::new()
|
||||
.fill(p.surface)
|
||||
@@ -608,7 +610,7 @@ impl State {
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
}
|
||||
if let (Some(name), Some(owner)) = (revoke, owner.clone()) {
|
||||
if let (Some((name, id)), Some(owner)) = (revoke, owner.clone()) {
|
||||
self.confirm = None;
|
||||
let b = book.to_string();
|
||||
self.start(
|
||||
@@ -616,7 +618,7 @@ impl State {
|
||||
jobs,
|
||||
format!("Revoke {name}"),
|
||||
"Ending an assistant's access",
|
||||
Box::new(move || owner.serve_revoke(&b, &name)),
|
||||
Box::new(move || owner.serve_revoke(&b, &name, &id)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -795,7 +797,7 @@ fn another_row(
|
||||
Box::new(move || {
|
||||
o.make_key(&b).map(|made| {
|
||||
if made {
|
||||
"made, and kept on this computer.".to_string()
|
||||
"made, and kept on this computer. It can read the books, draft entries and post them; it cannot see the access record.".to_string()
|
||||
} else {
|
||||
"it was already made.".to_string()
|
||||
}
|
||||
@@ -851,7 +853,7 @@ fn connection_row(
|
||||
row: &Connection<'_>,
|
||||
status: &Status,
|
||||
confirm: &mut Option<String>,
|
||||
revoke: &mut Option<String>,
|
||||
revoke: &mut Option<(String, String)>,
|
||||
busy: bool,
|
||||
can_revoke: bool,
|
||||
) {
|
||||
@@ -887,12 +889,12 @@ fn connection_row(
|
||||
if !can_revoke {
|
||||
return;
|
||||
}
|
||||
if confirm.as_deref() == Some(t.name.as_str()) {
|
||||
if confirm.as_deref() == Some(t.id.as_str()) {
|
||||
if ui
|
||||
.add_enabled(!busy, egui::Button::new("Yes, revoke"))
|
||||
.clicked()
|
||||
{
|
||||
*revoke = Some(t.name.clone());
|
||||
*revoke = Some((t.name.clone(), t.id.clone()));
|
||||
}
|
||||
if ui.button("Keep it").clicked() {
|
||||
*confirm = None;
|
||||
@@ -902,11 +904,14 @@ fn connection_row(
|
||||
.on_hover_text("Ends this key: the assistant using it is cut off and cannot reach these books again")
|
||||
.clicked()
|
||||
{
|
||||
*confirm = Some(t.name.clone());
|
||||
*confirm = Some(t.id.clone());
|
||||
}
|
||||
});
|
||||
});
|
||||
if confirm.as_deref() == Some(row.name.as_str()) {
|
||||
if row
|
||||
.token
|
||||
.is_some_and(|t| confirm.as_deref() == Some(t.id.as_str()))
|
||||
{
|
||||
ui.label(
|
||||
RichText::new(format!(
|
||||
"Revoke the key “{}”? Anything using it is cut off now; {}'s books are not changed.",
|
||||
|
||||
@@ -190,6 +190,9 @@ pub struct Assistant {
|
||||
/// A token, as listed: who may connect to a company (never its text).
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct TokenRow {
|
||||
/// Its id: what a revoke names, so a row of a key since replaced
|
||||
/// cannot end the new one.
|
||||
pub id: String,
|
||||
/// The company it opens.
|
||||
pub book: String,
|
||||
/// Its name.
|
||||
@@ -262,9 +265,11 @@ pub trait Owner: Send + Sync {
|
||||
fn serve_roster(&self) -> Result<Roster, String> {
|
||||
Ok(Roster::default())
|
||||
}
|
||||
/// End the token `name` of the company `book` (what `wanderbooks token
|
||||
/// revoke` does): `Ok` says what was done, in words. Blocks.
|
||||
fn serve_revoke(&self, _book: &str, _name: &str) -> Result<String, String> {
|
||||
/// End the token `name`, whose id is `id`, of the company `book` (what
|
||||
/// `wanderbooks token revoke` does, for that one key): `Ok` says what
|
||||
/// was done, in words; a key already replaced or revoked is an `Err`
|
||||
/// that says so. Blocks.
|
||||
fn serve_revoke(&self, _book: &str, _name: &str, _id: &str) -> Result<String, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
/// This program run with `words`, as a line to type in a terminal (the
|
||||
@@ -274,8 +279,10 @@ pub trait Owner: Send + Sync {
|
||||
Err("not here".into())
|
||||
}
|
||||
/// The key an assistant needs to reach the company `book` exists (made
|
||||
/// now if it did not): `Ok(true)` when it was made now. What `connect`
|
||||
/// does first, for an assistant set up by hand. Blocks.
|
||||
/// now if it did not), able to read, draft and post but not to see the
|
||||
/// access record: `Ok(true)` when it was made now. It never replaces a
|
||||
/// key: one that exists with no copy here is an `Err` that says so.
|
||||
/// Blocks.
|
||||
fn make_key(&self, _book: &str) -> Result<bool, String> {
|
||||
Err("not here".into())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user