Token deletion asks for confirmation like runner deletion
Browse files at this commit3535e27f8c66e7c4f9e89ebc28fff9bea52df897Parent: 4bff024- feat
- token deletion asks for confirmation like runner deletion
2 changed files +22 -10
- crates/forge-web/src/pages/admin_runners.rs +4 -4
- crates/forge-web/src/pages/settings_tokens.rs +18 -6
crates/forge-web/src/pages/admin_runners.rsmodified+4 -4
| @@ -353,7 +353,7 @@ async fn runners_view( | |||
| 353 | <button type="submit">(g::t(lang, K::Enable))</button> | 353 | <button type="submit">(g::t(lang, K::Enable))</button> |
| 354 | </form> | 354 | </form> |
| 355 | } else { | 355 | } else { |
| 356 | - confirm_post(lang: lang, csrf: csrf.as_str(), action: row.toggle_action.as_str(), label: g::t(lang, K::Disable), message: disable_message(lang, row.name.as_str()), confirm: s(lang, "Yes, disable", "Evet, devre dışı bırak"), danger: false, fields: vec![("disabled", "1")]) | 356 | + confirm_post(lang: lang, csrf: csrf.as_str(), action: row.toggle_action.as_str(), label: g::t(lang, K::Disable), message: disable_message(lang, row.name.as_str()), confirm: s(lang, "Yes, disable", "Evet, devre dışı bırak"), danger: false, fields: vec![("disabled", "1".into())]) |
| 357 | } | 357 | } |
| 358 | restart_control(lang: lang, csrf: csrf.as_str(), action: row.restart_action.as_str(), back: "list", can_restart: row.can_restart, pending: row.restart_pending) | 358 | restart_control(lang: lang, csrf: csrf.as_str(), action: row.restart_action.as_str(), back: "list", can_restart: row.can_restart, pending: row.restart_pending) |
| 359 | confirm_post(lang: lang, csrf: csrf.as_str(), action: row.delete_action.as_str(), label: i18n::t(lang, Key::Delete), message: delete_message(lang, row.name.as_str()), confirm: s(lang, "Yes, delete", "Evet, sil"), danger: true, fields: vec![]) | 359 | confirm_post(lang: lang, csrf: csrf.as_str(), action: row.delete_action.as_str(), label: i18n::t(lang, Key::Delete), message: delete_message(lang, row.name.as_str()), confirm: s(lang, "Yes, delete", "Evet, sil"), danger: true, fields: vec![]) |
| @@ -382,7 +382,7 @@ async fn runners_view( | |||
| 382 | /// A destructive button that opens the shared `confirm-inline` popover; the POST only fires from the | 382 | /// A destructive button that opens the shared `confirm-inline` popover; the POST only fires from the |
| 383 | /// confirm button inside it, and Cancel closes the popover. | 383 | /// confirm button inside it, and Cancel closes the popover. |
| 384 | #[component] | 384 | #[component] |
| 385 | -async fn confirm_post( | 385 | +pub(crate) async fn confirm_post( |
| 386 | lang: Lang, | 386 | lang: Lang, |
| 387 | csrf: &str, | 387 | csrf: &str, |
| 388 | action: &str, | 388 | action: &str, |
| @@ -390,7 +390,7 @@ async fn confirm_post( | |||
| 390 | message: String, | 390 | message: String, |
| 391 | confirm: &'static str, | 391 | confirm: &'static str, |
| 392 | danger: bool, | 392 | danger: bool, |
| 393 | - fields: Vec<(&'static str, &'static str)>, | 393 | + fields: Vec<(&'static str, String)>, |
| 394 | ) -> Result<impl View> { | 394 | ) -> Result<impl View> { |
| 395 | Ok(view! { | 395 | Ok(view! { |
| 396 | <details class="confirm-inline"> | 396 | <details class="confirm-inline"> |
| @@ -400,7 +400,7 @@ async fn confirm_post( | |||
| 400 | <form method="post" action=(action)> | 400 | <form method="post" action=(action)> |
| 401 | <input type="hidden" name="csrf" value=(csrf)> | 401 | <input type="hidden" name="csrf" value=(csrf)> |
| 402 | for (name, value) in fields.iter() { | 402 | for (name, value) in fields.iter() { |
| 403 | - <input type="hidden" name=(*name) value=(*value)> | 403 | + <input type="hidden" name=(*name) value=(value.as_str())> |
| 404 | } | 404 | } |
| 405 | <button type="submit" class=(if danger { "danger" } else { "primary" })>(confirm)</button> | 405 | <button type="submit" class=(if danger { "danger" } else { "primary" })>(confirm)</button> |
| 406 | <button type="button" data-close-details="">(s(lang, "Cancel", "Vazgeç"))</button> | 406 | <button type="button" data-close-details="">(s(lang, "Cancel", "Vazgeç"))</button> |
crates/forge-web/src/pages/settings_tokens.rsmodified+18 -6
| @@ -22,6 +22,7 @@ use crate::auth::{require_csrf, require_user}; | |||
| 22 | use crate::i18n::packages::{self as pk, K as PK}; | 22 | use crate::i18n::packages::{self as pk, K as PK}; |
| 23 | use crate::i18n::releases_ci::{self as rc, K as RC}; | 23 | use crate::i18n::releases_ci::{self as rc, K as RC}; |
| 24 | use crate::i18n::{self, Key, Lang, t, token_meta, token_name_length}; | 24 | use crate::i18n::{self, Key, Lang, t, token_meta, token_name_length}; |
| 25 | +use crate::pages::admin_runners::confirm_post; | ||
| 25 | use crate::state::AppState; | 26 | use crate::state::AppState; |
| 26 | use crate::views::{alert, shell}; | 27 | use crate::views::{alert, shell}; |
| 27 | 28 | ||
| @@ -50,6 +51,21 @@ struct DeleteTokenForm { | |||
| 50 | id: String, | 51 | id: String, |
| 51 | } | 52 | } |
| 52 | 53 | ||
| 54 | +/// The question the delete popover asks before a token is revoked. | ||
| 55 | +fn delete_message(lang: Lang, name: &str) -> String { | ||
| 56 | + match lang { | ||
| 57 | + Lang::Tr => format!("{name} silinsin mi? Bu token ile çalışan her şey hemen durur."), | ||
| 58 | + _ => format!("Delete token {name}? Anything using it stops working at once."), | ||
| 59 | + } | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +fn delete_confirm(lang: Lang) -> &'static str { | ||
| 63 | + match lang { | ||
| 64 | + Lang::Tr => "Evet, sil", | ||
| 65 | + _ => "Yes, delete", | ||
| 66 | + } | ||
| 67 | +} | ||
| 68 | + | ||
| 53 | /// Maps the form's expiry choice to a lifetime. `None` means the token never expires. | 69 | /// Maps the form's expiry choice to a lifetime. `None` means the token never expires. |
| 54 | /// An unrecognised value falls back to the 90-day default. | 70 | /// An unrecognised value falls back to the 90-day default. |
| 55 | fn expiry_days(choice: &str) -> Option<u64> { | 71 | fn expiry_days(choice: &str) -> Option<u64> { |
| @@ -78,7 +94,7 @@ async fn tokens_view( | |||
| 78 | <h2>(t(lang, Key::YourNewToken))</h2> | 94 | <h2>(t(lang, Key::YourNewToken))</h2> |
| 79 | <p>(t(lang, Key::CopyNow))</p> | 95 | <p>(t(lang, Key::CopyNow))</p> |
| 80 | <div class="copy-box"> | 96 | <div class="copy-box"> |
| 81 | - <code id="new-token">(token)</code> | 97 | + <pre class="code"><code id="new-token">(token)</code></pre> |
| 82 | <button type="button" data-copy="new-token" data-copied=(rc::t(lang, RC::CopyDone)) data-failed=(rc::t(lang, RC::CopyFailed))>(pk::t(lang, PK::CopyCommand))</button> | 98 | <button type="button" data-copy="new-token" data-copied=(rc::t(lang, RC::CopyDone)) data-failed=(rc::t(lang, RC::CopyFailed))>(pk::t(lang, PK::CopyCommand))</button> |
| 83 | </div> | 99 | </div> |
| 84 | <p class="muted small">(t(lang, Key::UseAsPassword))</p> | 100 | <p class="muted small">(t(lang, Key::UseAsPassword))</p> |
| @@ -95,11 +111,7 @@ async fn tokens_view( | |||
| 95 | <strong>(token.name.clone())</strong> | 111 | <strong>(token.name.clone())</strong> |
| 96 | <span class="muted small">(token_meta(lang, token.created_at.as_str(), token.last_used_at.as_deref(), token.expires_at.as_deref()))</span> | 112 | <span class="muted small">(token_meta(lang, token.created_at.as_str(), token.last_used_at.as_deref(), token.expires_at.as_deref()))</span> |
| 97 | </div> | 113 | </div> |
| 98 | - <form method="post" action="/settings/tokens/delete"> | 114 | + confirm_post(lang: lang, csrf: csrf, action: "/settings/tokens/delete", label: t(lang, Key::Delete), message: delete_message(lang, token.name.as_str()), confirm: delete_confirm(lang), danger: true, fields: vec![("id", token.id.clone())]) |
| 99 | - <input type="hidden" name="csrf" value=(csrf)> | ||
| 100 | - <input type="hidden" name="id" value=(token.id.clone())> | ||
| 101 | - <button type="submit" class="danger">(t(lang, Key::Delete))</button> | ||
| 102 | - </form> | ||
| 103 | </li> | 115 | </li> |
| 104 | } | 116 | } |
| 105 | </ul> | 117 | </ul> |