diff --git a/crates/forge-core/src/store/audit.rs b/crates/forge-core/src/store/audit.rs index 299181b..7f7fbf7 100644 --- a/crates/forge-core/src/store/audit.rs +++ b/crates/forge-core/src/store/audit.rs @@ -2,7 +2,7 @@ use turso::{Row, Value}; -use super::{Store, col_opt_text, col_text, db_err, fetch_all}; +use super::{Store, col_int, col_opt_text, col_text, db_err, fetch_all, fetch_opt}; use crate::audit::{AuditAction, AuditCursor, AuditEntry, AuditFilter}; use crate::error::{Error, Result}; @@ -28,6 +28,46 @@ fn map_audit(row: &Row) -> Result { }) } +/// The WHERE clause and its parameters for `filter` and an optional cursor, shared by the +/// listings and the count so they select the same entries. +fn audit_where(filter: &AuditFilter, before: Option<&AuditCursor>) -> (String, Vec) { + let mut clauses: Vec<&str> = Vec::new(); + let mut params: Vec = Vec::new(); + if let Some(actor) = &filter.actor_id { + clauses.push("actor_id = ?"); + params.push(Value::Text(actor.clone())); + } + if let Some(action) = filter.action { + clauses.push("action = ?"); + params.push(Value::Text(action.as_str().to_string())); + } + if let Some(kind) = &filter.target_kind { + clauses.push("target_kind = ?"); + params.push(Value::Text(kind.clone())); + } + if let Some(id) = &filter.target_id { + clauses.push("target_id = ?"); + params.push(Value::Text(id.clone())); + } + if let Some(user) = &filter.involving_user { + clauses.push("(actor_id = ? OR (target_kind = 'user' AND target_id = ?))"); + params.push(Value::Text(user.clone())); + params.push(Value::Text(user.clone())); + } + if let Some(cursor) = before { + clauses.push("(at < ? OR (at = ? AND id < ?))"); + params.push(Value::Text(cursor.at.clone())); + params.push(Value::Text(cursor.at.clone())); + params.push(Value::Text(cursor.id.clone())); + } + let where_sql = if clauses.is_empty() { + String::new() + } else { + format!("WHERE {}", clauses.join(" AND ")) + }; + (where_sql, params) +} + impl Store { /// Appends one entry. Nothing else in the store writes to `audit_log`. pub async fn record_audit(&self, entry: &AuditEntry) -> Result<()> { @@ -66,40 +106,7 @@ impl Store { before: Option<&AuditCursor>, limit: u32, ) -> Result> { - let mut clauses: Vec<&str> = Vec::new(); - let mut params: Vec = Vec::new(); - if let Some(actor) = &filter.actor_id { - clauses.push("actor_id = ?"); - params.push(Value::Text(actor.clone())); - } - if let Some(action) = filter.action { - clauses.push("action = ?"); - params.push(Value::Text(action.as_str().to_string())); - } - if let Some(kind) = &filter.target_kind { - clauses.push("target_kind = ?"); - params.push(Value::Text(kind.clone())); - } - if let Some(id) = &filter.target_id { - clauses.push("target_id = ?"); - params.push(Value::Text(id.clone())); - } - if let Some(user) = &filter.involving_user { - clauses.push("(actor_id = ? OR (target_kind = 'user' AND target_id = ?))"); - params.push(Value::Text(user.clone())); - params.push(Value::Text(user.clone())); - } - if let Some(cursor) = before { - clauses.push("(at < ? OR (at = ? AND id < ?))"); - params.push(Value::Text(cursor.at.clone())); - params.push(Value::Text(cursor.at.clone())); - params.push(Value::Text(cursor.id.clone())); - } - let where_sql = if clauses.is_empty() { - String::new() - } else { - format!("WHERE {}", clauses.join(" AND ")) - }; + let (where_sql, mut params) = audit_where(filter, before); let sql = format!( "SELECT {AUDIT_COLS} FROM audit_log {where_sql} ORDER BY at DESC, id DESC LIMIT ?" ); @@ -108,6 +115,34 @@ impl Store { fetch_all(&conn, &sql, params, map_audit).await } + /// Entries matching `filter` in the same order as [`Store::list_audit`], skipping `offset` + /// entries first. For numbered pages. `limit` is clamped to 1..=200. + pub async fn list_audit_page( + &self, + filter: &AuditFilter, + offset: u32, + limit: u32, + ) -> Result> { + let (where_sql, mut params) = audit_where(filter, None); + let sql = format!( + "SELECT {AUDIT_COLS} FROM audit_log {where_sql} ORDER BY at DESC, id DESC \ + LIMIT ? OFFSET ?" + ); + params.push(Value::Integer(i64::from(limit.clamp(1, MAX_AUDIT_PAGE)))); + params.push(Value::Integer(i64::from(offset))); + let conn = self.read_conn().await; + fetch_all(&conn, &sql, params, map_audit).await + } + + /// How many entries match `filter`, for the page count. + pub async fn count_audit(&self, filter: &AuditFilter) -> Result { + let (where_sql, params) = audit_where(filter, None); + let sql = format!("SELECT COUNT(*) FROM audit_log {where_sql}"); + let conn = self.read_conn().await; + let count = fetch_opt(&conn, &sql, params, |row| col_int(row, 0)).await?; + Ok(count.unwrap_or(0).max(0) as u64) + } + /// Retention: deletes entries stamped before `cutoff` (an RFC 3339 UTC stamp). Returns the /// number of entries removed. This is the only delete on the audit log. pub async fn purge_audit_before(&self, cutoff: &str) -> Result { diff --git a/crates/forge-e2e/tests/e2e/orgs_ui_e2e.rs b/crates/forge-e2e/tests/e2e/orgs_ui_e2e.rs index d4fbef5..bf12e6b 100644 --- a/crates/forge-e2e/tests/e2e/orgs_ui_e2e.rs +++ b/crates/forge-e2e/tests/e2e/orgs_ui_e2e.rs @@ -469,14 +469,14 @@ async fn org_settings_delete_and_audit_end_to_end() { .await; assert_eq!(audit.status, 200, "audit page"); assert!( - audit.body.contains("org_settings_updated"), + audit.body.contains("title=\"org_settings_updated\""), "settings change is audited" ); let audit = http .get("/admin/audit?action=org_deleted", Some(&root_session)) .await; assert!( - audit.body.contains("org_deleted"), + audit.body.contains("title=\"org_deleted\""), "org deletion is audited" ); } diff --git a/crates/forge-e2e/tests/e2e/section_nav_e2e.rs b/crates/forge-e2e/tests/e2e/section_nav_e2e.rs index 557b7c6..5bd2668 100644 --- a/crates/forge-e2e/tests/e2e/section_nav_e2e.rs +++ b/crates/forge-e2e/tests/e2e/section_nav_e2e.rs @@ -201,12 +201,11 @@ async fn settings_pages_get_the_settings_tabs() { "/settings/keys", "/settings/export", ]; - // A page folded into another tab marks that tab: sessions under security, GPG keys and + // A page folded into another tab marks that tab: GPG keys and // tokens under keys. let pages = [ ("/settings/profile", "/settings/profile"), ("/settings/keys", "/settings/keys"), - ("/settings/sessions", "/settings/security"), ("/settings/security", "/settings/security"), ("/settings/notifications", "/settings/notifications"), ("/settings/appearance", "/settings/appearance"), diff --git a/crates/forge-e2e/tests/e2e/ui_prefs_e2e.rs b/crates/forge-e2e/tests/e2e/ui_prefs_e2e.rs index c63d435..53b84d2 100644 --- a/crates/forge-e2e/tests/e2e/ui_prefs_e2e.rs +++ b/crates/forge-e2e/tests/e2e/ui_prefs_e2e.rs @@ -267,14 +267,14 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { ("csrf", &csrf), ("theme", "light"), ("language", "en"), - ("base_dark", "spark"), + ("base_dark", "graphite"), ], Some(&session), ) .await; assert_eq!(saved.status, 303, "save: {}", saved.body); let page = env.http.get("/settings/appearance", Some(&session)).await; - let chosen = ["ocean", "plum", "ink", "spark"].map(str::to_owned); + let chosen = ["ocean", "plum", "ink", "graphite"].map(str::to_owned); assert_eq!(checked_colours(&page.body), chosen.clone().map(Some)); assert_eq!(html_colours(&page.body), chosen.map(Some)); @@ -300,7 +300,7 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { assert_ne!(res.status, 303, "bad {field} {bad:?} must not save"); } let page = env.http.get("/settings/appearance", Some(&session)).await; - let chosen = ["ocean", "plum", "ink", "spark"].map(str::to_owned); + let chosen = ["ocean", "plum", "ink", "graphite"].map(str::to_owned); assert_eq!(checked_colours(&page.body), chosen.clone().map(Some)); assert_eq!(html_colours(&page.body), chosen.map(Some)); @@ -314,8 +314,8 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { ("theme", "light"), ("language", "tr"), ("accent_light", "hue-200"), - ("accent_dark", "gold"), - ("base_light", "spark"), + ("accent_dark", "rose"), + ("base_light", "graphite"), ("base_dark", "dusk"), ], Some(&session), @@ -324,9 +324,9 @@ async fn light_and_dark_colours_save_independently_and_render_on_html() { assert_eq!(saved.status, 303, "save: {}", saved.body); let page = env.http.get("/settings/appearance", Some(&session)).await; // The Custom radio carries the hue at the default vividness; the stored id stays `hue-200`. - let checked = ["hue-200-v50", "gold", "spark", "dusk"].map(str::to_owned); + let checked = ["hue-200-v50", "rose", "graphite", "dusk"].map(str::to_owned); assert_eq!(checked_colours(&page.body), checked.map(Some)); - let chosen = ["hue-200", "gold", "spark", "dusk"].map(str::to_owned); + let chosen = ["hue-200", "rose", "graphite", "dusk"].map(str::to_owned); assert_eq!(html_colours(&page.body), chosen.map(Some)); // The newest accents and backgrounds save and show the same way. @@ -369,16 +369,16 @@ async fn a_save_without_colour_fields_keeps_the_stored_colours() { ("theme", "light"), ("language", "en"), ("accent_light", "rose"), - ("accent_dark", "gold"), + ("accent_dark", "ocean"), ("base_light", "fern"), - ("base_dark", "spark"), + ("base_dark", "dusk"), ], Some(&session), ) .await; assert_eq!(saved.status, 303, "save: {}", saved.body); let before = env.http.get("/settings/appearance", Some(&session)).await; - let stored = ["rose", "gold", "fern", "spark"].map(str::to_owned); + let stored = ["rose", "ocean", "fern", "dusk"].map(str::to_owned); assert_eq!(html_colours(&before.body), stored.clone().map(Some)); let saved = env diff --git a/crates/forge-e2e/tests/e2e/wiki_e2e.rs b/crates/forge-e2e/tests/e2e/wiki_e2e.rs index 78d1bb3..a5397b8 100644 --- a/crates/forge-e2e/tests/e2e/wiki_e2e.rs +++ b/crates/forge-e2e/tests/e2e/wiki_e2e.rs @@ -242,7 +242,7 @@ async fn wiki_end_to_end() { .await; assert_eq!(audit.status, 200, "audit page"); assert!( - audit.body.contains("wiki_pushed"), + audit.body.contains("title=\"wiki_pushed\""), "the wiki push is audited: {}", audit.body ); diff --git a/crates/forge-web-base/src/accent.rs b/crates/forge-web-base/src/accent.rs index 8b44e19..b2475c8 100644 --- a/crates/forge-web-base/src/accent.rs +++ b/crates/forge-web-base/src/accent.rs @@ -310,16 +310,24 @@ mod tests { fn the_presets_are_offered_in_picker_order_and_removed_ids_are_not() { assert_eq!( ids().collect::>(), - ["ember", "sage", "spark", "ocean", "plum", "rose", "gold"] + ["ember", "sage", "ocean", "plum", "rose"] ); assert_eq!( base_ids().collect::>(), - ["anvil", "fern", "spark", "graphite", "dusk", "ink"] + ["anvil", "fern", "graphite", "dusk", "ink"] ); - for id in ["ochre", "teal", "Sage", "sage ", "terracotta"] { + for id in [ + "ochre", + "teal", + "Sage", + "sage ", + "terracotta", + "spark", + "gold", + ] { assert!(!is_offered(id), "{id}"); } - for id in ["stone", "mist", "Fern", "dune", "slate-blue"] { + for id in ["stone", "mist", "Fern", "dune", "slate-blue", "spark"] { assert!(!is_offered_base(id), "{id}"); } } @@ -372,11 +380,11 @@ mod tests { fn preset_hues_come_from_the_colour() { assert_eq!(preset_accent_hue("sage"), Some(149)); assert_eq!(preset_accent_hue("ocean"), Some(240)); - assert_eq!(preset_accent_hue("spark"), Some(42)); + assert_eq!(preset_accent_hue("plum"), Some(300)); assert_eq!(preset_accent_hue("fern"), None); assert_eq!(preset_accent_hue("hue-5"), None); assert!(preset_base_hue("fern").is_some()); - assert!(preset_base_hue("spark").is_some()); + assert!(preset_base_hue("dusk").is_some()); assert_eq!(preset_base_hue("sage"), None); } @@ -406,8 +414,8 @@ mod tests { Some("/theme/custom.css?al=hue-215&ad=plum&bl=fern&bd=hue-7") ); assert_eq!( - custom_css_href("sage", "sage", "spark", "hue-0").as_deref(), - Some("/theme/custom.css?al=sage&ad=sage&bl=spark&bd=hue-0") + custom_css_href("sage", "sage", "ink", "hue-0").as_deref(), + Some("/theme/custom.css?al=sage&ad=sage&bl=ink&bd=hue-0") ); } diff --git a/crates/forge-web-base/src/accent_palette.rs b/crates/forge-web-base/src/accent_palette.rs index c5a607c..073175f 100644 --- a/crates/forge-web-base/src/accent_palette.rs +++ b/crates/forge-web-base/src/accent_palette.rs @@ -141,34 +141,6 @@ pub const PALETTES: &[Palette] = &[ hunk_text: "#B3C385", }, }, - // Flare orange: a bright, clean orange on plain neutral greys. - Palette { - id: "spark", - light: Tokens { - accent: "#E8590C", - accent_ink: "#A83A07", - accent_soft: "#FDE9DB", - accent_text: "#18181B", - focus: "#A83A07", - public_bg: "#FDE9DB", - public_text: "#A83A07", - note: "#A83A07", - hunk_bg: "#FEF4EC", - hunk_text: "#9C3606", - }, - dark: Tokens { - accent: "#FF7A1A", - accent_ink: "#FF9A4D", - accent_soft: "#3B2214", - accent_text: "#18181B", - focus: "#FF7A1A", - public_bg: "#3B2214", - public_text: "#FF9A4D", - note: "#FF9A4D", - hunk_bg: "#2A1A10", - hunk_text: "#FF7A1A", - }, - }, // Blue, clear and cool. Palette { id: "ocean", @@ -253,34 +225,6 @@ pub const PALETTES: &[Palette] = &[ hunk_text: "#E79DAD", }, }, - // Bright yellow, leaning to lemon, so it takes dark text. - Palette { - id: "gold", - light: Tokens { - accent: "#D4A017", - accent_ink: "#7D5A00", - accent_soft: "#F8F0D6", - accent_text: "#1F1700", - focus: "#7D5A00", - public_bg: "#F8F0D6", - public_text: "#7D5A00", - note: "#7D5A00", - hunk_bg: "#FCF8EA", - hunk_text: "#7D5A00", - }, - dark: Tokens { - accent: "#E8BC4A", - accent_ink: "#F5D27A", - accent_soft: "#3A2E0E", - accent_text: "#1F1700", - focus: "#E8BC4A", - public_bg: "#3A2E0E", - public_text: "#F5D27A", - note: "#F5D27A", - hunk_bg: "#2A220D", - hunk_text: "#E8BC4A", - }, - }, ]; /// The neutral colour tokens one base sets in one theme. The values are CSS colours; @@ -438,38 +382,6 @@ pub const BASES: &[Base] = &[ ln_text: "#8A959A", }, }, - // Spark: plain neutral greys, barely warm. - Base { - id: "spark", - light: BaseTokens { - bg: "#FAFAFA", - surface: "#FFFFFF", - surface_2: "#F0F0F0", - text: "#18181B", - text_2: "#3F3F46", - muted: "#6C6C75", - border: "#E4E4E7", - border_strong: "#D4D4D8", - code_bg: "#F0F0F0", - private_bg: "#F0F0F0", - private_text: "#3F3F46", - ln_text: "#666670", - }, - dark: BaseTokens { - bg: "#18181A", - surface: "#212124", - surface_2: "#2A2A2E", - text: "#F4F4F5", - text_2: "#D4D4D8", - muted: "#A1A1AA", - border: "#3A3A40", - border_strong: "#4A4A50", - code_bg: "#111113", - private_bg: "#2A2A2E", - private_text: "#D4D4D8", - ln_text: "#A1A1AA", - }, - }, // Graphite: a cool neutral grey, flatter than the warmer neutrals. Base { id: "graphite", diff --git a/crates/forge-web-base/src/i18n/audit_names.rs b/crates/forge-web-base/src/i18n/audit_names.rs new file mode 100644 index 0000000..da4630c --- /dev/null +++ b/crates/forge-web-base/src/i18n/audit_names.rs @@ -0,0 +1,536 @@ +//! Display names for audit log entries: the action ids, the target kinds and the detail keys that +//! the audit log stores. An id with no name here shows its raw text, and the test below rules that +//! out for every action id. + +use super::Lang; + +/// The display name of an audit action id, or `None` for an id this table does not know. +pub fn action_name(lang: Lang, action: &str) -> Option<&'static str> { + match (action, lang) { + ("login_success", Lang::En) => Some("Signed in"), + ("login_success", Lang::Tr) => Some("Giriş yapıldı"), + ("login_failed", Lang::En) => Some("Sign-in failed"), + ("login_failed", Lang::Tr) => Some("Giriş başarısız"), + ("login_2fa_failed", Lang::En) => Some("Two-factor sign-in failed"), + ("login_2fa_failed", Lang::Tr) => Some("İki adımlı doğrulama başarısız"), + ("logout", Lang::En) => Some("Signed out"), + ("logout", Lang::Tr) => Some("Çıkış yapıldı"), + ("password_changed", Lang::En) => Some("Password changed"), + ("password_changed", Lang::Tr) => Some("Parola değiştirildi"), + ("email_changed", Lang::En) => Some("Email changed"), + ("email_changed", Lang::Tr) => Some("E-posta değiştirildi"), + ("password_reset_by_admin", Lang::En) => Some("Password reset by admin"), + ("password_reset_by_admin", Lang::Tr) => Some("Parola yönetici tarafından sıfırlandı"), + ("totp_enabled", Lang::En) => Some("Two-factor authentication turned on"), + ("totp_enabled", Lang::Tr) => Some("İki adımlı doğrulama açıldı"), + ("totp_disabled", Lang::En) => Some("Two-factor authentication turned off"), + ("totp_disabled", Lang::Tr) => Some("İki adımlı doğrulama kapatıldı"), + ("recovery_codes_regenerated", Lang::En) => Some("Recovery codes regenerated"), + ("recovery_codes_regenerated", Lang::Tr) => Some("Kurtarma kodları yenilendi"), + ("ssh_key_added", Lang::En) => Some("SSH key added"), + ("ssh_key_added", Lang::Tr) => Some("SSH anahtarı eklendi"), + ("ssh_key_removed", Lang::En) => Some("SSH key removed"), + ("ssh_key_removed", Lang::Tr) => Some("SSH anahtarı kaldırıldı"), + ("gpg_key_added", Lang::En) => Some("GPG key added"), + ("gpg_key_added", Lang::Tr) => Some("GPG anahtarı eklendi"), + ("gpg_key_deleted", Lang::En) => Some("GPG key deleted"), + ("gpg_key_deleted", Lang::Tr) => Some("GPG anahtarı silindi"), + ("token_created", Lang::En) => Some("Access token created"), + ("token_created", Lang::Tr) => Some("Erişim belirteci oluşturuldu"), + ("token_revoked", Lang::En) => Some("Access token revoked"), + ("token_revoked", Lang::Tr) => Some("Erişim belirteci iptal edildi"), + ("session_revoked", Lang::En) => Some("Session revoked"), + ("session_revoked", Lang::Tr) => Some("Oturum sonlandırıldı"), + ("user_created", Lang::En) => Some("User created"), + ("user_created", Lang::Tr) => Some("Kullanıcı oluşturuldu"), + ("username_changed", Lang::En) => Some("Username changed"), + ("username_changed", Lang::Tr) => Some("Kullanıcı adı değiştirildi"), + ("user_deleted", Lang::En) => Some("User deleted"), + ("user_deleted", Lang::Tr) => Some("Kullanıcı silindi"), + ("repo_created", Lang::En) => Some("Repository created"), + ("repo_created", Lang::Tr) => Some("Depo oluşturuldu"), + ("repo_deleted", Lang::En) => Some("Repository deleted"), + ("repo_deleted", Lang::Tr) => Some("Depo silindi"), + ("repo_renamed", Lang::En) => Some("Repository renamed"), + ("repo_renamed", Lang::Tr) => Some("Depo yeniden adlandırıldı"), + ("repo_transferred", Lang::En) => Some("Repository transferred"), + ("repo_transferred", Lang::Tr) => Some("Depo devredildi"), + ("repo_transfer_initiated", Lang::En) => Some("Repository transfer started"), + ("repo_transfer_initiated", Lang::Tr) => Some("Depo devri başlatıldı"), + ("repo_transfer_accepted", Lang::En) => Some("Repository transfer accepted"), + ("repo_transfer_accepted", Lang::Tr) => Some("Depo devri kabul edildi"), + ("repo_transfer_declined", Lang::En) => Some("Repository transfer declined"), + ("repo_transfer_declined", Lang::Tr) => Some("Depo devri reddedildi"), + ("repo_transfer_cancelled", Lang::En) => Some("Repository transfer cancelled"), + ("repo_transfer_cancelled", Lang::Tr) => Some("Depo devri iptal edildi"), + ("repo_visibility_changed", Lang::En) => Some("Repository visibility changed"), + ("repo_visibility_changed", Lang::Tr) => Some("Depo görünürlüğü değiştirildi"), + ("collaborator_added", Lang::En) => Some("Collaborator added"), + ("collaborator_added", Lang::Tr) => Some("Ortak eklendi"), + ("collaborator_removed", Lang::En) => Some("Collaborator removed"), + ("collaborator_removed", Lang::Tr) => Some("Ortak kaldırıldı"), + ("collaborator_role_changed", Lang::En) => Some("Collaborator role changed"), + ("collaborator_role_changed", Lang::Tr) => Some("Ortak rolü değiştirildi"), + ("branch_rule_created", Lang::En) => Some("Branch rule created"), + ("branch_rule_created", Lang::Tr) => Some("Dal kuralı oluşturuldu"), + ("branch_rule_updated", Lang::En) => Some("Branch rule updated"), + ("branch_rule_updated", Lang::Tr) => Some("Dal kuralı güncellendi"), + ("branch_rule_deleted", Lang::En) => Some("Branch rule deleted"), + ("branch_rule_deleted", Lang::Tr) => Some("Dal kuralı silindi"), + ("repo_archived", Lang::En) => Some("Repository archived"), + ("repo_archived", Lang::Tr) => Some("Depo arşivlendi"), + ("repo_unarchived", Lang::En) => Some("Repository unarchived"), + ("repo_unarchived", Lang::Tr) => Some("Depo arşivden çıkarıldı"), + ("webhook_created", Lang::En) => Some("Webhook created"), + ("webhook_created", Lang::Tr) => Some("Web kancası oluşturuldu"), + ("webhook_updated", Lang::En) => Some("Webhook updated"), + ("webhook_updated", Lang::Tr) => Some("Web kancası güncellendi"), + ("webhook_deleted", Lang::En) => Some("Webhook deleted"), + ("webhook_deleted", Lang::Tr) => Some("Web kancası silindi"), + ("mirror_created", Lang::En) => Some("Mirror created"), + ("mirror_created", Lang::Tr) => Some("Yansı oluşturuldu"), + ("mirror_updated", Lang::En) => Some("Mirror updated"), + ("mirror_updated", Lang::Tr) => Some("Yansı güncellendi"), + ("mirror_deleted", Lang::En) => Some("Mirror deleted"), + ("mirror_deleted", Lang::Tr) => Some("Yansı silindi"), + ("mirror_sync_failed", Lang::En) => Some("Mirror sync failed"), + ("mirror_sync_failed", Lang::Tr) => Some("Yansı eşitleme başarısız"), + ("backup_started", Lang::En) => Some("Backup started"), + ("backup_started", Lang::Tr) => Some("Yedekleme başlatıldı"), + ("fsck_started", Lang::En) => Some("Integrity check started"), + ("fsck_started", Lang::Tr) => Some("Bütünlük denetimi başlatıldı"), + ("replication_reconcile_started", Lang::En) => Some("Replication reconcile started"), + ("replication_reconcile_started", Lang::Tr) => Some("Çoğaltma uzlaştırması başlatıldı"), + ("ci_secret_set", Lang::En) => Some("CI secret set"), + ("ci_secret_set", Lang::Tr) => Some("CI gizli değeri ayarlandı"), + ("ci_secret_deleted", Lang::En) => Some("CI secret deleted"), + ("ci_secret_deleted", Lang::Tr) => Some("CI gizli değeri silindi"), + ("ci_runner_registered", Lang::En) => Some("CI runner registered"), + ("ci_runner_registered", Lang::Tr) => Some("CI çalıştırıcısı kaydedildi"), + ("ci_runner_deleted", Lang::En) => Some("CI runner deleted"), + ("ci_runner_deleted", Lang::Tr) => Some("CI çalıştırıcısı silindi"), + ("ci_runner_restart_requested", Lang::En) => Some("CI runner restart requested"), + ("ci_runner_restart_requested", Lang::Tr) => { + Some("CI çalıştırıcısının yeniden başlatılması istendi") + } + ("ci_runner_config_changed", Lang::En) => Some("CI runner settings changed"), + ("ci_runner_config_changed", Lang::Tr) => Some("CI çalıştırıcısı ayarları değiştirildi"), + ("ci_registration_token_created", Lang::En) => Some("CI registration token created"), + ("ci_registration_token_created", Lang::Tr) => Some("CI kayıt belirteci oluşturuldu"), + ("advisory_alert_dismissed", Lang::En) => Some("Advisory alert dismissed"), + ("advisory_alert_dismissed", Lang::Tr) => Some("Güvenlik uyarısı kapatıldı"), + ("advisory_alert_reopened", Lang::En) => Some("Advisory alert reopened"), + ("advisory_alert_reopened", Lang::Tr) => Some("Güvenlik uyarısı yeniden açıldı"), + ("ui_prefs_changed", Lang::En) => Some("Display preferences changed"), + ("ui_prefs_changed", Lang::Tr) => Some("Görünüm tercihleri değiştirildi"), + ("discussions_enabled", Lang::En) => Some("Discussions turned on"), + ("discussions_enabled", Lang::Tr) => Some("Tartışmalar açıldı"), + ("discussions_disabled", Lang::En) => Some("Discussions turned off"), + ("discussions_disabled", Lang::Tr) => Some("Tartışmalar kapatıldı"), + ("discussion_created", Lang::En) => Some("Discussion created"), + ("discussion_created", Lang::Tr) => Some("Tartışma oluşturuldu"), + ("discussion_edited", Lang::En) => Some("Discussion edited"), + ("discussion_edited", Lang::Tr) => Some("Tartışma düzenlendi"), + ("discussion_deleted", Lang::En) => Some("Discussion deleted"), + ("discussion_deleted", Lang::Tr) => Some("Tartışma silindi"), + ("discussion_locked", Lang::En) => Some("Discussion locked"), + ("discussion_locked", Lang::Tr) => Some("Tartışma kilitlendi"), + ("discussion_unlocked", Lang::En) => Some("Discussion unlocked"), + ("discussion_unlocked", Lang::Tr) => Some("Tartışmanın kilidi açıldı"), + ("discussion_answered", Lang::En) => Some("Discussion answered"), + ("discussion_answered", Lang::Tr) => Some("Tartışma yanıtlandı"), + ("discussion_comment_created", Lang::En) => Some("Discussion comment posted"), + ("discussion_comment_created", Lang::Tr) => Some("Tartışmaya yorum eklendi"), + ("discussion_comment_edited", Lang::En) => Some("Discussion comment edited"), + ("discussion_comment_edited", Lang::Tr) => Some("Tartışma yorumu düzenlendi"), + ("discussion_comment_deleted", Lang::En) => Some("Discussion comment deleted"), + ("discussion_comment_deleted", Lang::Tr) => Some("Tartışma yorumu silindi"), + ("mail_settings_updated", Lang::En) => Some("Mail settings updated"), + ("mail_settings_updated", Lang::Tr) => Some("E-posta ayarları güncellendi"), + ("mail_test_queued", Lang::En) => Some("Test email queued"), + ("mail_test_queued", Lang::Tr) => Some("Deneme e-postası kuyruğa alındı"), + ("server_settings_updated", Lang::En) => Some("Server settings updated"), + ("server_settings_updated", Lang::Tr) => Some("Sunucu ayarları güncellendi"), + ("server_restarted", Lang::En) => Some("Server restarted"), + ("server_restarted", Lang::Tr) => Some("Sunucu yeniden başlatıldı"), + ("snippet_created", Lang::En) => Some("Snippet created"), + ("snippet_created", Lang::Tr) => Some("Parçacık oluşturuldu"), + ("snippet_updated", Lang::En) => Some("Snippet updated"), + ("snippet_updated", Lang::Tr) => Some("Parçacık güncellendi"), + ("snippet_deleted", Lang::En) => Some("Snippet deleted"), + ("snippet_deleted", Lang::Tr) => Some("Parçacık silindi"), + ("wiki_page_saved", Lang::En) => Some("Wiki page saved"), + ("wiki_page_saved", Lang::Tr) => Some("Wiki sayfası kaydedildi"), + ("wiki_enabled", Lang::En) => Some("Wiki turned on"), + ("wiki_enabled", Lang::Tr) => Some("Wiki açıldı"), + ("wiki_disabled", Lang::En) => Some("Wiki turned off"), + ("wiki_disabled", Lang::Tr) => Some("Wiki kapatıldı"), + ("wiki_pushed", Lang::En) => Some("Wiki pushed"), + ("wiki_pushed", Lang::Tr) => Some("Wiki gönderildi"), + ("org_created", Lang::En) => Some("Organization created"), + ("org_created", Lang::Tr) => Some("Kuruluş oluşturuldu"), + ("org_deleted", Lang::En) => Some("Organization deleted"), + ("org_deleted", Lang::Tr) => Some("Kuruluş silindi"), + ("org_settings_updated", Lang::En) => Some("Organization settings updated"), + ("org_settings_updated", Lang::Tr) => Some("Kuruluş ayarları güncellendi"), + ("org_member_added", Lang::En) => Some("Organization member added"), + ("org_member_added", Lang::Tr) => Some("Kuruluşa üye eklendi"), + ("org_member_removed", Lang::En) => Some("Organization member removed"), + ("org_member_removed", Lang::Tr) => Some("Kuruluş üyesi çıkarıldı"), + ("org_member_role_changed", Lang::En) => Some("Organization member role changed"), + ("org_member_role_changed", Lang::Tr) => Some("Kuruluş üyesinin rolü değiştirildi"), + ("team_created", Lang::En) => Some("Team created"), + ("team_created", Lang::Tr) => Some("Takım oluşturuldu"), + ("team_updated", Lang::En) => Some("Team updated"), + ("team_updated", Lang::Tr) => Some("Takım güncellendi"), + ("team_deleted", Lang::En) => Some("Team deleted"), + ("team_deleted", Lang::Tr) => Some("Takım silindi"), + ("team_member_added", Lang::En) => Some("Team member added"), + ("team_member_added", Lang::Tr) => Some("Takıma üye eklendi"), + ("team_member_removed", Lang::En) => Some("Team member removed"), + ("team_member_removed", Lang::Tr) => Some("Takım üyesi çıkarıldı"), + ("team_repo_added", Lang::En) => Some("Repository added to team"), + ("team_repo_added", Lang::Tr) => Some("Takıma depo eklendi"), + ("team_repo_removed", Lang::En) => Some("Repository removed from team"), + ("team_repo_removed", Lang::Tr) => Some("Takımdan depo çıkarıldı"), + ("password_reset_completed", Lang::En) => Some("Password reset completed"), + ("password_reset_completed", Lang::Tr) => Some("Parola sıfırlama tamamlandı"), + ("email_verified", Lang::En) => Some("Email verified"), + ("email_verified", Lang::Tr) => Some("E-posta doğrulandı"), + ("invite_sent", Lang::En) => Some("Invite sent"), + ("invite_sent", Lang::Tr) => Some("Davet gönderildi"), + ("invite_accepted", Lang::En) => Some("Invite accepted"), + ("invite_accepted", Lang::Tr) => Some("Davet kabul edildi"), + ("user_suspended", Lang::En) => Some("User suspended"), + ("user_suspended", Lang::Tr) => Some("Kullanıcı askıya alındı"), + ("user_unsuspended", Lang::En) => Some("User unsuspended"), + ("user_unsuspended", Lang::Tr) => Some("Kullanıcının askısı kaldırıldı"), + ("admin_granted", Lang::En) => Some("Admin access granted"), + ("admin_granted", Lang::Tr) => Some("Yönetici yetkisi verildi"), + ("admin_revoked", Lang::En) => Some("Admin access revoked"), + ("admin_revoked", Lang::Tr) => Some("Yönetici yetkisi alındı"), + ("totp_disabled_by_admin", Lang::En) => { + Some("Two-factor authentication turned off by admin") + } + ("totp_disabled_by_admin", Lang::Tr) => { + Some("İki adımlı doğrulama yönetici tarafından kapatıldı") + } + ("passkey_added", Lang::En) => Some("Passkey added"), + ("passkey_added", Lang::Tr) => Some("Geçiş anahtarı eklendi"), + ("passkey_renamed", Lang::En) => Some("Passkey renamed"), + ("passkey_renamed", Lang::Tr) => Some("Geçiş anahtarı yeniden adlandırıldı"), + ("passkey_deleted", Lang::En) => Some("Passkey deleted"), + ("passkey_deleted", Lang::Tr) => Some("Geçiş anahtarı silindi"), + ("passkeys_removed_by_admin", Lang::En) => Some("Passkeys removed by admin"), + ("passkeys_removed_by_admin", Lang::Tr) => { + Some("Geçiş anahtarları yönetici tarafından kaldırıldı") + } + ("passkey_login", Lang::En) => Some("Signed in with passkey"), + ("passkey_login", Lang::Tr) => Some("Geçiş anahtarıyla giriş yapıldı"), + _ => None, + } +} + +/// The display name of a target kind (what an audit entry was done to), or `None` if unknown. +pub fn target_kind_name(lang: Lang, kind: &str) -> Option<&'static str> { + match (kind, lang) { + ("backup", Lang::En) => Some("backup"), + ("backup", Lang::Tr) => Some("yedek"), + ("branch_rule", Lang::En) => Some("branch rule"), + ("branch_rule", Lang::Tr) => Some("dal kuralı"), + ("ci_runner", Lang::En) => Some("CI runner"), + ("ci_runner", Lang::Tr) => Some("CI çalıştırıcısı"), + ("ci_runner_token", Lang::En) => Some("CI runner token"), + ("ci_runner_token", Lang::Tr) => Some("CI çalıştırıcı belirteci"), + ("comment", Lang::En) => Some("comment"), + ("comment", Lang::Tr) => Some("yorum"), + ("discussion", Lang::En) => Some("discussion"), + ("discussion", Lang::Tr) => Some("tartışma"), + ("fsck", Lang::En) => Some("integrity check"), + ("fsck", Lang::Tr) => Some("bütünlük denetimi"), + ("gpg_key", Lang::En) => Some("GPG key"), + ("gpg_key", Lang::Tr) => Some("GPG anahtarı"), + ("invite", Lang::En) => Some("invite"), + ("invite", Lang::Tr) => Some("davet"), + ("issue", Lang::En) => Some("issue"), + ("issue", Lang::Tr) => Some("sorun"), + ("mail", Lang::En) => Some("mail"), + ("mail", Lang::Tr) => Some("e-posta"), + ("mirror", Lang::En) => Some("mirror"), + ("mirror", Lang::Tr) => Some("yansı"), + ("org", Lang::En) => Some("organization"), + ("org", Lang::Tr) => Some("kuruluş"), + ("replication", Lang::En) => Some("replication"), + ("replication", Lang::Tr) => Some("çoğaltma"), + ("repo", Lang::En) => Some("repository"), + ("repo", Lang::Tr) => Some("depo"), + ("server", Lang::En) => Some("server"), + ("server", Lang::Tr) => Some("sunucu"), + ("session", Lang::En) => Some("session"), + ("session", Lang::Tr) => Some("oturum"), + ("snippet", Lang::En) => Some("snippet"), + ("snippet", Lang::Tr) => Some("parçacık"), + ("ssh_key", Lang::En) => Some("SSH key"), + ("ssh_key", Lang::Tr) => Some("SSH anahtarı"), + ("team", Lang::En) => Some("team"), + ("team", Lang::Tr) => Some("takım"), + ("token", Lang::En) => Some("access token"), + ("token", Lang::Tr) => Some("erişim belirteci"), + ("user", Lang::En) => Some("user"), + ("user", Lang::Tr) => Some("kullanıcı"), + _ => None, + } +} + +/// The display name of a key stored in an audit entry's details, or `None` if unknown. +pub fn detail_key_name(lang: Lang, key: &str) -> Option<&'static str> { + match (key, lang) { + ("user", Lang::En) => Some("user"), + ("user", Lang::Tr) => Some("kullanıcı"), + ("trigger", Lang::En) => Some("trigger"), + ("trigger", Lang::Tr) => Some("tetikleyici"), + ("to", Lang::En) => Some("to"), + ("to", Lang::Tr) => Some("hedef"), + ("name", Lang::En) => Some("name"), + ("name", Lang::Tr) => Some("ad"), + ("from", Lang::En) => Some("from"), + ("from", Lang::Tr) => Some("kaynak"), + ("role", Lang::En) => Some("role"), + ("role", Lang::Tr) => Some("rol"), + ("mirror_id", Lang::En) => Some("mirror"), + ("mirror_id", Lang::Tr) => Some("yansı"), + ("direction", Lang::En) => Some("direction"), + ("direction", Lang::Tr) => Some("yön"), + ("url", Lang::En) => Some("URL"), + ("url", Lang::Tr) => Some("URL"), + ("reason", Lang::En) => Some("reason"), + ("reason", Lang::Tr) => Some("neden"), + ("hook_id", Lang::En) => Some("webhook"), + ("hook_id", Lang::Tr) => Some("web kancası"), + ("admin", Lang::En) => Some("admin"), + ("admin", Lang::Tr) => Some("yönetici"), + ("theme", Lang::En) => Some("theme"), + ("theme", Lang::Tr) => Some("tema"), + ("set", Lang::En) => Some("set"), + ("set", Lang::Tr) => Some("ayarlanan"), + ("cleared", Lang::En) => Some("cleared"), + ("cleared", Lang::Tr) => Some("temizlenen"), + ("reset", Lang::En) => Some("reset"), + ("reset", Lang::Tr) => Some("sıfırlanan"), + ("runner_id", Lang::En) => Some("runner"), + ("runner_id", Lang::Tr) => Some("çalıştırıcı"), + ("repo_id", Lang::En) => Some("repository"), + ("repo_id", Lang::Tr) => Some("depo"), + ("reassigned_to", Lang::En) => Some("reassigned to"), + ("reassigned_to", Lang::Tr) => Some("devredilen"), + ("language", Lang::En) => Some("language"), + ("language", Lang::Tr) => Some("dil"), + ("full", Lang::En) => Some("full"), + ("full", Lang::Tr) => Some("tam"), + ("field", Lang::En) => Some("field"), + ("field", Lang::Tr) => Some("alan"), + ("avatar", Lang::En) => Some("avatar"), + ("avatar", Lang::Tr) => Some("profil resmi"), + ("updates", Lang::En) => Some("updates"), + ("updates", Lang::Tr) => Some("güncellemeler"), + ("ttl_hours", Lang::En) => Some("valid for hours"), + ("ttl_hours", Lang::Tr) => Some("geçerlilik (saat)"), + ("setup", Lang::En) => Some("setup"), + ("setup", Lang::Tr) => Some("kurulum"), + ("self_service", Lang::En) => Some("self-service"), + ("self_service", Lang::Tr) => Some("kendi kendine"), + ("self", Lang::En) => Some("self"), + ("self", Lang::Tr) => Some("kendisi"), + ("second_factor", Lang::En) => Some("second factor"), + ("second_factor", Lang::Tr) => Some("ikinci adım"), + ("register", Lang::En) => Some("register"), + ("register", Lang::Tr) => Some("kayıt"), + ("port", Lang::En) => Some("port"), + ("port", Lang::Tr) => Some("bağlantı noktası"), + ("page", Lang::En) => Some("page"), + ("page", Lang::Tr) => Some("sayfa"), + ("others", Lang::En) => Some("others"), + ("others", Lang::Tr) => Some("diğerleri"), + ("org", Lang::En) => Some("organization"), + ("org", Lang::Tr) => Some("kuruluş"), + ("mode", Lang::En) => Some("mode"), + ("mode", Lang::Tr) => Some("mod"), + ("members_can_create_repos", Lang::En) => Some("members can create repositories"), + ("members_can_create_repos", Lang::Tr) => Some("üyeler depo oluşturabilir"), + ("invite", Lang::En) => Some("invite"), + ("invite", Lang::Tr) => Some("davet"), + ("import", Lang::En) => Some("import"), + ("import", Lang::Tr) => Some("içe aktarma"), + ("host", Lang::En) => Some("host"), + ("host", Lang::Tr) => Some("sunucu adresi"), + ("fork_of", Lang::En) => Some("fork of"), + ("fork_of", Lang::Tr) => Some("çatal kaynağı"), + ("enabled", Lang::En) => Some("enabled"), + ("enabled", Lang::Tr) => Some("açık"), + ("ecosystem", Lang::En) => Some("ecosystem"), + ("ecosystem", Lang::Tr) => Some("ekosistem"), + ("default_repo_role", Lang::En) => Some("default repository role"), + ("default_repo_role", Lang::Tr) => Some("varsayılan depo rolü"), + ("commit", Lang::En) => Some("commit"), + ("commit", Lang::Tr) => Some("commit"), + ("boot_id", Lang::En) => Some("boot ID"), + ("boot_id", Lang::Tr) => Some("açılış kimliği"), + ("all_repos", Lang::En) => Some("all repositories"), + ("all_repos", Lang::Tr) => Some("tüm depolar"), + ("advisory", Lang::En) => Some("advisory"), + ("advisory", Lang::Tr) => Some("güvenlik uyarısı"), + ("version", Lang::En) => Some("version"), + ("version", Lang::Tr) => Some("sürüm"), + ("security", Lang::En) => Some("security"), + ("security", Lang::Tr) => Some("güvenlik"), + ("secret_changed", Lang::En) => Some("secret changed"), + ("secret_changed", Lang::Tr) => Some("gizli değer değişti"), + ("secret_cleared", Lang::En) => Some("secret cleared"), + ("secret_cleared", Lang::Tr) => Some("gizli değer temizlendi"), + ("password_changed", Lang::En) => Some("password changed"), + ("password_changed", Lang::Tr) => Some("parola değiştirildi"), + ("package", Lang::En) => Some("package"), + ("package", Lang::Tr) => Some("paket"), + ("user_ids", Lang::En) => Some("users"), + ("user_ids", Lang::Tr) => Some("kullanıcılar"), + ("base_light", Lang::En) => Some("light base"), + ("base_light", Lang::Tr) => Some("açık taban"), + ("base_dark", Lang::En) => Some("dark base"), + ("base_dark", Lang::Tr) => Some("koyu taban"), + ("accent_light", Lang::En) => Some("light accent"), + ("accent_light", Lang::Tr) => Some("açık vurgu"), + ("accent_dark", Lang::En) => Some("dark accent"), + ("accent_dark", Lang::Tr) => Some("koyu vurgu"), + ("passkey", Lang::En) => Some("passkey"), + ("passkey", Lang::Tr) => Some("geçiş anahtarı"), + ("ok", Lang::En) => Some("ok"), + ("ok", Lang::Tr) => Some("tamam"), + ("next", Lang::En) => Some("next"), + ("next", Lang::Tr) => Some("sonraki"), + _ => None, + } +} + +#[cfg(test)] +mod tests { + use super::*; + + const ACTION_IDS: &[&str] = &[ + "login_success", + "login_failed", + "login_2fa_failed", + "logout", + "password_changed", + "email_changed", + "password_reset_by_admin", + "totp_enabled", + "totp_disabled", + "recovery_codes_regenerated", + "ssh_key_added", + "ssh_key_removed", + "gpg_key_added", + "gpg_key_deleted", + "token_created", + "token_revoked", + "session_revoked", + "user_created", + "username_changed", + "user_deleted", + "repo_created", + "repo_deleted", + "repo_renamed", + "repo_transferred", + "repo_transfer_initiated", + "repo_transfer_accepted", + "repo_transfer_declined", + "repo_transfer_cancelled", + "repo_visibility_changed", + "collaborator_added", + "collaborator_removed", + "collaborator_role_changed", + "branch_rule_created", + "branch_rule_updated", + "branch_rule_deleted", + "repo_archived", + "repo_unarchived", + "webhook_created", + "webhook_updated", + "webhook_deleted", + "mirror_created", + "mirror_updated", + "mirror_deleted", + "mirror_sync_failed", + "backup_started", + "fsck_started", + "replication_reconcile_started", + "ci_secret_set", + "ci_secret_deleted", + "ci_runner_registered", + "ci_runner_deleted", + "ci_runner_restart_requested", + "ci_runner_config_changed", + "ci_registration_token_created", + "advisory_alert_dismissed", + "advisory_alert_reopened", + "ui_prefs_changed", + "discussions_enabled", + "discussions_disabled", + "discussion_created", + "discussion_edited", + "discussion_deleted", + "discussion_locked", + "discussion_unlocked", + "discussion_answered", + "discussion_comment_created", + "discussion_comment_edited", + "discussion_comment_deleted", + "mail_settings_updated", + "mail_test_queued", + "server_settings_updated", + "server_restarted", + "snippet_created", + "snippet_updated", + "snippet_deleted", + "wiki_page_saved", + "wiki_enabled", + "wiki_disabled", + "wiki_pushed", + "org_created", + "org_deleted", + "org_settings_updated", + "org_member_added", + "org_member_removed", + "org_member_role_changed", + "team_created", + "team_updated", + "team_deleted", + "team_member_added", + "team_member_removed", + "team_repo_added", + "team_repo_removed", + "password_reset_completed", + "email_verified", + "invite_sent", + "invite_accepted", + "user_suspended", + "user_unsuspended", + "admin_granted", + "admin_revoked", + "totp_disabled_by_admin", + "passkey_added", + "passkey_renamed", + "passkey_deleted", + "passkeys_removed_by_admin", + "passkey_login", + ]; + + #[test] + fn every_action_has_both_names() { + for id in ACTION_IDS { + assert!( + action_name(Lang::En, id).is_some() && action_name(Lang::Tr, id).is_some(), + "{id}" + ); + } + } +} diff --git a/crates/forge-web-base/src/i18n/issues.rs b/crates/forge-web-base/src/i18n/issues.rs index dcc3cb8..ec604f9 100644 --- a/crates/forge-web-base/src/i18n/issues.rs +++ b/crates/forge-web-base/src/i18n/issues.rs @@ -675,18 +675,18 @@ pub fn history_what(lang: Lang, pull: bool, target_kind: &str) -> &'static str { } } -/// The history page title: `Edit history of a {what} · {suffix}`. +/// The history page title: `Edit history of the {what} · {suffix}`. pub fn history_title(lang: Lang, what: &str, suffix: &str) -> String { match lang { - Lang::En => format!("Edit history of a {what} \u{b7} {suffix}"), + Lang::En => format!("Edit history of the {what} \u{b7} {suffix}"), Lang::Tr => format!("Düzenleme geçmişi: {what} \u{b7} {suffix}"), } } -/// The history page heading: `Edit history of {what}`. +/// The history page heading: `Edit history of the {what}`. pub fn history_heading(lang: Lang, what: &str) -> String { match lang { - Lang::En => format!("Edit history of {what}"), + Lang::En => format!("Edit history of the {what}"), Lang::Tr => format!("Düzenleme geçmişi: {what}"), } } diff --git a/crates/forge-web-base/src/i18n/mod.rs b/crates/forge-web-base/src/i18n/mod.rs index 809b27f..4d255bd 100644 --- a/crates/forge-web-base/src/i18n/mod.rs +++ b/crates/forge-web-base/src/i18n/mod.rs @@ -21,6 +21,7 @@ pub mod accents; pub mod accounts; pub mod admin; pub mod alerts; +pub mod audit_names; pub mod authoring; pub mod browse; pub mod code; @@ -906,8 +907,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { (Added, Tr) => "eklendi", (LastUsed, En) => "last used", (LastUsed, Tr) => "son kullanım", - (Created, En) => "Created", - (Created, Tr) => "Oluşturuldu", + (Created, En) => "created", + (Created, Tr) => "oluşturma", (SignedIn, En) => "Signed in", (SignedIn, Tr) => "Giriş", (LastSeen, En) => "last seen", diff --git a/crates/forge-web/src/pages/admin_mail.rs b/crates/forge-web/src/pages/admin_mail.rs index e4687e1..2100119 100644 --- a/crates/forge-web/src/pages/admin_mail.rs +++ b/crates/forge-web/src/pages/admin_mail.rs @@ -309,28 +309,23 @@ async fn mail_view( } else {
for row in queue.rows.into_iter() { -
- - (row.subject.as_str()) - (row.to.as_str()) " · " (row.kind) " · " (row.state) - -
-

(g::t(lang, K::TableQueued)) " " rel_time(lang: lang, stamp: row.created.as_str())

-

(g::t(lang, K::TableTries)) " " (row.attempts)

+
+ (row.subject.as_str()) + (row.to.as_str()) " · " (row.kind) " · " (row.state) + " · " (g::t(lang, K::TableQueued)) " " rel_time(lang: lang, stamp: row.created.as_str()) + " · " (g::t(lang, K::TableTries)) " " (row.attempts) if let Some(sent) = row.sent.as_deref() { -

(g::t(lang, K::MailSentAt)) " " rel_time(lang: lang, stamp: sent)

+ " · " (g::t(lang, K::MailSentAt)) " " rel_time(lang: lang, stamp: sent) } if !row.error.is_empty() { -

(g::t(lang, K::TableLastError)) " " (row.error.as_str())

+ " · " (g::t(lang, K::TableLastError)) ": " (row.error.as_str()) } - if row.failed { -
- post_act(label: g::t(lang, K::MailRetryNow), action: "/admin/mail/queue/retry", csrf: csrf.as_str(), fields: vec![("id".to_owned(), row.id.clone()), ("state".to_owned(), filter_param.clone())]) - confirm_act(lang: lang, label: g::t(lang, K::MailDiscard), action: "/admin/mail/queue/discard", csrf: csrf.as_str(), fields: vec![("id".to_owned(), row.id.clone()), ("state".to_owned(), filter_param.clone())], note: Some(crate::pages::passkeys::s(lang, "The message will not be sent.", "İleti gönderilmez.").to_owned())) -
- } -
-
+ + if row.failed { + post_act(label: g::t(lang, K::MailRetryNow), action: "/admin/mail/queue/retry", csrf: csrf.as_str(), fields: vec![("id".to_owned(), row.id.clone()), ("state".to_owned(), filter_param.clone())]) + confirm_act(lang: lang, label: g::t(lang, K::MailDiscard), action: "/admin/mail/queue/discard", csrf: csrf.as_str(), fields: vec![("id".to_owned(), row.id.clone()), ("state".to_owned(), filter_param.clone())], note: Some(crate::pages::passkeys::s(lang, "The message will not be sent.", "İleti gönderilmez.").to_owned())) + } +
} } diff --git a/crates/forge-web/src/pages/admin_user_detail.rs b/crates/forge-web/src/pages/admin_user_detail.rs index 7f07286..1512d51 100644 --- a/crates/forge-web/src/pages/admin_user_detail.rs +++ b/crates/forge-web/src/pages/admin_user_detail.rs @@ -4,6 +4,7 @@ //! like the rest of the admin area. use forge_core::names::normalize_name; +use forge_core::store::orgs::OrgMemberRole; use forge_core::store::suspension::{AccountFacts, Suspension}; use forge_core::store::user_delete::GHOST_USERNAME; use forge_core::{AuditAction, Store, User}; @@ -26,7 +27,7 @@ use crate::live::{Topic, stream_changes}; use crate::pages::admin_users::admin_only; use crate::pages::passkeys::s; use crate::state::AppState; -use crate::views::parts::{confirm_act, head, post_act, reveal}; +use crate::views::parts::{SubPart, confirm_act, head, post_act, reveal}; use crate::views::{alert, enc, rel_time, rel_time_or_never, shell, user_facing_message}; #[query_params(error = bad_request)] @@ -198,12 +199,10 @@ async fn detail_body( passkey_count ); Ok(view! { - head(title: target.username.as_str()) + head(title: target.username.as_str(), + (profile_label) + )
-

