From a39019b8560a901d3775801e8a9f5ed6e96c13e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= <1005065+DeepDiver1975@users.noreply.github.com> Date: Thu, 19 Nov 2026 11:32:58 +0100 Subject: [PATCH 1/2] fix(atemschutz): refuse a second Trupp of the same name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two Trupps not yet abgenommen may no longer share the same Funkrufname and Trupp-Art, compared trimmed and ignoring case. Incident.AddScbaTrupp and Incident.ChangeScbaTruppType both refuse it with "„HLF 1 · Angriffstrupp“ ist bereits eingetragen.", so a joined device's command meets the same rule and the host answers 400 with that reason. An abgenommen Trupp does not count: a second round from the same Fahrzeug is ordinary. In the Atemschutz tab the Trupp-Art flyout leaves out the choice that would collide, a stale flyout entry is inert, and Bereitstellen shows the same sentence under the form instead of throwing. The ETB line for a Trupp-Art change now names the Trupp by its full name, which the Funkrufname alone did not. Fixes #968 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com> --- .../+atemschutz-no-duplicate-trupp.fixed.md | 1 + .../ViewModels/ScbaViewModel.cs | 39 ++++- .../Atemschutz/AtemschutzTrupp.cs | 4 + src/LageBuch.Domain/Incident.cs | 40 +++++ .../ScbaTruppArtFlyoutTests.cs | 95 +++++++++++ .../ScbaNumberedTruppTests.cs | 20 +++ .../ScbaTruppArtChangeTests.cs | 60 ++++++- .../ScbaViewModelTests.cs | 79 ++++++++- .../LageBuch.Domain.Tests/AtemschutzTests.cs | 7 +- .../ScbaTruppNameUniquenessTests.cs | 152 ++++++++++++++++++ .../TruppArtChangeTests.cs | 2 +- .../IncidentHostTests.cs | 36 +++++ .../WorkspaceCollaborationTests.cs | 9 +- 13 files changed, 520 insertions(+), 24 deletions(-) create mode 100644 changelog.d/+atemschutz-no-duplicate-trupp.fixed.md create mode 100644 tests/LageBuch.Domain.Tests/ScbaTruppNameUniquenessTests.cs diff --git a/changelog.d/+atemschutz-no-duplicate-trupp.fixed.md b/changelog.d/+atemschutz-no-duplicate-trupp.fixed.md new file mode 100644 index 000000000..753f4658d --- /dev/null +++ b/changelog.d/+atemschutz-no-duplicate-trupp.fixed.md @@ -0,0 +1 @@ +Atemschutz no longer lets the same Trupp be listed twice: a Trupp not yet abgenommen with the same Funkrufname and Trupp-Art is refused at Bereitstellung with a message naming it, the Trupp-Art flyout leaves out the choice that would collide, and the ETB line for a Trupp-Art change names the Trupp by its full name (#968). diff --git a/src/LageBuch.AppLogic/ViewModels/ScbaViewModel.cs b/src/LageBuch.AppLogic/ViewModels/ScbaViewModel.cs index 1b9f43576..7d68d8ef4 100644 --- a/src/LageBuch.AppLogic/ViewModels/ScbaViewModel.cs +++ b/src/LageBuch.AppLogic/ViewModels/ScbaViewModel.cs @@ -488,6 +488,7 @@ public ScbaViewModel(IIncidentSession session, MasterDataSet masterData, IClock [NotifyPropertyChangedFor(nameof(RequiresThirdMember))] [NotifyPropertyChangedFor(nameof(IsNamedByNumber))] [NotifyPropertyChangedFor(nameof(NewTypeNumberError))] + [NotifyPropertyChangedFor(nameof(NewDuplicateTruppError))] private string _newDesignation = string.Empty; /// @@ -562,6 +563,8 @@ private void ApplyDefaultTypeNumber() private string _newZweiterTruppmann = string.Empty; [ObservableProperty] + [NotifyPropertyChangedFor(nameof(NewDuplicateTruppError))] + [NotifyPropertyChangedFor(nameof(ErrorSummary))] private string? _newCallSign; /// @@ -842,7 +845,7 @@ private void UpdateAlarm(bool newAlarmTripped) /// Whether the Trupp-Art is still missing, once the operator has asked (#412). /// Everything this form is still waiting on, on one line beneath its fields (#412). public string? ErrorSummary => ValidationMessages.Summarize( - NewDesignationError, NewTypeNumberError, NewTruppfuehrerError, NewTruppmannError, NewZweiterTruppmannError, NewEntryPressureError, SubmitError); + NewDesignationError, NewTypeNumberError, NewDuplicateTruppError, NewTruppfuehrerError, NewTruppmannError, NewZweiterTruppmannError, NewEntryPressureError, SubmitError); /// /// Why the host refused the last Bereitstellen, or that it never answered. Only a joined device @@ -852,6 +855,18 @@ private void UpdateAlarm(bool newAlarmTripped) [NotifyPropertyChangedFor(nameof(ErrorSummary))] private string? _submitError; + /// + /// Whether the Funkrufname and Trupp-Art name a Trupp that is already in the Überwachung and + /// not yet abgenommen, once asked (#968). The domain refuses that registration, so the press + /// says which Trupp it would duplicate instead of throwing. A numbered Trupp-Art's Trupp is + /// named by its number, not by the Funkrufname box, and a taken number is + /// 's to refuse. + /// + public string? NewDuplicateTruppError => + _errorsShown && !IsNamedByNumber && _session.Incident.FindScbaTruppNamed(NewCallSign, NewDesignation) is { } holder + ? AtemschutzTrupp.AlreadyRegisteredMessage(holder.DisplayName) + : null; + public string? NewDesignationError => _errorsShown && string.IsNullOrWhiteSpace(NewDesignation) ? ValidationMessages.Required : null; @@ -929,6 +944,7 @@ private bool Validate() ShowErrors(true); return NewDesignationError is null && NewTypeNumberError is null + && NewDuplicateTruppError is null && NewTruppfuehrerError is null && NewTruppmannError is null && NewZweiterTruppmannError is null @@ -953,6 +969,7 @@ private void ShowErrors(bool shown) OnPropertyChanged(nameof(NewDesignationError)); OnPropertyChanged(nameof(ErrorSummary)); OnPropertyChanged(nameof(NewTypeNumberError)); + OnPropertyChanged(nameof(NewDuplicateTruppError)); OnPropertyChanged(nameof(NewTruppfuehrerError)); OnPropertyChanged(nameof(ErrorSummary)); OnPropertyChanged(nameof(NewTruppmannError)); @@ -1161,9 +1178,13 @@ private ScbaTruppRow CreateRow(AtemschutzTrupp trupp) => safetyTruppId => AssignSafetyTrupp(trupp.Id, safetyTruppId)); /// The Trupp-Art flyout entries for one row (#835): today's Trupp-Arten, plus the - /// Trupp's own when the Stammdaten no longer list it, so the record is shown, never lost. + /// Trupp's own when the Stammdaten no longer list it, so the record is shown, never lost. A + /// Trupp-Art that would give the Trupp the name of another Trupp not yet abgenommen is left out + /// (#968): "HLF 1 · Angriffstrupp" twice is the one change the domain refuses. private List TruppTypeChoicesFor(AtemschutzTrupp trupp) => StammdatenCatalogue.Including(TruppTypeOptions, trupp.Designation) + .Where(name => _session.Incident.FindScbaTruppNamed(trupp.CallSign, name, trupp.Id) is null + || string.Equals(name, trupp.Designation, StringComparison.Ordinal)) .Select(name => new TruppTypeChoice( name, string.Equals(name, trupp.Designation, StringComparison.Ordinal), @@ -1257,11 +1278,13 @@ SafetyTruppChoice Choice(AtemschutzTrupp t) => private void ChangeTruppType(Guid truppId, string designation) { // Inert rather than throwing, as AssignSafetyTrupp is: a programmatic Execute bypasses the - // hidden button, and re-choosing the Trupp-Art in force writes no line. + // hidden button, and re-choosing the Trupp-Art in force writes no line. A flyout opened + // before another device took the name holds an entry the domain would refuse (#968). var incident = _session.Incident; if (IsReadOnly || incident.FindScbaTruppOrDefault(truppId) is not { IsReturned: false } trupp - || string.Equals(trupp.Designation, designation, StringComparison.Ordinal)) + || string.Equals(trupp.Designation, designation, StringComparison.Ordinal) + || incident.FindScbaTruppNamed(trupp.CallSign, designation, truppId) is not null) { return; } @@ -1271,8 +1294,9 @@ private void ChangeTruppType(Guid truppId, string designation) var interval = Math.Max(1, maxDuration / 3); // Read before mutating: the mutation raises Changed, which rebuilds every row. - var name = trupp.CallSign ?? $"Trupp {trupp.TruppNumber}"; - var text = $"Trupp-Art von {name} gewechselt: bisher {trupp.Designation}, jetzt {designation}"; + // The name as it read until now, which already carries the old Trupp-Art: the Funkrufname + // alone does not say which of a Fahrzeug's Trupps changed (#968). + var text = $"Trupp-Art von {trupp.DisplayName} gewechselt: jetzt {designation}"; if (trupp.IsWaiting && maxDuration != trupp.MaxDurationMinutes) { text += $", Einsatzzeit {maxDuration} Min."; @@ -1492,6 +1516,9 @@ private void RefreshTrupps() OnPropertyChanged(nameof(CallSignOptions)); } + // A Trupp abgenommen or renamed elsewhere may have freed, or taken, the name on the form. + OnPropertyChanged(nameof(NewDuplicateTruppError)); + OnPropertyChanged(nameof(ErrorSummary)); RefreshHeader(); // A Stand that shows a Trupp whose answer was lost is the answer. diff --git a/src/LageBuch.Domain/Atemschutz/AtemschutzTrupp.cs b/src/LageBuch.Domain/Atemschutz/AtemschutzTrupp.cs index abc2c8893..e153ab846 100644 --- a/src/LageBuch.Domain/Atemschutz/AtemschutzTrupp.cs +++ b/src/LageBuch.Domain/Atemschutz/AtemschutzTrupp.cs @@ -122,6 +122,10 @@ private static bool NamesTruppArt(string callSign, string designation) => && (string.Equals(callSign, designation, StringComparison.Ordinal) || callSign.StartsWith(designation + " ", StringComparison.Ordinal)); + /// Why a second Trupp of this name is refused (#968): the sentence the domain throws + /// and the registration form shows, so both say it the same way. + public static string AlreadyRegisteredMessage(string displayName) => $"„{displayName}“ ist bereits eingetragen."; + /// /// The crew, in position order: between and /// people, as the Trupp-Typ in the Stammdaten calls for. diff --git a/src/LageBuch.Domain/Incident.cs b/src/LageBuch.Domain/Incident.cs index b2330a1a1..2caa4869e 100644 --- a/src/LageBuch.Domain/Incident.cs +++ b/src/LageBuch.Domain/Incident.cs @@ -1943,6 +1943,7 @@ public AtemschutzTrupp AddScbaTrupp( throw new ArgumentException($"{taken} ist bereits vergeben.", nameof(callSign)); } + EnsureScbaTruppNameFree(callSign, designation, exceptTruppId: null); var trupp = AtemschutzTrupp.Register( clock.Now, designation, @@ -1999,16 +2000,55 @@ public AtemschutzTrupp MarkScbaRemoved(IClock clock, Guid truppId) /// . The values come from the caller, who reads them /// off today's Stammdaten. Takes no clock, and the ETB line is written by the caller, like /// . + /// + /// A Trupp-Art that would give the Trupp the name of another Trupp not yet abgenommen is + /// refused (#968), see . An abgenommen Trupp keeps its own + /// refusal, because it cannot change at all. + /// /// public AtemschutzTrupp ChangeScbaTruppType( Guid truppId, string designation, int maxDurationMinutes, int pressureControlIntervalMinutes) { EnsureOpen(); var trupp = FindScbaTrupp(truppId); + if (!trupp.IsReturned) + { + EnsureScbaTruppNameFree(trupp.CallSign, designation, trupp.Id); + } + trupp.ChangeType(designation, maxDurationMinutes, pressureControlIntervalMinutes); return trupp; } + /// + /// The Trupp not yet abgenommen that already goes by "{} · + /// {}", or null when that name is free (#968). Both parts are + /// compared trimmed and ignoring case, and a blank Funkrufname is no Funkrufname, so the + /// comparison sees what shows. An abgenommen Trupp + /// holds no name: a second round from the same Fahrzeug is an ordinary Einsatz. A pure query, + /// like , so the registration form and the Trupp-Art flyout + /// can ask before the domain refuses. + /// + public AtemschutzTrupp? FindScbaTruppNamed(string? callSign, string designation, Guid? exceptTruppId = null) + { + ArgumentNullException.ThrowIfNull(designation); + var wantedCallSign = callSign?.Trim() ?? string.Empty; + var wantedDesignation = designation.Trim(); + return _scbaTrupps.Find(t => + !t.IsReturned + && t.Id != exceptTruppId + && string.Equals(t.Designation.Trim(), wantedDesignation, StringComparison.OrdinalIgnoreCase) + && string.Equals(t.CallSign?.Trim() ?? string.Empty, wantedCallSign, StringComparison.OrdinalIgnoreCase)); + } + + private void EnsureScbaTruppNameFree(string? callSign, string designation, Guid? exceptTruppId) + { + if (FindScbaTruppNamed(callSign, designation, exceptTruppId) is { } holder) + { + throw new InvalidOperationException(AtemschutzTrupp.AlreadyRegisteredMessage(holder.DisplayName)); + } + } + /// /// Designates the Sicherheitstrupp standing by for (#399), or clears /// it with a null . Takes no clock: nothing here is timestamped, diff --git a/tests/LageBuch.Acceptance.Tests/ScbaTruppArtFlyoutTests.cs b/tests/LageBuch.Acceptance.Tests/ScbaTruppArtFlyoutTests.cs index 308f03ff1..bb93a578b 100644 --- a/tests/LageBuch.Acceptance.Tests/ScbaTruppArtFlyoutTests.cs +++ b/tests/LageBuch.Acceptance.Tests/ScbaTruppArtFlyoutTests.cs @@ -4,6 +4,7 @@ using Avalonia.Headless; using Avalonia.Headless.XUnit; using Avalonia.Input; +using Avalonia.Media.Imaging; using Avalonia.Threading; using Avalonia.VisualTree; using LageBuch.App.Shared.Views; @@ -57,6 +58,100 @@ public void Picking_a_trupp_art_changes_it_and_closes_the_flyout(bool narrow) t => t.IsEffectivelyVisible && t.Text == "Florian Musterdorf 42/1 · Angriffstrupp"); } + // #968: the fixture's "Florian Musterstadt 40/1 · Angriffstrupp" is under air, so that Fahrzeug's + // Sicherheitstrupp is not offered Angriffstrupp -- the change that listed the same Trupp twice. + [AvaloniaFact] + public void The_flyout_does_not_offer_the_trupp_art_another_trupp_of_the_fahrzeug_already_has() + { + var vm = WorkspaceRenderHelper.BuildEditableWorkspaceWithAllBars(); + var scba = vm.Scba; + scba.NewDesignation = "Sicherheitstrupp"; + scba.NewCallSign = "Florian Musterstadt 40/1"; + scba.NewTruppfuehrer = "Huber"; + scba.NewTruppmann = "Maier"; + scba.NewZweiterTruppmann = string.Empty; + scba.AddTruppCommand.Execute(null); + var row = scba.Trupps[^1]; + var (window, view) = Show(scba); + + var pencil = Pencil(view, row); + Click(pencil); + var flyout = Assert.IsType(pencil.Flyout); + var content = Assert.IsAssignableFrom(flyout.Content); + var offered = content.GetVisualDescendants().OfType