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:
@@ -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>
|
||||
|
||||
@@ -155,12 +155,12 @@
|
||||
<td>
|
||||
@if (row.CurrentAgreement != null)
|
||||
{
|
||||
<span class="badge bg-success"><i class="bi bi-check-circle me-1"></i>v@row.CurrentAgreement.TermsVersion</span>
|
||||
<span class="badge bg-success"><i class="bi bi-check-circle me-1"></i>v@(row.CurrentAgreement.TermsVersion)</span>
|
||||
}
|
||||
else if (row.LatestAgreement != null)
|
||||
{
|
||||
<span class="badge bg-warning text-dark" title="Accepted v@row.LatestAgreement.TermsVersion — current is v@currentVersion">
|
||||
<i class="bi bi-exclamation-triangle me-1"></i>Stale (v@row.LatestAgreement.TermsVersion)
|
||||
<span class="badge bg-warning text-dark" title="Accepted v@(row.LatestAgreement.TermsVersion) — current is v@currentVersion">
|
||||
<i class="bi bi-exclamation-triangle me-1"></i>Stale (v@(row.LatestAgreement.TermsVersion))
|
||||
</span>
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user