if !email.is_empty() { (email.as_str()) " · " @@ -289,7 +288,7 @@ async fn detail_body( if !own {

-

(i18n::t(lang, Key::Delete))

+

(i18n::t(lang, Key::DangerZone))

(at(lang, A::DeleteHelp))

(i18n::t(lang, Key::Delete)) @@ -300,25 +299,50 @@ async fn detail_body( }) } -/// An organization's page: its name, its member count, its profile, and its delete. An -/// organization is not a person, so the delete goes through the same POST as a user's. +/// An organization's page: its name, its members with a link to each account, its profile, and its +/// delete. An organization is not a person, so the delete goes through the same POST as a user's. #[component] -async fn org_body(lang: Lang, csrf: &str, org: User, members: usize) -> Result { +async fn org_body( + lang: Lang, + csrf: &str, + org: User, + members: Vec<(User, OrgMemberRole)>, +) -> Result { let base = format!("/admin/users/{}", enc(&org.id)); let delete_action = format!("{base}/delete"); let profile = format!("/{}", enc(&org.username)); - let members = members.to_string(); + let count = format!("{} {}", og::t(lang, OG::Members), members.len()); let profile_label = s(lang, "Open profile", "Profili aç"); + let organization = s(lang, "Organization", "Kuruluş"); + let owner = s(lang, "Owner", "Sahip"); + let member = s(lang, "Member", "Üye"); + let rows: Vec<(String, String, &str)> = members + .into_iter() + .map(|(user, role)| { + let href = format!("/admin/users/{}", enc(&user.id)); + let role = match role { + OrgMemberRole::Owner => owner, + OrgMemberRole::Member => member, + }; + (href, user.username, role) + }) + .collect(); Ok(view! { - head(title: org.username.as_str()) + head(title: org.username.as_str(), sub: vec![ + SubPart::text(organization), + SubPart::text(count.as_str()), + ], + (profile_label) + )
- -

(og::t(lang, OG::Members)) " " (members.as_str())

-

(i18n::t(lang, Key::Delete))

+

(og::t(lang, OG::Members))

+ for (href, name, role) in rows.iter() { + (name.as_str())(*role) + } +
+
+

(i18n::t(lang, Key::DangerZone))

confirm_act(lang: lang, label: g::t(lang, K::DeleteOrgTitle), action: delete_action.as_str(), csrf: csrf)
@@ -377,7 +401,7 @@ async fn detail_page(cx: &Cx) -> Result { let id = path_param_segment(cx, "user_id").to_owned(); let org = match store.user_by_id(&id).await? { Some(user) if user.is_org() => { - let members = store.org_members(&user.id).await?.len(); + let members = store.org_members(&user.id).await?; Some((user, members)) } _ => None, diff --git a/crates/forge-web/src/pages/audit_log.rs b/crates/forge-web/src/pages/audit_log.rs index d29d7d9..1485b8b 100644 --- a/crates/forge-web/src/pages/audit_log.rs +++ b/crates/forge-web/src/pages/audit_log.rs @@ -1,9 +1,10 @@ //! Pages: the admin audit log (`/admin/audit`, instance admins only, 404 otherwise) and a user's //! own security log (`/settings/security/log`: entries the viewer acted in, or that targeted -//! them). Both list newest first, a page of rows at a time, continued with a cursor: 8 rows on the +//! them). Both list newest first, a page of rows at a time, with numbered pages: 8 rows on the //! admin page (its filter bar takes the room) and 10 in the own log, sized to fit the window. +//! Repeats in a row (same action, actor and target) fold into one row with a count. -use forge_core::{AuditAction, AuditCursor, AuditEntry, AuditFilter, Store}; +use forge_core::{AuditAction, AuditEntry, AuditFilter, Store}; use topcoat::Result; use topcoat::context::{Cx, app_context}; use topcoat::router::response::Response; @@ -12,12 +13,15 @@ use topcoat::view::{View, component, view}; use crate::auth::require_user; use crate::i18n::admin::{self as g, K}; -use crate::i18n::{self, Lang}; +use crate::i18n::{self, Lang, audit_names}; use crate::live::{Topic, stream_changes}; use crate::pages::admin_users::admin_only; use crate::pages::issues_list::list_href; +use crate::pages::passkeys::s; +use crate::pages::settings_security::{security_rail_for, security_sub}; use crate::state::AppState; -use crate::views::parts::{SubPart, head}; +use crate::views::parts::{RailItem, SubPart, head, rail}; +use crate::views::repo_list::{PageLink, pager, pager_links}; use crate::views::{rel_time, shell}; /// Entries per page of the admin audit log, under its filter bar. @@ -26,21 +30,113 @@ const ADMIN_PAGE_SIZE: usize = 8; /// Entries per page of the own security log. const OWN_PAGE_SIZE: usize = 10; +/// Details shorter than this show in the row; longer ones move to the line's hover title. +const DETAILS_INLINE_CHARS: usize = 80; + #[query_params(error = bad_request)] pub(crate) struct AuditQuery { action: Option, actor: Option, + /// Old cursor links. Still accepted so old bookmarks load, and ignored. + #[allow(dead_code)] before: Option, + /// The 1-based page number. Anything unreadable is page 1. + page: Option, } -/// One table row, already formatted for display. +/// One table row, already formatted for display. A row can stand for several entries in a row. struct RowView { when: String, actor: String, + /// The action as words: "Ui prefs changed". + name: String, + /// The raw action, for the hover title. action: String, + /// "kind: name", or the name alone, or empty when the entry has no target name. target: String, ip: String, - details: String, + /// The details when short enough to show in the row. Empty when they are long. + details_inline: String, + /// The details when too long for the row, for the line's hover title. Empty otherwise. + details_title: String, + /// How many entries this row stands for. + count: usize, +} + +/// "ci_secret_set" as "CI secret set": words, with the short names in capitals. +fn action_words(action: &str) -> String { + let words: Vec = action + .split('_') + .enumerate() + .map(|(i, word)| match word { + "ci" | "ui" | "ip" | "ssh" | "gpg" | "oci" | "totp" | "2fa" | "api" | "pat" => { + word.to_uppercase() + } + _ if i == 0 => { + let mut chars = word.chars(); + match chars.next() { + Some(first) => first.to_uppercase().chain(chars).collect(), + None => String::new(), + } + } + _ => word.to_owned(), + }) + .collect(); + words.join(" ") +} + +/// A stored role ("write") in the viewer's language. +fn role_word(lang: Lang, role: &str) -> Option<&'static str> { + Some(match role { + "read" => s(lang, "read", "okuma"), + "write" => s(lang, "write", "yazma"), + "admin" => s(lang, "admin", "yönetici"), + "maintain" => s(lang, "maintain", "bakım"), + "triage" => s(lang, "triage", "ön değerlendirme"), + "owner" => s(lang, "owner", "sahip"), + "member" => s(lang, "member", "üye"), + _ => return None, + }) +} + +/// An action's name in the viewer's language; an action with no name yet reads as its words. +fn action_label(lang: Lang, action: &str) -> String { + audit_names::action_name(lang, action) + .map(str::to_owned) + .unwrap_or_else(|| action_words(action)) +} + +/// A flat JSON object as "key value · key value" in the viewer's language, so a row reads as +/// text. Anything else (nested values, arrays, broken JSON) stays as it was stored. +fn details_words(lang: Lang, data: &str) -> String { + let Ok(serde_json::Value::Object(map)) = serde_json::from_str::(data) else { + return data.to_owned(); + }; + let mut parts = Vec::with_capacity(map.len()); + for (key, value) in map { + let value = match value { + serde_json::Value::String(text) => text, + serde_json::Value::Bool(yes) => s( + lang, + if yes { "yes" } else { "no" }, + if yes { "evet" } else { "hayır" }, + ) + .to_owned(), + serde_json::Value::Number(_) | serde_json::Value::Null => value.to_string(), + _ => return data.to_owned(), + }; + // A role is a word of the app's own, so it reads in the viewer's language too. + let value = if key == "role" { + role_word(lang, &value).map(str::to_owned).unwrap_or(value) + } else { + value + }; + let key = audit_names::detail_key_name(lang, &key) + .map(str::to_owned) + .unwrap_or_else(|| key.replace('_', " ")); + parts.push(format!("{key} {value}")); + } + parts.join(" · ") } fn row_view(entry: &AuditEntry, lang: Lang) -> RowView { @@ -53,46 +149,100 @@ fn row_view(entry: &AuditEntry, lang: Lang) -> RowView { } else { entry.target_name.as_str() }; - let target = if entry.target_kind.is_empty() { - name.to_owned() + let target = match (entry.target_kind.is_empty(), name.is_empty()) { + (_, true) => String::new(), + (true, false) => name.to_owned(), + (false, false) => { + let kind = audit_names::target_kind_name(lang, &entry.target_kind) + .map(str::to_owned) + .unwrap_or_else(|| entry.target_kind.replace('_', " ")); + format!("{kind}: {name}") + } + }; + let details = if entry.data == "{}" { + String::new() + } else { + details_words(lang, &entry.data) + }; + let (details_inline, details_title) = if details.chars().count() < DETAILS_INLINE_CHARS { + (details.clone(), String::new()) } else { - format!("{}: {name}", entry.target_kind) + (String::new(), details.clone()) }; RowView { when: entry.at.clone(), actor, + name: action_label(lang, entry.action.as_str()), action: entry.action.as_str().to_owned(), target, ip: entry.ip.clone(), - details: if entry.data == "{}" { - String::new() - } else { - entry.data.clone() - }, + details_inline, + details_title, + count: 1, } } -/// One page of `size` entries, and the cursor for the page after it when there may be one. +/// Rows for `entries` (newest first), with consecutive entries of the same action, actor and +/// target folded into one row. The row keeps the newest entry's time, IP and details. +fn fold_rows(entries: &[AuditEntry], lang: Lang) -> Vec { + let mut rows: Vec<(&AuditEntry, RowView)> = Vec::new(); + for entry in entries { + if let Some((last, row)) = rows.last_mut() { + let same = last.action == entry.action + && last.actor_id == entry.actor_id + && last.actor_name == entry.actor_name + && last.target_kind == entry.target_kind + && last.target_id == entry.target_id + && last.target_name == entry.target_name; + if same { + row.count += 1; + continue; + } + } + rows.push((entry, row_view(entry, lang))); + } + rows.into_iter().map(|(_, row)| row).collect() +} + +/// The page the query asks for, 1-based. Anything unreadable is page 1. +fn requested_page(query: &AuditQuery) -> u64 { + query + .page + .as_deref() + .and_then(|p| p.parse::().ok()) + .unwrap_or(1) + .max(1) +} + +/// One page of `size` entries, and the page that was asked for, clamped to the pages there are, +/// with the page count. async fn fetch_page( store: &Store, filter: &AuditFilter, - before: Option<&str>, + page: u64, size: usize, -) -> forge_core::Result<(Vec, Option)> { - let cursor = before.and_then(AuditCursor::decode); - let mut entries = store - .list_audit(filter, cursor.as_ref(), (size + 1) as u32) - .await?; - let more = entries.len() > size; - entries.truncate(size); - let next = if more { - entries - .last() - .map(|entry| AuditCursor::after(entry).encode()) - } else { - None - }; - Ok((entries, next)) +) -> forge_core::Result<(Vec, u64, u64)> { + let total = store.count_audit(filter).await?; + let pages = total.div_ceil(size as u64).max(1); + let page = page.clamp(1, pages); + let offset = ((page - 1) * size as u64) as u32; + let entries = store.list_audit_page(filter, offset, size as u32).await?; + Ok((entries, page, pages)) +} + +/// The numbered pager's entries and links for `page` of `pages`, under `href`'s params. +fn nav_for( + page: u64, + pages: u64, + base: &str, + params: &[(&str, &str)], +) -> (Vec, Option, Option) { + pager_links(page, pages, |n| { + let number = n.to_string(); + let mut all: Vec<(&str, &str)> = params.to_vec(); + all.push(("page", number.as_str())); + list_href(base, &all) + }) } #[component] @@ -102,39 +252,28 @@ async fn audit_table(lang: Lang, rows: Vec, show_actor: bool) -> Result

(g::t(lang, K::NoEntries))

} else { for row in rows.into_iter() { - if row.ip.is_empty() && row.details.is_empty() { -
- (row.action.as_str()) - - rel_time(lang: lang, stamp: row.when.as_str()) - if show_actor { - " · " (row.actor.as_str()) - } + let count = row.count.to_string(); +
+ (row.name.as_str()) + if row.count > 1 { + "×" (count.as_str()) + } + + rel_time(lang: lang, stamp: row.when.as_str()) + if show_actor { + " · " (row.actor.as_str()) + } + if !row.target.is_empty() { " · " (row.target.as_str()) - -
- } else { -
- - (row.action.as_str()) - - rel_time(lang: lang, stamp: row.when.as_str()) - if show_actor { - " · " (row.actor.as_str()) - } - " · " (row.target.as_str()) - - -
- if !row.ip.is_empty() { -

"IP " (row.ip.as_str())

- } - if !row.details.is_empty() { -

(row.details.as_str())

- } -
-
- } + } + if !row.ip.is_empty() { + " · IP " (row.ip.as_str()) + } + if !row.details_inline.is_empty() { + " · " (row.details_inline.as_str()) + } +
+
} } }) @@ -148,8 +287,11 @@ async fn admin_audit_view( actor: String, notice: Option, rows: Vec, - older_href: Option, + page: u64, + pages: u64, + nav: (Vec, Option, Option), ) -> Result { + let (links, prev, next) = nav; let sub = vec![SubPart::text(g::t(lang, K::AuditIntro))]; Ok(view! { head(title: g::t(lang, K::AuditLog), sub: sub) @@ -166,7 +308,7 @@ async fn admin_audit_view( @@ -176,11 +318,7 @@ async fn admin_audit_view(

(message.as_str())

} audit_table(lang: lang, rows: rows, show_actor: true) - if let Some(href) = older_href { - - } + pager(page: page, pages: pages, links: links, prev: prev, next: next, lang: lang)
}) } @@ -188,19 +326,26 @@ async fn admin_audit_view( #[component] async fn own_log_view( lang: Lang, + items: Vec, rows: Vec, - older_href: Option, + page: u64, + pages: u64, + nav: (Vec, Option, Option), ) -> Result { - let sub = vec![SubPart::text(g::t(lang, K::OwnLogIntro))]; + let (links, prev, next) = nav; + let sub = vec![SubPart::text(security_sub(lang))]; Ok(view! { - head(title: g::t(lang, K::SecurityLogTitle), sub: sub) -
- audit_table(lang: lang, rows: rows, show_actor: false) - if let Some(href) = older_href { - - } + head(title: i18n::t(lang, i18n::Key::Security), sub: sub) +
+ rail(label: i18n::t(lang, i18n::Key::Security), items: items) +
+
+

(g::t(lang, K::SecurityLogTitle))

+

(g::t(lang, K::OwnLogIntro))

+ audit_table(lang: lang, rows: rows, show_actor: false) +
+ pager(page: page, pages: pages, links: links, prev: prev, next: next, lang: lang) +
}) } @@ -229,30 +374,26 @@ async fn admin_audit_page(cx: &Cx) -> Result { } } // An unknown action or actor matches nothing, so the notice explains the empty table. - let (entries, next) = if notice.is_some() { - (Vec::new(), None) + let (entries, page, pages) = if notice.is_some() { + (Vec::new(), 1, 1) } else { - fetch_page(store, &filter, query.before.as_deref(), ADMIN_PAGE_SIZE).await? + fetch_page(store, &filter, requested_page(&query), ADMIN_PAGE_SIZE).await? }; - let rows: Vec = entries.iter().map(|entry| row_view(entry, lang)).collect(); - let older_href = next.map(|cursor| { - list_href( - "/admin/audit", - &[ - ("action", action.as_str()), - ("actor", actor.as_str()), - ("before", cursor.as_str()), - ], - ) - }); + let rows = fold_rows(&entries, lang); + let nav = nav_for( + page, + pages, + "/admin/audit", + &[("action", action.as_str()), ("actor", actor.as_str())], + ); let live = list_href( "/admin/audit/events", &[("action", action.as_str()), ("actor", actor.as_str())], ); let title = g::t(lang, K::AuditLog); Ok(view! { - shell(title: title, viewer: Some(&viewer), admin_audit_view(lang: lang, live: live, action: action, actor: actor, notice: notice, rows: rows, older_href: older_href)) + shell(title: title, viewer: Some(&viewer), admin_audit_view(lang: lang, live: live, action: action, actor: actor, notice: notice, rows: rows, page: page, pages: pages, nav: nav)) }) } @@ -272,7 +413,7 @@ async fn first_page_fingerprint(store: &Store, action: &str, actor: &str) -> Res None => return Ok(String::new()), } } - let (entries, _) = fetch_page(store, &filter, None, ADMIN_PAGE_SIZE).await?; + let (entries, _, _) = fetch_page(store, &filter, 1, ADMIN_PAGE_SIZE).await?; Ok(entries .iter() .map(|entry| entry.id.as_str()) @@ -307,15 +448,15 @@ async fn own_log_page(cx: &Cx) -> Result { involving_user: Some(viewer.0.id.clone()), ..Default::default() }; - let (entries, next) = - fetch_page(store, &filter, query.before.as_deref(), OWN_PAGE_SIZE).await?; + let (entries, page, pages) = + fetch_page(store, &filter, requested_page(&query), OWN_PAGE_SIZE).await?; - let rows: Vec = entries.iter().map(|entry| row_view(entry, lang)).collect(); - let older_href = - next.map(|cursor| list_href("/settings/security/log", &[("before", cursor.as_str())])); + let rows = fold_rows(&entries, lang); + let nav = nav_for(page, pages, "/settings/security/log", &[]); + let items = security_rail_for(app_context::(cx), lang, &viewer, "log").await?; let title = g::t(lang, K::SecurityLogTitle); Ok(view! { - shell(title: title, viewer: Some(&viewer), own_log_view(lang: lang, rows: rows, older_href: older_href)) + shell(title: title, viewer: Some(&viewer), own_log_view(lang: lang, items: items, rows: rows, page: page, pages: pages, nav: nav)) }) } @@ -477,6 +618,6 @@ mod tests { let row = row_view(&entry, Lang::En); assert_eq!(row.actor, "anonymous"); assert_eq!(row.target, "mallory"); - assert_eq!(row.details, ""); + assert_eq!(row.details_inline, ""); } } diff --git a/crates/forge-web/src/pages/branches.rs b/crates/forge-web/src/pages/branches.rs index 1e07353..51c7132 100644 --- a/crates/forge-web/src/pages/branches.rs +++ b/crates/forge-web/src/pages/branches.rs @@ -143,36 +143,31 @@ async fn branch_table( Ok(view! {
for row in rows.into_iter() { -
- - (row.name.as_str()) - if row.is_default { - (g::t(lang, K::DefaultBadge)) - } - (row.author.as_str()) " · " - if let Some(counts) = row.counts { - " · " (counts.as_str()) - } else if row.up_to_date { - " · " (b::t(lang, b::K::UpToDate)) - } - - -
+
+ (row.name.as_str()) + if row.is_default { + (g::t(lang, K::DefaultBadge)) + } + if let Some(last) = row.last { -

commit_line(subject: last.summary.clone())

+ commit_line(subject: last.summary.clone()) " · " + } + (row.author.as_str()) " · " + if let Some(counts) = row.counts { + " · " (counts.as_str()) + } else if row.up_to_date { + " · " (b::t(lang, b::K::UpToDate)) } -
- if let Some(pr) = row.pr_href { - (b::t(lang, b::K::NewPr)) - } - if can_delete && !row.is_default { - confirm_act(lang: lang, label: b::t(lang, b::K::DeleteBranch), action: delete_action.as_str(), csrf: csrf.as_str(), - fields: vec![("name".to_owned(), row.name.clone()), ("oid".to_owned(), row.oid.clone())], - note: Some(b::t(lang, b::K::DeleteConfirm).to_owned())) - } -
-
-
+ + if let Some(pr) = row.pr_href { + (b::t(lang, b::K::NewPr)) + } + if can_delete && !row.is_default { + confirm_act(lang: lang, label: b::t(lang, b::K::DeleteBranch), action: delete_action.as_str(), csrf: csrf.as_str(), + fields: vec![("name".to_owned(), row.name.clone()), ("oid".to_owned(), row.oid.clone())], + note: Some(b::t(lang, b::K::DeleteConfirm).to_owned())) + } +
}
}) diff --git a/crates/forge-web/src/pages/ci_job.rs b/crates/forge-web/src/pages/ci_job.rs index aa21089..2134e2b 100644 --- a/crates/forge-web/src/pages/ci_job.rs +++ b/crates/forge-web/src/pages/ci_job.rs @@ -449,7 +449,7 @@ async fn job_body( }

