Fix SMS Agreements version display and auto-remove stale templates

Fix Razor rendering of TermsVersion — property chains after a literal
character need @() parentheses or Razor misparses the expression.

Also adds cleanup to EnsureNotificationTemplatesSeededAsync to remove
stale template rows (no longer canonical, never customised) on next
settings visit, so retired types like JobReadyForPickup SMS disappear
automatically.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-03 11:02:25 -04:00
parent 0b6a7a14c4
commit 90f333c8f3
2 changed files with 19 additions and 6 deletions
@@ -2557,24 +2557,37 @@ public class CompanySettingsController : Controller
/// company. Called on every visit to the Settings Index and NotificationTemplates pages so new
/// notification types added to <c>SeedData.BuildDefaultNotificationTemplates</c> are automatically
/// provisioned without requiring a migration or a manual "Seed Data" action by the platform admin.
/// Returns the count of newly added templates so the caller can decide whether to reload from the DB.
/// Also removes stale rows (no longer in the canonical list) that have never been customised
/// (UpdatedAt == null), so retired notification types disappear from the UI automatically.
/// Returns the count of changes so the caller can decide whether to reload from the DB.
/// </summary>
private async Task<int> EnsureNotificationTemplatesSeededAsync(
int companyId, List<NotificationTemplate> existing)
{
var allDefaults = SeedData.BuildDefaultNotificationTemplates(companyId);
var toAdd = allDefaults
.Where(d => !existing.Any(e =>
e.NotificationType == d.NotificationType && e.Channel == d.Channel))
.ToList();
// Remove rows that are no longer canonical and have never been customised.
var toRemove = existing
.Where(e => !allDefaults.Any(d =>
d.NotificationType == e.NotificationType && d.Channel == e.Channel)
&& e.UpdatedAt == null)
.ToList();
foreach (var t in toAdd)
await _unitOfWork.NotificationTemplates.AddAsync(t);
if (toAdd.Count > 0)
foreach (var t in toRemove)
await _unitOfWork.NotificationTemplates.DeleteAsync(t);
if (toAdd.Count > 0 || toRemove.Count > 0)
await _unitOfWork.CompleteAsync();
return toAdd.Count;
return toAdd.Count + toRemove.Count;
}
/// <summary>