Skip to main content

max / makenotwork

2.0 KB · 63 lines History Blame Raw
1 //! The Askama entry point for the described "revoke a license key" button.
2 //!
3 //! Shape 8 (`b279b9eb`), through the glue-module ruling `27d5e5b8`.
4 //!
5 //! Destructive and irreversible in a way a deleted row is not: every activation
6 //! standing against the key stops working, which is the reason the prompt says
7 //! more than the label does. Both marks, as the ruling asks.
8 //!
9 //! `POST /api/keys/{id}/revoke` is a plain API route the description layer does
10 //! not serve. It answers the whole list rebuilt, so the control says where that
11 //! lands. See [`Action::replaces`].
12 //!
13 //! Ids arrive as `impl Display` rather than `&str`: the caller is Askama and
14 //! the server's ids are typed newtypes over `Uuid`, so asking for a string
15 //! would push a `to_string()` into every call site to say what `format!`
16 //! already says here.
17
18 use std::fmt;
19
20 use makeover_layout::Tone;
21 use quasi_router::screen::Act;
22 use quasi_router::{Action, Node};
23
24 /// The revoke button for one key's row.
25 #[must_use]
26 pub fn html(key_id: impl fmt::Display) -> String {
27 use quasi_axum::Serves as _;
28
29 let act = Act::new(
30 "Revoke",
31 Action::post(format!("/api/keys/{key_id}/revoke")).replacing("license-keys-list"),
32 )
33 .tone(Tone::Danger)
34 .confirm("Revoke this license key? All activations will be deactivated.");
35
36 quasi_webview::Webview::new().fragment(&Node::Act(act))
37 }
38
39 #[cfg(test)]
40 mod tests {
41 #[test]
42 fn a_revoke_names_its_route_its_region_and_its_prompt() {
43 let html = super::html("k1");
44
45 assert!(html.contains(r#"hx-post="/api/keys/k1/revoke""#), "{html}");
46 assert!(
47 html.contains(r##"hx-target="#license-keys-list""##),
48 "{html}"
49 );
50 assert!(
51 html.contains(
52 r#"hx-confirm="Revoke this license key? All activations will be deactivated.""#
53 ),
54 "{html}"
55 );
56 }
57
58 #[test]
59 fn a_revoke_says_it_is_dangerous() {
60 assert!(super::html("k1").contains(r#"data-tone="danger""#));
61 }
62 }
63