- (g::t(lang, K::RunNumber)) " " (job.run_number) + (g::t(lang, K::RunNumber))(job.run_number) (job.state.as_str()) if !job.runner.is_empty() { @@ -501,13 +501,10 @@ async fn job_body( }

(log.as_str())
if !artifacts.is_empty() { -
+

(g::t(lang, K::Artifacts))

for artifact in artifacts.iter() { -
- (artifact.name.as_str()) - (artifact.size.as_str()) -
+ (artifact.name.as_str()) " " (artifact.size.as_str()) }
} @@ -614,8 +611,10 @@ async fn job_page(cx: &Cx) -> Result { let dock_owner = ctx.repo.owner_name.clone(); let dock_repo = ctx.repo.name.clone(); let page_title = format!("{title} \u{b7} CI \u{b7} {}", view.name); + // The path bar shows the run the job belongs to, between CI and the job. + let parents = vec![(format!("#{}", view.run_number), view.run_href.clone())]; Ok(view! { - shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(), + shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(), parents: parents, job_body(head: head, lang: lang, job: view, log: log, log_offset: log_offset.to_string(), first_line: first_line.to_string(), truncated: truncated, artifacts: artifacts, live: live, owner: dock_owner, repo: dock_repo, bars: bars)) }) diff --git a/crates/forge-web/src/pages/merge_queue.rs b/crates/forge-web/src/pages/merge_queue.rs index ead3855..4004fa8 100644 --- a/crates/forge-web/src/pages/merge_queue.rs +++ b/crates/forge-web/src/pages/merge_queue.rs @@ -383,32 +383,28 @@ async fn queue_body( } else { for row in rows.iter() { if row.remove { -
- - "#"(row.pull_number)" "(row.pull_title.as_str()) - - if !row.position.is_empty() { - (g::t(lang, K::QueueColPosition)) " " (row.position.as_str()) " · " - } - (row.state) - " · " (row.branch.as_str()) - " · " (row.by.as_str()) - " · " rel_time(lang: lang, stamp: row.queued_at.as_str()) - " · " - if let Some(href) = row.run_href.as_ref() { - (row.run_label.as_str()) - } else { - (row.run_label.as_str()) - } - if !row.reason.is_empty() { - " · " (row.reason.as_str()) - } - - -
- confirm_act(lang: lang, label: remove_label, action: row.remove_action.as_str(), csrf: csrf.as_str(), note: Some(remove_note.clone())) -
-
+
+ "#"(row.pull_number)" "(row.pull_title.as_str()) + + if !row.position.is_empty() { + (g::t(lang, K::QueueColPosition)) " " (row.position.as_str()) " · " + } + (row.state) + " · " (row.branch.as_str()) + " · " (row.by.as_str()) + " · " rel_time(lang: lang, stamp: row.queued_at.as_str()) + " · " + if let Some(href) = row.run_href.as_ref() { + (row.run_label.as_str()) + } else { + (row.run_label.as_str()) + } + if !row.reason.is_empty() { + " · " (row.reason.as_str()) + } + + confirm_act(lang: lang, label: remove_label, action: row.remove_action.as_str(), csrf: csrf.as_str(), note: Some(remove_note.clone())) +
} else {
"#"(row.pull_number)" "(row.pull_title.as_str()) diff --git a/crates/forge-web/src/pages/packages_oci.rs b/crates/forge-web/src/pages/packages_oci.rs index fc3f531..f777a17 100644 --- a/crates/forge-web/src/pages/packages_oci.rs +++ b/crates/forge-web/src/pages/packages_oci.rs @@ -151,22 +151,15 @@ pub async fn oci_package_view(page: OciPage) -> Result { if has_tags {
for (tag, short, full, size, created) in rows.iter() { -
- - (tag.as_str()) - (short.as_str()) " · " (size.as_str()) " · " rel_time(lang: lang, stamp: created.as_str()) - -
- (full.as_str()) - if can_delete { -
- confirm_act(lang: lang, label: pk::t(lang, K::DeleteTag), action: delete_action.as_str(), csrf: csrf.as_str(), - fields: vec![("package".to_owned(), package.name.clone()), ("tag".to_owned(), tag.clone())], - note: Some(pk::t(lang, K::DeleteTagMessage).to_owned())) -
- } -
-
+
+ (tag.as_str()) + (short.as_str()) " · " (size.as_str()) " · " rel_time(lang: lang, stamp: created.as_str()) " · " (full.as_str()) + if can_delete { + confirm_act(lang: lang, label: pk::t(lang, K::DeleteTag), action: delete_action.as_str(), csrf: csrf.as_str(), + fields: vec![("package".to_owned(), package.name.clone()), ("tag".to_owned(), tag.clone())], + note: Some(pk::t(lang, K::DeleteTagMessage).to_owned())) + } +
}
} else { diff --git a/crates/forge-web/src/pages/palette.rs b/crates/forge-web/src/pages/palette.rs index 85ae08e..7003c67 100644 --- a/crates/forge-web/src/pages/palette.rs +++ b/crates/forge-web/src/pages/palette.rs @@ -77,10 +77,6 @@ const SETTINGS_TERMS: &[(&str, &[&str])] = &[ "/settings/tokens", &["API", "PAT", "Personal access token", "Erişim belirteci"], ), - ( - "/settings/sessions", - &["Devices", "Cihazlar", "Sign out", "Logged in", "Oturumlar"], - ), ( "/settings/security", &[ @@ -101,6 +97,12 @@ const SETTINGS_TERMS: &[(&str, &[&str])] = &[ "Delete account", "Hesabı sil", "Security log", + "Sessions", + "Devices", + "Cihazlar", + "Sign out", + "Logged in", + "Oturumlar", ], ), ( @@ -224,7 +226,9 @@ fn term_in_lang(term: &str, lang: Lang) -> bool { return true; } let turkish = term.chars().any(|c| "çğıöşüÇĞİÖŞÜ".contains(c)) - || TURKISH_WORDS.iter().any(|word| word.eq_ignore_ascii_case(term)); + || TURKISH_WORDS + .iter() + .any(|word| word.eq_ignore_ascii_case(term)); turkish == matches!(lang, Lang::Tr) } diff --git a/crates/forge-web/src/pages/refs.rs b/crates/forge-web/src/pages/refs.rs index bf78d3e..690ae28 100644 --- a/crates/forge-web/src/pages/refs.rs +++ b/crates/forge-web/src/pages/refs.rs @@ -114,18 +114,13 @@ async fn refs_table(rows: Vec, lang: Lang) -> Result {
for row in rows.into_iter() { if let Some(last) = row.last { -
- - (row.name) - if row.is_default { - (g::t(lang, K::DefaultBadge)) - } - - - -
+
+ (row.name) + if row.is_default { + (g::t(lang, K::DefaultBadge)) + } + commit_line(subject: last.summary.clone()) " · " +
} else {
(row.name) diff --git a/crates/forge-web/src/pages/repo.rs b/crates/forge-web/src/pages/repo.rs index 60123ae..4a3fb98 100644 --- a/crates/forge-web/src/pages/repo.rs +++ b/crates/forge-web/src/pages/repo.rs @@ -34,9 +34,7 @@ use crate::pages::tree::{ use crate::state::AppState; use crate::views::parts::{SubPart, head_sub}; use crate::views::repo_list::badge_class; -use crate::views::{ - now_unix, ref_selector, relative_time, repo_href, repo_tabs, shell, -}; +use crate::views::{now_unix, ref_selector, relative_time, repo_href, repo_tabs, shell}; path_param!(owner); path_param!(repo); @@ -63,7 +61,7 @@ pub fn ssh_clone_url(config: &Config, owner: &str, name: &str) -> String { } /// The title a repo page shows when it gives none: the tab it is on. -fn tab_title(lang: Lang, active: &str, repo: &str) -> String { +pub(crate) fn tab_title(lang: Lang, active: &str, repo: &str) -> String { match active { "issues" => g::t(lang, K::TabIssues).to_owned(), "pulls" => g::t(lang, K::TabPulls).to_owned(), diff --git a/crates/forge-web/src/pages/repo_secrets.rs b/crates/forge-web/src/pages/repo_secrets.rs index a6feaf6..c65866f 100644 --- a/crates/forge-web/src/pages/repo_secrets.rs +++ b/crates/forge-web/src/pages/repo_secrets.rs @@ -241,19 +241,13 @@ async fn secrets_body( rel_time(lang: lang, stamp: row.updated_at.as_str())
} else { -
- - (row.name.as_str()) - rel_time(lang: lang, stamp: row.updated_at.as_str()) - -
-
- confirm_act(lang: lang, label: g::t(lang, K::Delete), action: delete_action.as_str(), csrf: csrf.as_str(), - fields: vec![("name".to_owned(), row.name.clone())], - note: Some(passkeys::s(lang, "Jobs that use it fail until it is set again.", "Onu kullanan işler, yeniden ayarlanana kadar başarısız olur.").to_owned())) -
-
-
+
+ (row.name.as_str()) + rel_time(lang: lang, stamp: row.updated_at.as_str()) + confirm_act(lang: lang, label: g::t(lang, K::Delete), action: delete_action.as_str(), csrf: csrf.as_str(), + fields: vec![("name".to_owned(), row.name.clone())], + note: Some(passkeys::s(lang, "Jobs that use it fail until it is set again.", "Onu kullanan işler, yeniden ayarlanana kadar başarısız olur.").to_owned())) +
} }
diff --git a/crates/forge-web/src/pages/repo_security.rs b/crates/forge-web/src/pages/repo_security.rs index aa68291..8ad0af9 100644 --- a/crates/forge-web/src/pages/repo_security.rs +++ b/crates/forge-web/src/pages/repo_security.rs @@ -136,24 +136,17 @@ async fn security_body( }
for row in rows.iter() { -
- - (row.advisory.as_str()) - (row.package.as_str()) " " (row.version.as_str()) " · " (row.severity.as_str()) " · " (row.state_text) " · " rel_time(lang: lang, stamp: row.created_at.as_str()) - -
-

(crate::pages::passkeys::s(lang, "Details on osv.dev", "osv.dev'de ayrıntılar"))

-

(row.summary.as_str())

-
- if row.open { - post_act(label: g::t(lang, K::Dismiss), action: row.dismiss_action.as_str(), csrf: csrf.as_str(), fields: row.fields.clone()) - } - if row.dismissed { - post_act(label: g::t(lang, K::Reopen), action: row.reopen_action.as_str(), csrf: csrf.as_str(), fields: row.fields.clone()) - } -
-
-
+
+ (row.advisory.as_str()) + (row.package.as_str()) " " (row.version.as_str()) " · " (row.severity.as_str()) " · " (row.state_text) " · " rel_time(lang: lang, stamp: row.created_at.as_str()) + (crate::pages::passkeys::s(lang, "osv.dev", "osv.dev")) + if row.open { + post_act(label: g::t(lang, K::Dismiss), action: row.dismiss_action.as_str(), csrf: csrf.as_str(), fields: row.fields.clone()) + } + if row.dismissed { + post_act(label: g::t(lang, K::Reopen), action: row.reopen_action.as_str(), csrf: csrf.as_str(), fields: row.fields.clone()) + } +
}
diff --git a/crates/forge-web/src/pages/settings_appearance.rs b/crates/forge-web/src/pages/settings_appearance.rs index 139bef6..b874851 100644 --- a/crates/forge-web/src/pages/settings_appearance.rs +++ b/crates/forge-web/src/pages/settings_appearance.rs @@ -345,7 +345,7 @@ async fn colour_row(row: ColourRow) -> Result {
@@ -735,9 +735,7 @@ mod tests { "base: empty" ); - for id in [ - "sage", "spark", "ocean", "plum", "rose", "gold", "ember", "hue-0", "hue-359", - ] { + for id in ["sage", "ocean", "plum", "rose", "ember", "hue-0", "hue-359"] { assert_eq!( accent_choice(Lang::En, Some(id), "sage").unwrap(), id, @@ -748,9 +746,7 @@ mod tests { "accent upper case {id}" ); } - for id in [ - "fern", "spark", "graphite", "dusk", "ink", "anvil", "hue-120", - ] { + for id in ["fern", "graphite", "dusk", "ink", "anvil", "hue-120"] { assert_eq!( base_choice(Lang::Tr, Some(id), "fern").unwrap(), id, @@ -766,6 +762,8 @@ mod tests { "teal", "moss", "terracotta", + "spark", + "gold", "hue-360", "hue-07", "hue-", @@ -782,6 +780,7 @@ mod tests { "blush", "pine", "slate-blue", + "spark", "hue-360", "hue-07", ] { diff --git a/crates/forge-web/src/pages/settings_gpg.rs b/crates/forge-web/src/pages/settings_gpg.rs index 45d0d3d..c035c83 100644 --- a/crates/forge-web/src/pages/settings_gpg.rs +++ b/crates/forge-web/src/pages/settings_gpg.rs @@ -14,10 +14,10 @@ use topcoat::view::{View, component, view}; use crate::audit::{self, Actor, Target}; use crate::auth::{require_csrf, require_user}; use crate::i18n::{self, Key, Lang, t}; -use crate::signatures; -use crate::state::AppState; use crate::pages::passkeys::s; use crate::pages::settings_keys::{AddQuery, KeyKind, KeysDraft, keys_page_view}; +use crate::signatures; +use crate::state::AppState; use crate::views::parts::confirm_act; use crate::views::{added_status, alert, user_facing_message}; @@ -75,18 +75,11 @@ pub(crate) async fn gpg_section(

(t(lang, Key::NoGpgKeys))

} for key in keys.into_iter() { -
- - (key.emails.join(", ")) - added_status(lang: lang, added: Some(key.created_at.as_str()), used: None) - -
- (key.fingerprint.clone()) -
- confirm_act(lang: lang, label: t(lang, Key::Delete), action: "/settings/gpg/delete", csrf: csrf, fields: vec![("id".to_owned(), key.id.clone())]) -
-
-
+
+ (key.emails.join(", ")) + (key.fingerprint.clone()) " · " added_status(lang: lang, added: Some(key.created_at.as_str()), used: None) + confirm_act(lang: lang, label: t(lang, Key::Delete), action: "/settings/gpg/delete", csrf: csrf, fields: vec![("id".to_owned(), key.id.clone())]) +
} }) } diff --git a/crates/forge-web/src/pages/settings_keys.rs b/crates/forge-web/src/pages/settings_keys.rs index cfa7d88..5452509 100644 --- a/crates/forge-web/src/pages/settings_keys.rs +++ b/crates/forge-web/src/pages/settings_keys.rs @@ -15,10 +15,10 @@ use topcoat::view::{View, component, view}; use crate::audit::{self, Actor, Target}; use crate::auth::{require_csrf, require_user}; use crate::i18n::{self, Key, Lang, t, unsupported_key_type}; -use crate::state::AppState; +use crate::pages::passkeys::s; use crate::pages::settings_gpg::gpg_section; use crate::pages::settings_tokens::tokens_section; -use crate::pages::passkeys::s; +use crate::state::AppState; use crate::views::parts::{RailItem, SubPart, confirm_act, head, rail}; use crate::views::{added_status, alert, shell, user_facing_message}; @@ -189,8 +189,16 @@ impl KeyKind { fn about(self, lang: Lang) -> &'static str { match self { KeyKind::Ssh => s(lang, "Push and pull over SSH", "SSH ile gönder ve çek"), - KeyKind::Gpg => s(lang, "Verify the commits you sign", "İmzaladığın commit'leri doğrula"), - KeyKind::Tokens => s(lang, "Sign in from the command line and from scripts", "Komut satırından ve betiklerden giriş yap"), + KeyKind::Gpg => s( + lang, + "Verify the commits you sign", + "İmzaladığın commit'leri doğrula", + ), + KeyKind::Tokens => s( + lang, + "Sign in from the command line and from scripts", + "Komut satırından ve betiklerden giriş yap", + ), } } } @@ -237,8 +245,10 @@ pub(crate) async fn keys_page_view( || draft.ssh_error.is_some() || draft.gpg_error.is_some() || draft.token_error.is_some(); + // The path bar names the Keys tab between Settings and the kind, as every tab's page does. + let parents = vec![(pk_title(lang).to_owned(), "/settings/keys".to_owned())]; Ok(view! { - shell(title: kind.title(lang), viewer: Some(viewer), + shell(title: kind.title(lang), viewer: Some(viewer), parents: parents, head(title: kind.title(lang), sub: sub, (kind.add_label(lang)) ) @@ -308,19 +318,11 @@ async fn ssh_section(

(t(lang, Key::NoSshKeys))

} for key in keys.into_iter() { -
- - (key.title.clone()) - (key.fingerprint.chars().take(15).collect::()) - added_status(lang: lang, added: Some(key.created_at.as_str()), used: key.last_used_at.as_deref()) - -
- (key.algorithm.clone()) " " (key.fingerprint.clone()) -
- confirm_act(lang: lang, label: t(lang, Key::Delete), action: "/settings/keys/delete", csrf: csrf, fields: vec![("id".to_owned(), key.id.clone())]) -
-
-
+
+ (key.title.clone()) + (key.algorithm.clone()) " " (key.fingerprint.clone()) " · " added_status(lang: lang, added: Some(key.created_at.as_str()), used: key.last_used_at.as_deref()) + confirm_act(lang: lang, label: t(lang, Key::Delete), action: "/settings/keys/delete", csrf: csrf, fields: vec![("id".to_owned(), key.id.clone())]) +
} }) } diff --git a/crates/forge-web/src/pages/settings_notifications.rs b/crates/forge-web/src/pages/settings_notifications.rs index 025c447..68137a6 100644 --- a/crates/forge-web/src/pages/settings_notifications.rs +++ b/crates/forge-web/src/pages/settings_notifications.rs @@ -126,24 +126,17 @@ async fn notifications_body(page: NotificationsPage) -> Result {

(push_text::t(lang, push_text::K::DevicesEmpty))

} for device in devices.into_iter() { -
- - (device.agent_label.as_str()) - (push_text::added_label(lang)) " " rel_time(lang: lang, stamp: device.created_at.as_str()) - -
-

- if let Some(stamp) = device.last_success_at.as_deref() { - (push_text::last_delivered_label(lang)) " " rel_time(lang: lang, stamp: stamp) - } else { - (push_text::t(lang, push_text::K::NeverDelivered)) - } -

-
- confirm_act(lang: lang, label: push_text::t(lang, push_text::K::RemoveDevice), action: "/settings/notifications/push/remove", csrf: csrf.as_str(), fields: vec![("id".to_owned(), device.id.clone())]) -
-
-
+
+ (device.agent_label.as_str()) + (push_text::added_label(lang)) " " rel_time(lang: lang, stamp: device.created_at.as_str()) " · " + if let Some(stamp) = device.last_success_at.as_deref() { + (push_text::last_delivered_label(lang)) " " rel_time(lang: lang, stamp: stamp) + } else { + (push_text::t(lang, push_text::K::NeverDelivered)) + } + + confirm_act(lang: lang, label: push_text::t(lang, push_text::K::RemoveDevice), action: "/settings/notifications/push/remove", csrf: csrf.as_str(), fields: vec![("id".to_owned(), device.id.clone())]) +
}
diff --git a/crates/forge-web/src/pages/settings_security.rs b/crates/forge-web/src/pages/settings_security.rs index 8f2bcc7..408fcfe 100644 --- a/crates/forge-web/src/pages/settings_security.rs +++ b/crates/forge-web/src/pages/settings_security.rs @@ -26,9 +26,10 @@ use crate::i18n::packages::{self as pk, K as PK}; use crate::i18n::releases_ci::{self as rc, K as RC}; use crate::i18n::{self, Key, Lang, password_too_long, password_too_short, t}; use crate::pages::passkeys::{PasskeyPanel, build_panel, passkeys_panel, s}; +use crate::pages::settings_sessions::session_label; use crate::state::AppState; use crate::throttle::{self, LOGIN_USER_LIMIT, TWO_FACTOR_USER_LIMIT}; -use crate::views::parts::{RailItem, SubPart, head, post_act, rail, reveal}; +use crate::views::parts::{RailItem, SubPart, confirm_act, head, post_act, rail, reveal}; use crate::views::{added_status, alert, rel_time, shell, user_facing_message}; /// Shortest and longest new passwords, in characters. @@ -186,12 +187,106 @@ struct SecurityPage { passkeys: PasskeyPanel, /// Repositories still owned by the user. Deletion is refused while there are any. owned_repos: Vec, - /// Web sessions open on the account, the count the Sessions topic shows. - session_count: usize, + /// Web sessions open on the account, listed by the Sessions topic. + sessions: Vec, + /// The id of the session that is viewing the page. + current_session_id: String, /// The topic asked for in the address, when no error or notice picks one. part: Option, } +/// The rail's kinds of security, one per topic. `active` names the topic that is shown, or +/// "log" for the security log page, which the last item opens. +pub(crate) fn security_rail_items( + lang: Lang, + active: &str, + two_factor_on: bool, + passkey_count: usize, + session_count: usize, +) -> Vec { + let two_factor_val = if two_factor_on { + t(lang, Key::PillOn) + } else { + t(lang, Key::PillOff) + }; + vec![ + RailItem { + name: t(lang, Key::Password).to_owned(), + val: String::new(), + href: "/settings/security?part=password".to_owned(), + current: active == "password", + }, + RailItem { + name: t(lang, Key::Email).to_owned(), + val: String::new(), + href: "/settings/security?part=email".to_owned(), + current: active == "email", + }, + RailItem { + name: t(lang, Key::TwoFactorAuth).to_owned(), + val: two_factor_val.to_owned(), + href: "/settings/security?part=two-factor".to_owned(), + current: active == "two-factor", + }, + RailItem { + name: s(lang, "Passkeys", "Geçiş anahtarları").to_owned(), + val: passkey_count.to_string(), + href: "/settings/security?part=passkeys".to_owned(), + current: active == "passkeys", + }, + RailItem { + name: t(lang, Key::Sessions).to_owned(), + val: session_count.to_string(), + href: "/settings/security?part=sessions".to_owned(), + current: active == "sessions", + }, + RailItem { + name: t(lang, Key::SecurityLog).to_owned(), + val: String::new(), + href: "/settings/security/log".to_owned(), + current: active == "log", + }, + RailItem { + name: t(lang, Key::DangerZone).to_owned(), + val: String::new(), + href: "/settings/security?part=danger".to_owned(), + current: active == "danger", + }, + ] +} + +/// The Security tab's head line, shared by the topics and the security log. +pub(crate) fn security_sub(lang: Lang) -> &'static str { + s( + lang, + "Sign-in, email, two-factor, passkeys and sessions", + "Giriş, e-posta, iki adımlı doğrulama, geçiş anahtarları ve oturumlar", + ) +} + +/// The rail for a page outside the topics (the security log), with live counts. +pub(crate) async fn security_rail_for( + state: &AppState, + lang: Lang, + viewer: &(User, Session), + active: &str, +) -> forge_core::Result> { + let two_factor_on = state + .store + .totp_state(&viewer.0.id) + .await? + .is_some_and(|totp| totp.enabled); + let passkey_count = state.store.list_passkeys(&viewer.0.id).await?.len(); + let session_count = state.store.list_sessions(&viewer.0.id).await?.len(); + Ok(security_rail_items( + lang, + active, + two_factor_on, + passkey_count, + session_count, + )) +} + #[component] async fn security_body(page: SecurityPage, csrf: &str) -> Result { let SecurityPage { @@ -213,11 +308,17 @@ async fn security_body(page: SecurityPage, csrf: &str) -> Result { delete_error, passkeys, owned_repos, - session_count, + sessions, + current_session_id, part, } = page; let two_factor_on = two_factor.is_some(); let passkey_count = passkeys.items.len(); + let session_count = sessions.len(); + let others = sessions + .iter() + .filter(|session| session.id != current_session_id) + .count(); let pending_set = pending.is_some(); let password_open = password_error.is_some(); let email_open = email_error.is_some(); @@ -234,19 +335,25 @@ async fn security_body(page: SecurityPage, csrf: &str) -> Result { let disable_open = disable_error.is_some(); let delete_open = delete_error.is_some(); let delete_blocked = !owned_repos.is_empty(); - let sessions_line = format!("{session_count} {}", s(lang, "active", "etkin")); - let two_factor_val = if two_factor_on { - t(lang, Key::PillOn) - } else { - t(lang, Key::PillOff) - }; // One topic shows at a time: the one with an error or fresh codes, else the one asked for. - const TOPICS: [&str; 6] = ["password", "email", "two-factor", "passkeys", "sessions", "danger"]; + const TOPICS: [&str; 6] = [ + "password", + "email", + "two-factor", + "passkeys", + "sessions", + "danger", + ]; let active: &'static str = if password_open { "password" } else if email_open { "email" - } else if regenerate_open || disable_open || setup_error.is_some() || codes.is_some() || (pending_set && part.is_none()) { + } else if regenerate_open + || disable_open + || setup_error.is_some() + || codes.is_some() + || (pending_set && part.is_none()) + { "two-factor" } else if delete_open { "danger" @@ -255,47 +362,9 @@ async fn security_body(page: SecurityPage, csrf: &str) -> Result { .and_then(|asked| TOPICS.into_iter().find(|topic| *topic == asked)) .unwrap_or("password") }; - // The kinds of security, one per topic. Each shows its topic in the sheet. - let items: Vec = vec![ - RailItem { - name: t(lang, Key::Password).to_owned(), - val: String::new(), - href: "?part=password".to_owned(), - current: active == "password", - }, - RailItem { - name: t(lang, Key::Email).to_owned(), - val: String::new(), - href: "?part=email".to_owned(), - current: active == "email", - }, - RailItem { - name: t(lang, Key::TwoFactorAuth).to_owned(), - val: two_factor_val.to_owned(), - href: "?part=two-factor".to_owned(), - current: active == "two-factor", - }, - RailItem { - name: s(lang, "Passkeys", "Geçiş anahtarları").to_owned(), - val: passkey_count.to_string(), - href: "?part=passkeys".to_owned(), - current: active == "passkeys", - }, - RailItem { - name: t(lang, Key::Sessions).to_owned(), - val: session_count.to_string(), - href: "?part=sessions".to_owned(), - current: active == "sessions", - }, - RailItem { - name: t(lang, Key::DangerZone).to_owned(), - val: String::new(), - href: "?part=danger".to_owned(), - current: active == "danger", - }, - ]; + let items = security_rail_items(lang, active, two_factor_on, passkey_count, session_count); Ok(view! { - head(title: t(lang, Key::Security), sub: vec![SubPart::text(s(lang, "Sign-in, email, two-factor, passkeys and sessions", "Giriş, e-posta, iki adımlı doğrulama, geçiş anahtarları ve oturumlar"))]) + head(title: t(lang, Key::Security), sub: vec![SubPart::text(security_sub(lang))]) if let Some(message) = notice {

(message)

} @@ -307,30 +376,26 @@ async fn security_body(page: SecurityPage, csrf: &str) -> Result { if let Some(stamp) = password_changed {

(i18n::last_changed_label(lang)) " " rel_time(lang: lang, stamp: stamp.as_str())

} -
- reveal(label: t(lang, Key::ChangeAction), open: password_open, - if let Some(message) = password_error { - alert(message: message.as_str()) - } -
- -
- - -
-
- - -

(t(lang, Key::NewPasswordHint))

-
-
- - -
- -
- ) -
+ if let Some(message) = password_error { + alert(message: message.as_str()) + } +
+ +
+ + +
+
+ + +

(t(lang, Key::NewPasswordHint))

+
+
+ + +
+ +

(t(lang, Key::Email))

@@ -339,28 +404,26 @@ async fn security_body(page: SecurityPage, csrf: &str) -> Result { } else {

(stored_email.as_str()) (" · ")(email_status.as_str()) if let Some(stamp) = email_sent { " " rel_time(lang: lang, stamp: stamp.as_str()) }

} -
- reveal(label: t(lang, Key::ChangeAction), open: email_open, - if let Some(message) = email_error { - alert(message: message.as_str()) - } -
- -
- - -
-
- - -
- -
- ) - if show_resend { + if let Some(message) = email_error { + alert(message: message.as_str()) + } +
+ +
+ + +
+
+ + +
+ +
+ if show_resend { +
post_act(label: t(lang, Key::VerifyResend), action: "/settings/security/email/resend", csrf: csrf) - } -
+
+ }

(t(lang, Key::TwoFactorAuth))

@@ -458,12 +521,28 @@ async fn security_body(page: SecurityPage, csrf: &str) -> Result { passkeys_panel(lang: lang, csrf: csrf, panel: passkeys)

(t(lang, Key::Sessions))

-

(sessions_line.as_str())

-

(t(lang, Key::SecurityLog))(t(lang, Key::SecurityLogRest))

- + if others > 0 { +
+ confirm_act(lang: lang, label: t(lang, Key::RevokeAllOthers), action: "/settings/sessions/revoke-others", csrf: csrf, note: Some(s(lang, "Every other browser is signed out at once. This one stays signed in.", "Diğer tüm tarayıcılarda oturum hemen kapanır. Bu tarayıcıda oturum açık kalır.").to_owned())) +
+ } + for session in sessions.into_iter() { +
+ (session_label(lang, &session)) + + if session.id == current_session_id { + (t(lang, Key::ThisSession)) " · " + } + if let Some(ip) = session.last_ip.as_deref() { + (ip) " · " + } + (i18n::dated_label(lang, Key::LastSeen)) " " rel_time(lang: lang, stamp: session.last_seen.as_str()) " · " (t(lang, Key::SignedIn)) " " rel_time(lang: lang, stamp: session.created_at.as_str()) + + if session.id != current_session_id { + confirm_act(lang: lang, label: t(lang, Key::Revoke), action: "/settings/sessions/revoke", csrf: csrf, fields: vec![("id".to_owned(), session.id.clone())], note: Some(s(lang, "This browser is signed out at once.", "Bu tarayıcıda oturum hemen kapanır.").to_owned())) + } +
+ }

(t(lang, Key::DangerZone))

@@ -625,7 +704,8 @@ async fn build_page( pending, password_changed, two_factor, - session_count: state.store.list_sessions(&viewer.0.id).await?.len(), + sessions: state.store.list_sessions(&viewer.0.id).await?, + current_session_id: viewer.1.id.clone(), part: shown.part, }) } @@ -1708,7 +1788,11 @@ mod tests { assert!(page.body.contains("Added "), "{}", page.body); assert!(page.body.contains("1 of 10 recovery codes unused")); assert!(page.body.contains("Running low")); - assert!(page.body.contains("

On · "), "{}", page.body); + assert!( + page.body.contains("

On · "), + "{}", + page.body + ); let bad = format!( "csrf={CSRF}¤t_password=nope&code={}", @@ -1729,8 +1813,9 @@ mod tests { .expect("turn-off panel should stay open"); assert!( opened.contains("Turn off") - && opened.split(" String { - session - .user_agent - .as_deref() - .map_or_else(|| t(lang, Key::UnknownBrowser).to_owned(), |agent| agent_label_in(lang, agent)) +pub(crate) fn session_label(lang: Lang, session: &Session) -> String { + session.user_agent.as_deref().map_or_else( + || t(lang, Key::UnknownBrowser).to_owned(), + |agent| agent_label_in(lang, agent), + ) } -#[component] -async fn sessions_view( - lang: Lang, - csrf: &str, - current_id: &str, - sessions: Vec, -) -> Result { - let others = sessions.iter().filter(|s| s.id != current_id).count(); - Ok(view! { - head(title: t(lang, Key::Sessions), sub: vec![SubPart::text(s(lang, "Where you are signed in", "Oturum açık olduğun yerler"))]) -

- if others > 0 { -
- confirm_act(lang: lang, label: t(lang, Key::RevokeAllOthers), action: "/settings/sessions/revoke-others", csrf: csrf, note: Some(s(lang, "Every other browser is signed out at once. This one stays signed in.", "Diğer tüm tarayıcılarda oturum hemen kapanır. Bu tarayıcıda oturum açık kalır.").to_owned())) -
- } - for session in sessions.into_iter() { -
- - (session_label(lang, &session)) - - if session.id == current_id { - (t(lang, Key::ThisSession)) " · " - } - (i18n::dated_label(lang, Key::LastSeen)) " " rel_time(lang: lang, stamp: session.last_seen.as_str()) - - -
- session_details(lang: lang, csrf: csrf, session: session.clone(), current: session.id == current_id) - -
-
- } -
- }) +#[route(GET "/settings/sessions")] +async fn sessions_page(cx: &Cx) -> Result { + require_user(cx).await?; + Ok(see_other("/settings/security?part=sessions")) } -/// The facts about one session, shared by its row on the list and its detail page: the badge -/// when it is the current session, the key/value grid, and the revoke action for any other one. -#[component] -async fn session_details( - lang: Lang, - csrf: &str, - session: Session, - current: bool, -) -> Result { - let user_agent = session - .user_agent - .clone() - .unwrap_or_else(|| t(lang, Key::UnknownBrowser).to_owned()); - // Sessions from before IP recording have no sign-in address. - let sign_in_ip = session - .ip - .clone() - .unwrap_or_else(|| t(lang, Key::NotRecorded).to_owned()); - let last_ip = session - .last_ip - .clone() - .unwrap_or_else(|| t(lang, Key::NotRecorded).to_owned()); - let id = session.id.clone(); - Ok(view! { - if current { -

(t(lang, Key::ThisSession))

- } -
-
(t(lang, Key::UserAgent))
(user_agent.as_str())
-
(t(lang, Key::SignInIp))
(sign_in_ip.as_str())
-
(t(lang, Key::LastIp))
(last_ip.as_str())
-
(t(lang, Key::SignedIn))
rel_time(lang: lang, stamp: session.created_at.as_str())
-
(t(lang, Key::LastSeenAt))
rel_time(lang: lang, stamp: session.last_seen.as_str())
-
(t(lang, Key::ExpiresAt))
rel_time(lang: lang, stamp: session.expires_at.as_str())
-
- if !current { -
- confirm_act(lang: lang, label: t(lang, Key::Revoke), action: "/settings/sessions/revoke", csrf: csrf, fields: vec![("id".to_owned(), id)], note: Some(s(lang, "This browser is signed out at once.", "Bu tarayıcıda oturum hemen kapanır.").to_owned())) -
- } - }) -} - -#[component] -async fn session_detail_view( - lang: Lang, - csrf: &str, - session: Session, - current: bool, -) -> Result { - let label = session_label(lang, &session); - Ok(view! { - head(title: label.as_str()) -
- -
-

(i18n::dated_label(lang, Key::LastSeen)) " " rel_time(lang: lang, stamp: session.last_seen.as_str())

- session_details(lang: lang, csrf: csrf, session: session.clone(), current: current) -
-
- }) -} - -#[page("/settings/sessions")] -async fn sessions_page(cx: &Cx) -> Result { - let viewer = require_user(cx).await?; - let lang = i18n::lang(cx, Some(&viewer.0)); - let sessions = app_context::(cx) - .store - .list_sessions(&viewer.0.id) - .await?; - let csrf = viewer.1.csrf_token.clone(); - let current_id = viewer.1.id.clone(); - Ok(view! { - shell(title: t(lang, Key::Sessions), viewer: Some(&viewer), sessions_view(lang: lang, csrf: csrf.as_str(), current_id: current_id.as_str(), sessions: sessions)) - }) -} - -#[page("/settings/sessions/{id}")] -async fn session_page(cx: &Cx) -> Result { - let viewer = require_user(cx).await?; - let lang = i18n::lang(cx, Some(&viewer.0)); - let id = path_param_segment(cx, "id").to_owned(); - // Only the signed-in user's own sessions are shown; anything else is not found. - let sessions = app_context::(cx) - .store - .list_sessions(&viewer.0.id) - .await?; - let Some(session) = sessions.into_iter().find(|s| s.id == id) else { - return Err(not_found().into()); - }; - let current = session.id == viewer.1.id; - let csrf = viewer.1.csrf_token.clone(); - let title = session_label(lang, &session); - Ok(view! { - shell(title: title.as_str(), viewer: Some(&viewer), session_detail_view(lang: lang, csrf: csrf.as_str(), session: session, current: current)) - }) +#[route(GET "/settings/sessions/{id}")] +async fn session_page(cx: &Cx) -> Result { + require_user(cx).await?; + Ok(see_other("/settings/security?part=sessions")) } #[route(POST "/settings/sessions/revoke")] @@ -220,7 +89,7 @@ async fn sessions_revoke(cx: &Cx, Form(form): Form) -> Result) -> Result")); - assert!(html.contains("
")); - assert!(html.contains("
")); - assert!(html.contains(&format!("href=\"/settings/sessions/{}\"", current.id))); + assert!(html.contains("
")); + assert!(html.contains("This session")); } #[tokio::test] diff --git a/crates/forge-web/src/pages/settings_tokens.rs b/crates/forge-web/src/pages/settings_tokens.rs index f5ae0ad..674b204 100644 --- a/crates/forge-web/src/pages/settings_tokens.rs +++ b/crates/forge-web/src/pages/settings_tokens.rs @@ -130,18 +130,11 @@ pub(crate) async fn tokens_section(

(t(lang, Key::NoAccessTokens))

} for token in tokens.into_iter() { -
- - (token.name.clone()) - (i18n::dated_label(lang, Key::LastUsed)) " " rel_time_or_never(lang: lang, stamp: token.last_used_at.as_deref()) ", " (i18n::dated_label(lang, Key::ExpiresLabel)) " " rel_time_or_never(lang: lang, stamp: token.expires_at.as_deref()) - -
-

(i18n::dated_label(lang, Key::Created)) " " rel_time(lang: lang, stamp: token.created_at.as_str())

-
- confirm_act(lang: lang, label: t(lang, Key::Delete), action: "/settings/tokens/delete", csrf: csrf, fields: vec![("id".to_owned(), token.id.clone())], note: Some(delete_message(lang).to_owned())) -
-
-
+
+ (token.name.clone()) + (i18n::dated_label(lang, Key::LastUsed)) " " rel_time_or_never(lang: lang, stamp: token.last_used_at.as_deref()) " · " (i18n::dated_label(lang, Key::ExpiresLabel)) " " rel_time_or_never(lang: lang, stamp: token.expires_at.as_deref()) " · " (i18n::dated_label(lang, Key::Created)) " " rel_time(lang: lang, stamp: token.created_at.as_str()) + confirm_act(lang: lang, label: t(lang, Key::Delete), action: "/settings/tokens/delete", csrf: csrf, fields: vec![("id".to_owned(), token.id.clone())], note: Some(delete_message(lang).to_owned())) +
} }) } diff --git a/crates/forge-web/src/views/mod.rs b/crates/forge-web/src/views/mod.rs index 6f09491..dfb8c2a 100644 --- a/crates/forge-web/src/views/mod.rs +++ b/crates/forge-web/src/views/mod.rs @@ -149,11 +149,39 @@ fn crumb_label(part: &str) -> String { } } -/// The path bar for a request path, as `(label, href)` pairs. The root and the top-level pages -/// return no segments: their page head already shows the name, so the bar only holds its hint. A -/// repo path shows the owner, the repo and, for a `tree` or `blob` path, one segment per path -/// part. The last segment never links. Labels are decoded. -fn path_segments(path: &str, title: &str) -> Vec<(String, Option)> { +/// The word a path bar shows for the last step of a path below an item, such as `edit` or `files`. +fn step_label(lang: Lang, word: &str) -> String { + match word { + "new" => s(lang, "New", "Yeni").to_owned(), + "edit" => s(lang, "Edit", "Düzenle").to_owned(), + "history" => s(lang, "History", "Geçmiş").to_owned(), + "revisions" => s(lang, "Revisions", "Sürümler").to_owned(), + "files" => s(lang, "Files", "Dosyalar").to_owned(), + "commits" => g::t(lang, K::TabCommits).to_owned(), + other => crumb_label(other), + } +} + +/// The name of a repo section in the path bar, for a page under it. `None` for a word that is no +/// section, such as `scrub`. +fn repo_section_label(lang: Lang, kind: &str) -> Option { + match kind { + "issues" | "pulls" | "ci" | "commits" | "branches" | "tags" | "releases" + | "discussions" | "wiki" | "security" | "settings" => { + Some(crate::pages::repo::tab_title(lang, kind, "")) + } + "milestones" => Some(s(lang, "Milestones", "Kilometre taşları").to_owned()), + "labels" => Some(s(lang, "Labels", "Etiketler").to_owned()), + _ => None, + } +} + +/// The path bar for a request path, as `(label, href)` pairs: every place above the page links, +/// so a page is always one click from the one it belongs to. The root and the top-level pages +/// return no segments (their section names them). A repo path shows the owner, the repo, then for +/// a page under a section the section, the item (`#12`) and the page; a `tree` or `blob` path has +/// one segment per path part. The last segment never links. Labels are decoded. +fn path_segments(lang: Lang, path: &str, title: &str) -> Vec<(String, Option)> { let parts: Vec = path .trim_matches('/') .split('/') @@ -163,6 +191,42 @@ fn path_segments(path: &str, title: &str) -> Vec<(String, Option)> { let Some(owner) = parts.first() else { return Vec::new(); }; + // The page's own name: the part of its title after the last " · ", when there is one. + let titled = title.rsplit_once(" · ").map(|(_, last)| last.to_owned()); + match parts + .iter() + .map(String::as_str) + .collect::>() + .as_slice() + { + ["snippets", id, rest @ ..] => { + let mut segments = vec![( + cm::t(lang, CK::Snippets).to_owned(), + Some("/snippets".to_owned()), + )]; + match rest { + // A snippet's own page is named by its title. + [] => segments.push((title.to_owned(), None)), + // A page under a snippet goes back to the snippet, then names its step. The revisions + // page is titled by the snippet; the edit page by what it does. + [.., last] => { + let back = if *last == "revisions" { + title.to_owned() + } else { + s(lang, "Snippet", "Parçacık").to_owned() + }; + segments.push((back, Some(format!("/snippets/{}", enc(id))))); + segments.push((step_label(lang, last), None)); + } + } + return segments; + } + ["org", name, rest @ ..] if *name != "new" && !rest.is_empty() => { + let page = titled.unwrap_or_else(|| step_label(lang, rest[rest.len() - 1])); + return vec![((*name).to_owned(), Some(user_href(name))), (page, None)]; + } + _ => {} + } if owner.starts_with('-') || TOP_LEVEL_PAGES.contains(&owner.as_str()) { return Vec::new(); } @@ -182,27 +246,115 @@ fn path_segments(path: &str, title: &str) -> Vec<(String, Option)> { } // The repo's home: the repo name is the last segment already. [] => {} - // Titles read "owner/repo · Page": the path bar has the repo already. A page titled by - // the repo alone is named by its route. - [_, ..] => { - // A title ending in the repo plus a word ("Install · owner/repo wiki") reads by - // the part before it. + [kind, rest @ ..] => { + // Titles read "owner/repo · Page": the path bar has the repo already. A page titled by + // the repo alone is named by its route. A title ending in the repo plus a word + // ("Install · owner/repo wiki") reads by the part before it. let full = format!("{owner}/{repo}"); let mut tail = title.rsplit(" · "); let named = match tail.next() { Some(last) if last == full => None, Some(last) if last.starts_with(&format!("{full} ")) => tail.next(), last => last, + } + .map(str::to_owned); + let section = if kind == "commit" { + "commits" + } else { + kind.as_str() }; - let page = match named { - Some(page) => page.to_owned(), - None => parts[2..] - .iter() - .map(|part| crumb_label(part)) - .collect::>() - .join("/"), - }; - segments.push((page, None)); + match (repo_section_label(lang, section), rest) { + // Files at one commit, from the home page's timeline: under that commit. + (None, [oid]) if kind == "scrub" => { + let short: String = oid.chars().take(7).collect(); + segments.push(( + g::t(lang, K::TabCommits).to_owned(), + Some(repo_href(owner, repo, "commits", "")), + )); + segments.push((short, Some(repo_href(owner, repo, "commit", oid)))); + segments.push((step_label(lang, "files"), None)); + } + // Compare and search: their word, then what is compared. + (None, rest) if matches!(kind.as_str(), "compare" | "search") => { + let word = if kind == "compare" { + s(lang, "Compare", "Karşılaştır") + } else { + s(lang, "Search", "Ara") + }; + if rest.is_empty() { + segments.push((word.to_owned(), None)); + } else { + segments + .push((word.to_owned(), Some(repo_href(owner, repo, kind, "")))); + segments.push((rest.join("/"), None)); + } + } + // A section's own page, or a word that is no section: one segment. + (None, _) | (Some(_), []) => { + let page = named.unwrap_or_else(|| { + parts[2..] + .iter() + .map(|part| crumb_label(part)) + .collect::>() + .join("/") + }); + segments.push((page, None)); + } + (Some(label), rest) => { + segments.push((label, Some(repo_href(owner, repo, section, "")))); + let item = rest[0].as_str(); + let numbered = matches!(section, "issues" | "pulls" | "discussions") + && item.bytes().all(|b| b.is_ascii_digit()); + match (section, rest) { + ("ci", [runs, number]) if runs == "runs" => { + segments.push((format!("#{number}"), None)); + } + _ if numbered && rest.len() == 1 => { + segments.push((format!("#{item}"), None)); + } + _ if numbered => { + segments.push(( + format!("#{item}"), + Some(repo_href(owner, repo, section, item)), + )); + // The step, by its word: an edit history ends in an id, so its + // word is History; a comment's edit is Edit. + let step = if rest.iter().any(|part| part == "history") { + "history" + } else { + rest[rest.len() - 1].as_str() + }; + segments.push((step_label(lang, step), None)); + } + ("wiki", [dash, new]) if dash == "-" && new == "new" => { + segments.push((s(lang, "New page", "Yeni sayfa").to_owned(), None)); + } + ("wiki" | "settings", [page, more @ ..]) + if !more.is_empty() && page != "-" => + { + let page_label = match page.as_str() { + "hooks" => { + i18n::integrations::t(lang, i18n::integrations::K::Webhooks) + .to_owned() + } + other => crumb_label(other), + }; + segments.push(( + page_label, + Some(repo_href(owner, repo, section, page)), + )); + let last = more[more.len() - 1].as_str(); + segments.push((step_label(lang, last), None)); + } + _ => { + let page = named.unwrap_or_else(|| { + step_label(lang, rest[rest.len() - 1].as_str()) + }); + segments.push((page, None)); + } + } + } + } } } } @@ -398,7 +550,7 @@ async fn profile_corner(lang: Lang, corner: ProfileCorner) -> Result (profile_label) (settings_label) if corner.is_admin { (admin_label) @@ -470,6 +621,7 @@ pub async fn shell( title: &str, viewer: Option<&(User, Session)>, #[default] extra_stylesheet: Option<&str>, + #[default] parents: Vec<(String, String)>, #[default] child: Child<'_>, ) -> Result { let full_title = format!("{title} \u{b7} forge"); @@ -573,17 +725,32 @@ pub async fn shell( let palette_label = br::t(lang, br::K::PaletteOpen).to_owned(); let explore_label = t(lang, Key::Explore); // The path bar: one segment per part of the request path, the last one unlinked. - let mut segments = path_segments(uri(__cx).path(), title); + let mut segments = path_segments(lang, uri(__cx).path(), title); // A page with no place of its own in the path, such as settings, names its section and itself. + // A page below one of the section's tabs (an account under Users) names that tab too. if segments.is_empty() { if let Some(section) = §ion { let first = section.items.first().map(|item| item.href.clone()); if section.title != title { segments.push((section.title.clone(), first)); } + let path = uri(__cx).path(); + if let Some(item) = section.items.iter().find(|item| { + path.strip_prefix(item.href.as_str()) + .is_some_and(|below| below.starts_with('/')) + }) { + segments.push((item.label.to_owned(), Some(item.href.clone()))); + } } segments.push((title.to_owned(), None)); } + // Places the path does not show, such as a job's run, go just before the page itself. + if !parents.is_empty() { + let at = segments.len().saturating_sub(1); + for (offset, (label, href)) in parents.into_iter().enumerate() { + segments.insert(at + offset, (label, Some(href))); + } + } let path_attr = segments .iter() .map(|(label, _)| label.as_str()) @@ -821,7 +988,10 @@ pub fn page_width(path: &str) -> &'static str { ["settings" | "admin", ..] | ["new", ..] | ["org", "new"] | ["org", _, "settings", ..] => { "col" } - ["login" | "register" | "forgot" | "reset" | "setup" | "invite", ..] => "col", + [ + "login" | "register" | "forgot" | "reset" | "setup" | "invite", + .., + ] => "col", [_, _, section, ..] => match *section { "settings" | "new" | "edit" | "fork" | "transfer" | "rename" => "col", "tree" | "blob" | "blame" | "commit" | "compare" | "ci" | "raw" | "edit-file" @@ -973,8 +1143,16 @@ pub fn section_for(lang: Lang, path: &str) -> Option
{ let first = parts.next()?; let second = parts.next().unwrap_or(""); let (key, title, items) = match first { - "admin" => ("admin", ad::t(lang, AK::AdminArea).to_owned(), admin_items(lang)), - "settings" => ("settings", o::t(lang, OK::Settings).to_owned(), settings_items(lang)), + "admin" => ( + "admin", + ad::t(lang, AK::AdminArea).to_owned(), + admin_items(lang), + ), + "settings" => ( + "settings", + o::t(lang, OK::Settings).to_owned(), + settings_items(lang), + ), _ => return None, }; let second = match second { @@ -1619,7 +1797,7 @@ mod tests { #[test] fn path_segments_follow_the_request_path() { assert_eq!( - path_segments("/tahinli/forge/blob/main/src/main.rs", "main.rs"), + path_segments(Lang::En, "/tahinli/forge/blob/main/src/main.rs", "main.rs"), vec![ ("tahinli".to_owned(), Some("/tahinli".to_owned())), ("forge".to_owned(), Some("/tahinli/forge".to_owned())), @@ -1631,24 +1809,37 @@ mod tests { ] ); assert_eq!( - path_segments("/tahinli/forge", "tahinli/forge"), + path_segments(Lang::En, "/tahinli/forge", "tahinli/forge"), vec![ ("tahinli".to_owned(), Some("/tahinli".to_owned())), ("forge".to_owned(), None), ] ); - let (last, _) = path_segments("/tahinli/forge/issues", "tahinli/forge · Issues").remove(2); + let (last, _) = + path_segments(Lang::En, "/tahinli/forge/issues", "tahinli/forge · Issues").remove(2); assert_eq!(last, "Issues"); - let (last, _) = path_segments("/tahinli/forge/commits/main", "tahinli/forge").remove(2); - assert_eq!(last, "commits/main"); - assert!(path_segments("/explore", "Explore").is_empty()); - assert!(path_segments("/", "Home").is_empty()); + let crumbs = path_segments(Lang::En, "/tahinli/forge/commits/main", "tahinli/forge"); + assert_eq!( + crumbs[2], + ( + "Commits".to_owned(), + Some("/tahinli/forge/commits".to_owned()) + ) + ); + assert_eq!(crumbs[3], ("main".to_owned(), None)); + let crumbs = path_segments(Lang::En, "/tahinli/forge/issues/4/edit", "tahinli/forge"); + let labels: Vec<&str> = crumbs.iter().map(|(label, _)| label.as_str()).collect(); + assert_eq!(labels, ["tahinli", "forge", "Issues", "#4", "Edit"]); + assert_eq!(crumbs[3].1.as_deref(), Some("/tahinli/forge/issues/4")); + assert!(path_segments(Lang::En, "/explore", "Explore").is_empty()); + assert!(path_segments(Lang::En, "/", "Home").is_empty()); let (last, _) = path_segments( + Lang::En, "/tahinli/forge/commit/0123456789abcdef0123456789abcdef01234567", "tahinli/forge", ) - .remove(2); - assert_eq!(last, "commit/0123456"); + .remove(3); + assert_eq!(last, "0123456"); } #[test] @@ -1725,7 +1916,7 @@ mod tests { ); } - /// Renders `/settings/sessions` (a page that uses the shell) for a freshly signed-in user. + /// Renders `/settings/security` (a page that uses the shell) for a freshly signed-in user. async fn menu_html( router: &topcoat::router::Router, store: &forge_core::Store, @@ -1744,7 +1935,7 @@ mod tests { crate::test_support::create_session(store, &user.id, token, "menu-csrf").await; let req = Request::builder() .method("GET") - .uri("/settings/sessions") + .uri("/settings/security") .header("cookie", format!("__Host-{SESSION_COOKIE}={token}")) .body(Body::empty()) .expect("request"); @@ -1848,7 +2039,7 @@ mod shell_tests { &page[at..at + len + 1] } - /// The `` tag of `/settings/sessions` for a signed-in user whose stored colours are the + /// The `` tag of `/settings/security` for a signed-in user whose stored colours are the /// four ids given, in the order light accent, dark accent, light base, dark base. async fn html_tag_for_colours( router: &topcoat::router::Router, @@ -1870,7 +2061,7 @@ mod shell_tests { crate::test_support::create_session(store, &user.id, token, "colour-csrf").await; let req = Request::builder() .method("GET") - .uri("/settings/sessions") + .uri("/settings/security") .header("cookie", format!("__Host-{SESSION_COOKIE}={token}")) .body(Body::empty()) .unwrap(); @@ -1932,12 +2123,12 @@ mod shell_tests { &store, "hued", "hued-token", - ["hue-215", "hue-7", "hue-300", "spark"], + ["hue-215", "hue-7", "hue-300", "ink"], ) .await; assert!(hued.contains("data-accent-light=\"hue-215\""), "{hued}"); assert!(hued.contains("data-accent-dark=\"hue-7\""), "{hued}"); assert!(hued.contains("data-base-light=\"hue-300\""), "{hued}"); - assert!(hued.contains("data-base-dark=\"spark\""), "{hued}"); + assert!(hued.contains("data-base-dark=\"ink\""), "{hued}"); } } diff --git a/docs/ui-language.md b/docs/ui-language.md index c7800ad..4df5ad0 100644 --- a/docs/ui-language.md +++ b/docs/ui-language.md @@ -46,15 +46,20 @@ Sections never go in the rail: they go in `.tabs`. ## Rows `....` when the item -has its own page. When it opens in place: +has its own page. Otherwise the row shows everything at once: its facts in the one `.val`, joined with +" · ", and its actions right after them on the same line. A confirm opens in place of its word, on the row. ```html -
- laptopSHA256:9fK2c1Qx -
..
-
+
+ laptopSHA256:9fK2c1Qx · added 3 days ago + confirm_act(..Delete..) +
``` +`
` only for a row whose hidden part is an edit form (a rename, a role). Never a +row that opens to show facts or a single action, never a link to a page that shows the same row again: +one click to see, one to act. + Details come right after the title on one line. Nothing is pushed to the far end of a row: no `margin-left:auto`, no `justify-content:space-between`, no second column at the right. @@ -96,7 +101,11 @@ label. Errors are `alert` at the top of the form they belong to, which stays ope Every search bar is live: `data-live-search` on a real GET form's input in `.plain-search`. It sits in the tools row or above the rail's list. Filters are the rail, or `.tabs` when there are only a few. Pagers -appear only when another page exists, as one `nav.pager` row (Newer, the page, Older) under the list. An empty list is `.state` with one line and its action as `.act`. +appear only when another page exists, as one `nav.pager` row (Newer, the page, Older) under the list, on +the sheet's inset with a hairline above. A long log (the audit log) numbers its pages in the same row +(`nav.pager.pager-numbered`), the current page held like a pressed tool. An empty list is `.state` with +one line and its action as `.act`. A log reads as text: action words, then facts joined with " · ", never +raw JSON; repeats in a row fold into one line with "×N". ## Menus @@ -108,8 +117,13 @@ triangles. It never leaves the window, on a phone either. Tokens only: `--bg`, `--surface`, `--surface-2`, `--text`, `--muted`, `--border`, `--border-strong`, `--accent`, `--accent-soft`, `--bad`, `--danger-bg`, `--add-bg`, `--del-bg`. Accent marks the one live or selected -thing. Running colour is the accent. Passed is neutral. Failed is `--bad`. Cancelled is grey, never red. -Added is blue and deleted is rose. Graphs use the same set: neutral marks, accent for now. +thing. In CI, running is the accent, passed is `--ok` green and failed is `--bad`, everywhere a result +shows (ticks, step strips, timeline, history bars). `--ok` takes the accent's lightness and strength +with a green hue, so results sit with whichever accent is chosen. Cancelled is grey, never red. Added +is blue and deleted is rose. + +A colour choice offers five presets and a Custom chip (its swatch and the word), on the same columns +in every row. ## Type @@ -132,3 +146,15 @@ Turkish page shows no English, an English page no Turkish. - A setting must visibly change something, or it goes. - A phone (390px) is one column: no sideways scroll, tabs scroll inside their row. - Pages fit one screen where they can: use tabs and the rail, not stacked unrelated topics. + +## Fixed places + +- Every head on a page with tabs is one height (a 38px title line and one sub line), so the tabs and the + sheet never move when you switch tabs. +- The path bar names every place above the page as a link: section, item (`#12`), page. A page whose + parent is not in its address (a job's run) passes it to `shell(parents: ..)`. No page needs the browser's + Back button. +- A form of one field puts its submit beside the field. +- Every control has one focus ring: 2px in `--focus`, inside its own edge (`outline-offset: -2px`), so + no sheet, row or scrolling list cuts it. +- A tab's own pages sit in its rail: the Security log is a Security rail item, not a page of its own. diff --git a/style/_one.scss b/style/_one.scss index 6b6278d..1438c20 100644 --- a/style/_one.scss +++ b/style/_one.scss @@ -2260,10 +2260,13 @@ main > .diff-section, display: contents; } +// Log or Timeline: the current one held like a pressed tool inside the sheet, as a sort choice is, +// with no underline or accent of its own. #ci-view-log:checked ~ .ci-logbar .ci-tl-tab-log, #ci-view-timeline:checked ~ .ci-logbar .ci-tl-tab-timeline { - background: var(--accent-soft); - color: var(--accent); + background: var(--surface-2); + color: var(--text); + box-shadow: none; font-weight: 500; // the same as its neighbours, so choosing never shifts the row } @@ -3042,18 +3045,17 @@ details:not([open])::details-content { align-self: center; } -// Colour rows: the swatches sit on nine fixed columns, the most any row has, so the sliders and the hex -// box of Background and Accent start on one edge whatever each row holds. Hue, vividness and hex -// follow on one line, each its own width; a note about a lightened hex goes under them. +// Colour rows: five presets on fixed columns, then the Custom chip, then hue, vividness and hex, +// so Background and Accent line up column for column. A note about a lightened hex goes under them. .colour-choices { display: grid; - grid-template-columns: repeat(9, 30px) auto; + grid-template-columns: repeat(5, 30px) auto auto; align-items: center; gap: 8px; } .colour-choices > .tune { - grid-column: 10; + grid-column: 7; display: flex; flex-wrap: wrap; align-items: center; @@ -3097,3 +3099,177 @@ details:not([open])::details-content { margin: 0; } } + +// Every head of a page with tabs is one height: a 38px title line (as tall as the button beside a +// title) and one sub line, so switching tabs never moves the tabs or what is under them. +.head-title { + min-height: 38px; +} + +main:has(> nav.tabs) > .head { + min-height: 64px; +} + +// A focus ring sits inside what has it, so a list that scrolls on its own never cuts it off. +:is(.rail-item, .line, summary, nav.tabs a, .tabs a, .sub a, .choice label):focus-visible { + outline-offset: -2px; +} + +// A row's actions follow its text on the same line. A confirm opens in place of its word: the +// question, then the danger button and Keep it, all on the row. +.line { + flex-wrap: wrap; +} + +.line > :is(details.reveal, .act-form, a.act, button.act) { + flex: none; + align-self: center; +} + +.line > details.reveal[open] > summary { + display: none; +} + +.line > details.reveal > form.opened { + display: flex; + flex-direction: row; + flex-wrap: wrap; + align-items: center; + gap: 8px; + margin: 0; + padding: 0; + + > .hint { + margin: 0; + } + + > .acts.asks { + margin: 0; + } +} + +// The account menu's name is its profile link: a menu row in the name's weight. +a.corner-who { + display: flex; + align-items: center; + min-height: 34px; + box-sizing: border-box; + border-radius: 12px; + color: var(--text); + font-weight: 600; + text-decoration: none; + + &:hover { + background: var(--surface-2); + } +} + +// Run alerts: the previews stand on the switch's middle line, as tall as its choices. +.sound-row > .act.play { + align-self: center; + height: 32px; + border-radius: 16px; +} + +// The custom colour reads as a word with its swatch, not as one more circle. +.colour-choice:has(> .custom-word) { + display: inline-flex; + flex-direction: row; + align-items: center; + gap: 8px; + width: auto; + height: 32px; + padding: 0 12px 0 4px; + border-radius: 16px; + background: var(--surface-2); + color: var(--text); + font-size: 14px; + cursor: pointer; + + > .hue-swatch { + width: 24px; + height: 24px; + } + + > .custom-word { + max-width: none; + overflow: visible; + font-size: 14px; + font-weight: 400; + color: var(--text); + } +} + +// A form of one field sends from beside it: the field, then its button on the same line. +form.fields:has(> .field + button[type="submit"]):not(:has(> :not(.field, button[type="submit"], input[type="hidden"]))):not(:has(> .field ~ .field)) { + flex-direction: row; + flex-wrap: wrap; + align-items: flex-start; + column-gap: 8px; + + > .field { + flex: none; + } + + > button[type="submit"] { + margin: 0; + } +} + +// Numbered pages are the same row as every pager: on the sheet's inset with a hairline above, the +// numbers quiet words, the current one held like a pressed tool at the same weight, so moving +// between pages never shifts the row. +nav.pager.pager-numbered { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 4px; + margin: 0; + padding: 8px 18px; + border-top: 1px solid var(--border); + font-size: 14px; + + .pager-page, + .pager-step { + color: var(--muted); + font-weight: 500; + } + + > :first-child { + margin-left: -8px; + } + + .current { + background: var(--surface-2); + color: var(--text); + font-weight: 500; + } + + a:hover { + color: var(--text); + } +} + +// A commit subject among a row's facts stays inline with the facts after it. +.line .val .commit-line { + display: inline-flex; + max-width: 40ch; + vertical-align: bottom; +} + +// Passed is green everywhere, but a green with the accent's lightness and strength, so CI results +// sit with the chosen accent instead of beside it. A grey accent still gets a readable green. +@supports (color: oklch(from red l c h)) { + :root:root:root { + --ok: oklch(from var(--accent) l clamp(0.09, c, 0.15) 158); + } +} + +// One focus ring for every control: 2px in the focus colour, drawn inside the control's own edge, +// so a sheet's or a row's edge never clips it and it looks the same on a button, a quiet action, a +// pager number or a tab. +:is(button, .button, a.act, .act, nav.pager a, .ci-tl-tab, .corner-who):focus-visible { + outline: 2px solid var(--focus); + outline-offset: -2px; + box-shadow: none; +} diff --git a/style/_one_ci.scss b/style/_one_ci.scss index 1d7b678..463095a 100644 --- a/style/_one_ci.scss +++ b/style/_one_ci.scss @@ -356,3 +356,99 @@ main:has(> .ci-job) > .sheet { .ci-job .ci-dock { padding: 12px 18px; } + +// Log lines: the number column fits five digits on one line in the log's own font, so a number +// never wraps under itself and every line is one line tall. +.ci-log .ll { + grid-template-columns: 7ch minmax(0, 1fr); + column-gap: 2ch; +} + +.ci-log .ln { + width: auto; + padding-right: 0; + white-space: nowrap; +} + +// A group's name is a line like the others, with its number, and keeps a hairline under it while +// it sticks. +.ci-log details.lg > summary { + display: grid; +} + +// A run or job page fills the window under the top bar, whatever stands between them (a banner, +// a notice): the page is a column, and the log takes the room left. +body:has(> .shell main > :is(.ci-run, .ci-job)) { + height: 100dvh; + min-height: 600px; + + > .shell { + flex: 1 1 0; + min-height: 0; + } + + .shell-body { + min-height: 0; + } +} + +.shell-body > main:has(> :is(.ci-run, .ci-job)) { + flex: 1 1 0; + height: auto; + min-height: 0; +} + +// Artifacts are one line of links under the log, not a list that pushes the page past the window. +.ci-job .ci-artifacts { + display: flex; + flex: none; + flex-wrap: wrap; + align-items: baseline; + gap: 4px 16px; + padding: 10px 18px; + border-top: 1px solid var(--border); + font-size: 14px; + + > h2 { + margin: 0; + color: var(--muted); + font-size: 13px; + font-weight: 600; + } + + .val { + color: var(--muted); + font-size: 13px; + } +} + +// The state in a head's sub line is its word in its colour after a dot, on the line's middle, not a +// box that stands taller than the text around it. +.head-sub .ci-state { + display: inline-flex; + align-items: center; + gap: 6px; + height: auto; + padding: 0; + border: 0; + background: none; + font-size: 14px; + line-height: 20px; +} + +.head-sub .ci-state::before { + margin-right: 0; +} + +// The Timeline tab is the chart and one line a job: what ran where and for how long, with its Re-run. +// The output lives in the Log tab, so no tail of it repeats here. +.ci-tl-panel-timeline { + :is(.ci-job-head, .ci-job-last, .ci-job-tail, .ci-chev) { + display: none; + } + + .ci-job-list { + margin-top: 8px; + border-top: 1px solid var(--border); + } +} diff --git a/style/_one_people.scss b/style/_one_people.scss index b6d1bc8..5ccbe99 100644 --- a/style/_one_people.scss +++ b/style/_one_people.scss @@ -305,3 +305,49 @@ .snippet-form .snippet-tabs { flex: 0 1 auto; } + +// A snippet's files are one row on the control column: the file chips, Add file, then how many of +// how many, the way every control starts on the fields' edge. +.snippet-form > .snippet-files { + display: flex; + flex-direction: row; + flex-wrap: wrap; + align-items: center; + column-gap: 8px; + row-gap: 6px; + padding-left: calc(var(--label-w, 130px) + 16px); + + > .snippet-tabbar { + display: contents; + } + + .snippet-tabs { + order: 1; + margin: 0; + padding: 0; + } + + > .acts { + order: 2; + margin: 0; + } + + .snippet-count { + order: 3; + margin: 0; + } + + > fieldset { + order: 4; + flex: 1 1 100%; + margin: 0 0 0 calc(-1 * (var(--label-w, 130px) + 16px)); + } + + @media (max-width: 700px) { + padding-left: 0; + + > fieldset { + margin-left: 0; + } + } +}