diff --git a/compliance-agent/src/api/handlers/devices.rs b/compliance-agent/src/api/handlers/devices.rs index 6a5f047..02df7ae 100644 --- a/compliance-agent/src/api/handlers/devices.rs +++ b/compliance-agent/src/api/handlers/devices.rs @@ -17,7 +17,7 @@ use crate::pipeline::csaf_match::{AdvisoryIndex, Wanted}; use compliance_core::csaf_ingest::Advisory; use compliance_core::device_check::{DeviceCheck, DeviceLookup}; use compliance_core::models::plc_device::normalised_order_number; -use compliance_core::models::PlcDevice; +use compliance_core::models::{PlcDevice, TargetDevice}; use compliance_core::tenant_ctx::TenantCtx; /// The provider whose advisories name devices by order number. @@ -44,10 +44,14 @@ async fn advisories_naming( } /// Each of `devices` against `advisories`. -fn checks(devices: Vec, advisories: &[Advisory]) -> Vec { +/// An exported device keeps the export it comes from (#1090, #1097). +fn checks(devices: Vec, advisories: &[Advisory]) -> Vec { devices .into_iter() - .map(|device| DeviceCheck::new(device, advisories)) + .map(|d| DeviceCheck { + exported_in: d.exported_in, + ..DeviceCheck::new(d.device, advisories) + }) .collect() } @@ -81,16 +85,13 @@ pub async fn list_devices( .await .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)? .ok_or(StatusCode::NOT_FOUND)?; - // Entered and exported alike (#1090): a TIA export's devices are listed - // under their names in the project. - let target_devices: Vec<_> = target - .target_devices() - .into_iter() - .map(|d| d.device) - .collect(); + // Entered and exported alike (#1090, #1097): a TIA export's devices are + // listed under their names in the project, saying which export they are + // from, so a client edits only the entered ones. + let target_devices = target.target_devices(); let mut order_numbers: Vec = target_devices .iter() - .map(|d| d.order_number.clone()) + .map(|d| d.device.order_number.clone()) .collect(); order_numbers.sort(); order_numbers.dedup(); @@ -204,9 +205,15 @@ mod tests { assert_eq!(advisories.len(), 1); let devices = checks( vec![ - PlcDevice::new("6ES7511-1AK02-0AB0", "3.1.4", None).unwrap(), - PlcDevice::new("6ES7511-1AK02-0AB0", "3.1.5", None).unwrap(), - PlcDevice::new("6ES7516-3AN02-0AB0", "3.0", None).unwrap(), + PlcDevice::new("6ES7511-1AK02-0AB0", "3.1.4", None) + .unwrap() + .into(), + PlcDevice::new("6ES7511-1AK02-0AB0", "3.1.5", None) + .unwrap() + .into(), + PlcDevice::new("6ES7516-3AN02-0AB0", "3.0", None) + .unwrap() + .into(), ], &advisories, ); diff --git a/compliance-agent/tests/integration/api/onboarding.rs b/compliance-agent/tests/integration/api/onboarding.rs index 4999a38..8f98d98 100644 --- a/compliance-agent/tests/integration/api/onboarding.rs +++ b/compliance-agent/tests/integration/api/onboarding.rs @@ -710,6 +710,9 @@ async fn a_tia_export_brings_its_devices_and_replaces_the_last_one() { let devices = body["data"].as_array().unwrap(); assert_eq!(devices.len(), 1, "{body}"); assert_eq!(devices[0]["label"], "PLC_1", "{body}"); + // It says which export it comes from, so the page saves and edits only + // the devices entered with the target, never this one. + assert_eq!(devices[0]["exported_in"], "linie1.tia-export.zip", "{body}"); server.cleanup().await; } diff --git a/compliance-core/src/device_check.rs b/compliance-core/src/device_check.rs index f08f1b9..7299272 100644 --- a/compliance-core/src/device_check.rs +++ b/compliance-core/src/device_check.rs @@ -114,6 +114,10 @@ pub struct DeviceCheck { pub product: Option, /// The advisories naming it: affecting it first, then by severity. pub advisories: Vec, + /// The TIA export that declares it (its file name, #1090/#1097); none for + /// a device entered with the target. Only an entered one is edited. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub exported_in: Option, } impl DeviceCheck { @@ -147,6 +151,7 @@ impl DeviceCheck { device, product, advisories: rows, + exported_in: None, } } diff --git a/compliance-dashboard/assets/main.css b/compliance-dashboard/assets/main.css index 6e3143f..09e1f86 100644 --- a/compliance-dashboard/assets/main.css +++ b/compliance-dashboard/assets/main.css @@ -9919,6 +9919,7 @@ div.offer-option { flex-direction: column; align-items: flex-start; justify-cont .dev-detail-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: flex-start; } .dev-detail-head > div:first-child { display: flex; flex-direction: column; gap: 4px; } .dev-detail-label { font-size: 14px; color: var(--text-tertiary); } +.dev-detail-source { display: block; margin-top: 2px; } .dev-detail-actions { display: flex; gap: 8px; } .dev-detail-actions .btn { min-height: 44px; } .btn-danger-ghost { color: var(--danger); border-color: var(--danger-bg); } diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index 72a4e4e..a31598c 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -9057,6 +9057,15 @@ pub mod devices { de: "Firmware", en: "Firmware", }; + /// Where an exported device comes from, instead of its edit buttons: it + /// changes with the next export, not here. + pub fn exported_from(file: &str, lang: Lang) -> String { + match lang { + Lang::De => format!("Aus dem TIA-Export {file}; ändert sich mit dem nächsten Export."), + Lang::En => format!("From the TIA export {file}; changes with the next export."), + } + } + pub const CHANGE_FIRMWARE: Text = Text { de: "Firmware ändern", en: "Change firmware", diff --git a/compliance-dashboard/src/pages/devices.rs b/compliance-dashboard/src/pages/devices.rs index 1241736..0dd64fa 100644 --- a/compliance-dashboard/src/pages/devices.rs +++ b/compliance-dashboard/src/pages/devices.rs @@ -104,7 +104,14 @@ pub fn TargetDevicesPage(id: String) -> Element { } None => return rsx! { div { class: "loading", {tx::LOADING.get(lang)} } }, }; - let devices: Vec = listed.iter().map(|c| c.device.clone()).collect(); + // The devices entered with the target: the only ones saved. Exported ones + // (#1090, #1097) are listed after them and change with their export, so + // a selected entered device has the same index in both lists. + let devices: Vec = listed + .iter() + .filter(|c| c.exported_in.is_none()) + .map(|c| c.device.clone()) + .collect(); // A first device is added from the empty rail's form. let show_form = can_write && (adding() || listed.is_empty()); let chosen = (!show_form) @@ -362,8 +369,11 @@ fn DeviceDetail( div { h2 { "{name}" } span { class: "dev-detail-label", "{label}" } + if let Some(file) = &check.exported_in { + span { class: "dev-detail-label dev-detail-source", {tx::exported_from(file, lang)} } + } } - if can_write { + if can_write && check.exported_in.is_none() { div { class: "dev-detail-actions", if !editing() { button {