fix(config): #998 deploy gate rejects duplicate ZTag/SAPID, duplicate owned historian tagnames and dangling parent links; NULL-keyed unique indexes enforced; node/cluster edits carry a RowVersion

C-3 ZTag/SAPID uniqueness enforced from the draft (reservation ledger has no writer); UI/doc claim corrected.
C-5 HistorianTagnameDuplicate (owned tags, per cluster, case-insensitive; readOnly exempt).
C-8 UX_NodeAcl_PrincipalScope / UX_LdapGroupRoleMapping_Group_Cluster unfiltered (migration with duplicate pre-check) + friendly service/page checks.
C-9 RowVersion on ClusterNode/ServerCluster, edit pages use it; node delete removes its NodeDeploymentState rows.
C-10 DanglingReference rule; dead PathTooLong/EquipmentUuidImmutable rules + PriorEquipment/Enterprise/Site inputs deleted.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-12-03 10:49:57 -05:00
parent b9955f6946
commit 486628cf0a
24 changed files with 2833 additions and 171 deletions
@@ -252,6 +252,15 @@ else
if (!_scope.Ok) { _error = $"Scope: {_scope.Message}"; return; }
await using var db = await DbFactory.CreateDbContextAsync();
// #998 (review C-8): UX_NodeAcl_PrincipalScope allows one row per (cluster, principal, scope kind,
// scope id) — including one Cluster-scope row (NULL scope id). Report it in words.
var scopeId = string.IsNullOrWhiteSpace(_form.ScopeId) ? null : _form.ScopeId;
var editedId = IsNew ? _form.NodeAclId : NodeAclId;
if (await db.NodeAcls.AnyAsync(a => a.ClusterId == ClusterId && a.Principal == _form.Principal
&& a.ScopeKind == _form.ScopeKind && a.ScopeId == scopeId && a.NodeAclId != editedId))
{ _error = $"An ACL for '{_form.Principal}' at this scope already exists in this cluster; edit that row instead."; return; }
if (IsNew)
{
if (await db.NodeAcls.AnyAsync(a => a.NodeAclId == _form.NodeAclId))
@@ -139,6 +139,7 @@ else
RedundancyMode = _existing.RedundancyMode,
Enabled = _existing.Enabled,
Notes = _existing.Notes,
RowVersion = _existing.RowVersion,
};
}
_loaded = true;
@@ -154,6 +155,8 @@ else
var entity = await db.ServerClusters.FirstOrDefaultAsync(c => c.ClusterId == ClusterId);
if (entity is null) { _error = "Cluster no longer exists."; return; }
// #998 (review C-9): the token loaded with the form, so a stale form cannot overwrite a concurrent edit.
db.Entry(entity).Property(e => e.RowVersion).OriginalValue = _form.RowVersion;
var auth = await AuthState.GetAuthenticationStateAsync();
entity.Name = _form.Name;
entity.Enterprise = _form.Enterprise;
@@ -168,6 +171,10 @@ else
await db.SaveChangesAsync();
Nav.NavigateTo($"/clusters/{ClusterId}");
}
catch (DbUpdateConcurrencyException)
{
_error = "Another user changed this cluster while you were editing. Reload the page and re-apply your change.";
}
catch (Exception ex)
{
_error = ex.Message;
@@ -209,5 +216,6 @@ else
public RedundancyMode RedundancyMode { get; set; } = RedundancyMode.None;
public bool Enabled { get; set; } = true;
public string? Notes { get; set; }
public byte[] RowVersion { get; set; } = [];
}
}
@@ -177,6 +177,7 @@ else
ServiceLevelBase = _existing.ServiceLevelBase,
Enabled = _existing.Enabled,
DriverConfigOverridesJson = _existing.DriverConfigOverridesJson,
RowVersion = _existing.RowVersion,
};
}
}
@@ -251,6 +252,9 @@ else
var entity = await db.ClusterNodes.FirstOrDefaultAsync(
n => n.ClusterId == ClusterId && n.NodeId == NodeId);
if (entity is null) { _error = "Row no longer exists."; return; }
// #998 (review C-9): the token loaded with the form, not the one just re-read — otherwise a
// concurrent edit (e.g. Enabled flipped for maintenance) would be silently overwritten.
db.Entry(entity).Property(e => e.RowVersion).OriginalValue = _form.RowVersion;
entity.Host = _form.Host;
entity.OpcUaPort = _form.OpcUaPort;
entity.DashboardPort = _form.DashboardPort;
@@ -262,6 +266,10 @@ else
await db.SaveChangesAsync();
Nav.NavigateTo($"/clusters/{ClusterId}");
}
catch (DbUpdateConcurrencyException)
{
_error = "Another user changed this node while you were editing. Reload the page and re-apply your change.";
}
catch (Exception ex)
{
_error = ex.Message;
@@ -283,6 +291,10 @@ else
var entity = await db.ClusterNodes.FirstOrDefaultAsync(
n => n.ClusterId == ClusterId && n.NodeId == NodeId);
if (entity is null) { Nav.NavigateTo($"/clusters/{ClusterId}"); return; }
// #998 (review C-9): NodeDeploymentState.NodeId is a Restrict FK, so a node that was ever deployed
// to could not be deleted (raw FK error). Its per-deployment ack rows are history about THIS node
// and meaningless without it: remove them in the same transaction.
db.NodeDeploymentStates.RemoveRange(await db.NodeDeploymentStates.Where(s => s.NodeId == NodeId).ToListAsync());
db.ClusterNodes.Remove(entity);
await db.SaveChangesAsync();
Nav.NavigateTo($"/clusters/{ClusterId}");
@@ -321,5 +333,6 @@ else
[Range(0, 255)] public int ServiceLevelBase { get; set; } = 200;
public bool Enabled { get; set; } = true;
public string? DriverConfigOverridesJson { get; set; }
public byte[] RowVersion { get; set; } = [];
}
}
@@ -23,7 +23,7 @@ else
<h2 class="panel-head">@_rows.Count reservation@(_rows.Count == 1 ? "" : "s")</h2>
@if (_rows.Count == 0)
{
<div style="padding:1rem" class="text-muted">No reservations yet.</div>
<div style="padding:1rem" class="text-muted">No reservations. (Nothing writes this ledger any more: ZTag / SAPID uniqueness is enforced by the deploy gate.)</div>
}
else
{
@@ -117,11 +117,12 @@ else
<div class="col-md-6 mb-3">
<label class="form-label" for='@FieldId("eq-ztag")'>ZTag (ERP)</label>
<InputText id='@FieldId("eq-ztag")' aria-describedby='@FieldId("eq-ztag-hint")' @bind-Value="form.ZTag" class="form-control form-control-sm" />
<div id='@FieldId("eq-ztag-hint")' class="form-text">Unique fleet-wide via ExternalIdReservation.</div>
<div id='@FieldId("eq-ztag-hint")' class="form-text">Must be unique fleet-wide (case-insensitive); a duplicate is rejected when you deploy.</div>
</div>
<div class="col-md-6 mb-3">
<label class="form-label" for='@FieldId("eq-sap")'>SAPID</label>
<InputText id='@FieldId("eq-sap")' @bind-Value="form.SAPID" class="form-control form-control-sm" />
<div class="form-text">Must be unique fleet-wide (case-insensitive); a duplicate is rejected when you deploy.</div>
</div>
</div>
<div class="mb-3">