fix(dashboard): targets named owner/repo can be edited and saved
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 10m53s
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 10m53s
Targets created from a managed git repo are named "owner/repo". The
target name check refused slashes ("the name becomes a folder"), so the
edit dialog of every such target could not be saved until it was renamed,
and the message was English in the German UI.
The agent never uses the raw name as a path: clone_dir collapses it to
one safe segment (tenant_path::name_segment), downloads are named by id,
and the target update handler does not validate the name. So the
dashboard only refuses an empty name and outer spaces now, with German
and English messages.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
This commit is contained in:
1 parent
e1bf9e861c
commit
97b4a73f1a
4 files changed
+38
-19
No files matched your search
@@ -708,6 +708,14 @@ pub mod targets {
|
||||
de: "Typ",
|
||||
en: "Type",
|
||||
};
|
||||
pub const NAME_EMPTY: Text = Text {
|
||||
de: "Bitte einen Namen eingeben",
|
||||
en: "Enter a name",
|
||||
};
|
||||
pub const NAME_OUTER_SPACES: Text = Text {
|
||||
de: "Bitte Leerzeichen am Anfang und Ende entfernen",
|
||||
en: "Remove the leading/trailing spaces",
|
||||
};
|
||||
pub const COL_LAST_SCAN: Text = Text {
|
||||
de: "Letzte Prüfung",
|
||||
en: "Last scan",
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
use dioxus::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::i18n::texts::demo;
|
||||
use crate::i18n::Lang;
|
||||
use crate::i18n::texts::{demo, targets};
|
||||
use crate::i18n::{Lang, Text};
|
||||
|
||||
/// One artifact the wizard collects for a target.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
|
||||
@@ -225,8 +225,6 @@ pub fn demo_seed_default_selection(targets: &[DemoSeedTarget], source_only: bool
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Validate a target name. The name is used as the clone directory downstream,
|
||||
/// so it must be a single safe segment (no slashes) and free of stray spaces.
|
||||
/// Artifact kinds provided as an uploaded file (rather than a URL/text ref).
|
||||
pub fn is_file_kind(kind: &str) -> bool {
|
||||
matches!(
|
||||
@@ -249,18 +247,19 @@ pub fn plc_format_for(file_name: &str) -> Option<&'static str> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn validate_target_name(name: &str) -> Option<String> {
|
||||
let n = name.trim();
|
||||
if n.is_empty() {
|
||||
return Some("Enter a name".to_string());
|
||||
/// Validate a target name, returning the message to show when it is unusable.
|
||||
///
|
||||
/// Only an empty name and stray outer spaces are refused. Slashes are fine:
|
||||
/// targets created from a git repo are named `owner/repo`, and the agent
|
||||
/// collapses the name to one safe path segment wherever it needs a folder.
|
||||
pub fn validate_target_name(name: &str) -> Option<Text> {
|
||||
if name.trim().is_empty() {
|
||||
Some(targets::NAME_EMPTY)
|
||||
} else if name != name.trim() {
|
||||
Some(targets::NAME_OUTER_SPACES)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
if name != n {
|
||||
return Some("Remove the leading/trailing spaces".to_string());
|
||||
}
|
||||
if n.contains('/') || n.contains('\\') {
|
||||
return Some("No slashes — the name becomes a folder (e.g. stm32f411-blinky)".to_string());
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Client-side validation of an artifact reference for its kind. Returns an
|
||||
@@ -569,6 +568,18 @@ mod tests {
|
||||
assert_eq!(plc_format_for("firmware.bin"), None);
|
||||
assert!(is_file_kind("source_archive") && !is_file_kind("git_repo"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_target_name_may_carry_slashes_but_not_blanks() {
|
||||
assert_eq!(validate_target_name("bp-test/plc-codesys"), None);
|
||||
assert_eq!(validate_target_name("sensor-node"), None);
|
||||
assert_eq!(validate_target_name(""), Some(targets::NAME_EMPTY));
|
||||
assert_eq!(validate_target_name(" "), Some(targets::NAME_EMPTY));
|
||||
assert_eq!(
|
||||
validate_target_name(" owner/repo"),
|
||||
Some(targets::NAME_OUTER_SPACES)
|
||||
);
|
||||
}
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -178,8 +178,8 @@ pub fn OnboardingPage() -> Element {
|
||||
oninput: move |e| name.set(e.value()),
|
||||
}
|
||||
if !name().is_empty() {
|
||||
if let Some(err) = name_error.clone() {
|
||||
div { style: "color: var(--danger, #d33); font-size: 0.85em; margin-top: 4px;", "{err}" }
|
||||
if let Some(err) = name_error {
|
||||
div { style: "color: var(--danger, #d33); font-size: 0.85em; margin-top: 4px;", {err.get(lang)} }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,8 +462,8 @@ fn TargetEditor(
|
||||
oninput: move |e| edit_name.set(e.value()),
|
||||
}
|
||||
if !edit_name().is_empty() {
|
||||
if let Some(err) = name_err.clone() {
|
||||
div { style: "color: var(--danger, #d33); font-size: 0.85em;", "{err}" }
|
||||
if let Some(err) = name_err {
|
||||
div { style: "color: var(--danger, #d33); font-size: 0.85em;", {err.get(lang)} }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user