feat(11-02): add optional ReportBranding parameter to all 5 HTML export services

- Added ReportBranding? branding = null to BuildHtml on all 5 services
- Added ReportBranding? branding = null after CancellationToken ct on all WriteAsync overloads
- Injected BrandingHtmlHelper.BuildBrandingHeader(branding) between <body> and <h1> in each
- StorageHtmlExportService both overloads updated (nodes-only and nodes+fileTypeMetrics)
- HtmlExportService both overloads updated (PermissionEntry and SimplifiedPermissionEntry)
- Build passes with 0 warnings — all existing callers compile unchanged via default null
This commit is contained in:
Dev
2026-04-08 14:44:23 +02:00
parent 2e8ceea279
commit 2233fb86a9
5 changed files with 36 additions and 21 deletions

View File

@@ -10,7 +10,7 @@ namespace SharepointToolbox.Services.Export;
/// </summary> /// </summary>
public class DuplicatesHtmlExportService public class DuplicatesHtmlExportService
{ {
public string BuildHtml(IReadOnlyList<DuplicateGroup> groups) public string BuildHtml(IReadOnlyList<DuplicateGroup> groups, ReportBranding? branding = null)
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
@@ -52,6 +52,9 @@ public class DuplicatesHtmlExportService
</script> </script>
</head> </head>
<body> <body>
""");
sb.Append(BrandingHtmlHelper.BuildBrandingHeader(branding));
sb.AppendLine("""
<h1>Duplicate Detection Report</h1> <h1>Duplicate Detection Report</h1>
"""); """);
@@ -117,9 +120,9 @@ public class DuplicatesHtmlExportService
return sb.ToString(); return sb.ToString();
} }
public async Task WriteAsync(IReadOnlyList<DuplicateGroup> groups, string filePath, CancellationToken ct) public async Task WriteAsync(IReadOnlyList<DuplicateGroup> groups, string filePath, CancellationToken ct, ReportBranding? branding = null)
{ {
var html = BuildHtml(groups); var html = BuildHtml(groups, branding);
await System.IO.File.WriteAllTextAsync(filePath, html, Encoding.UTF8, ct); await System.IO.File.WriteAllTextAsync(filePath, html, Encoding.UTF8, ct);
} }

View File

@@ -15,7 +15,7 @@ public class HtmlExportService
/// Builds a self-contained HTML string from the supplied permission entries. /// Builds a self-contained HTML string from the supplied permission entries.
/// Includes inline CSS, inline JS filter, stats cards, type badges, unique/inherited badges, and user pills. /// Includes inline CSS, inline JS filter, stats cards, type badges, unique/inherited badges, and user pills.
/// </summary> /// </summary>
public string BuildHtml(IReadOnlyList<PermissionEntry> entries) public string BuildHtml(IReadOnlyList<PermissionEntry> entries, ReportBranding? branding = null)
{ {
// Compute stats // Compute stats
var totalEntries = entries.Count; var totalEntries = entries.Count;
@@ -73,6 +73,7 @@ a:hover { text-decoration: underline; }
// ── BODY ─────────────────────────────────────────────────────────────── // ── BODY ───────────────────────────────────────────────────────────────
sb.AppendLine("<body>"); sb.AppendLine("<body>");
sb.Append(BrandingHtmlHelper.BuildBrandingHeader(branding));
sb.AppendLine("<h1>SharePoint Permissions Report</h1>"); sb.AppendLine("<h1>SharePoint Permissions Report</h1>");
// Stats cards // Stats cards
@@ -148,9 +149,9 @@ a:hover { text-decoration: underline; }
/// <summary> /// <summary>
/// Writes the HTML report to the specified file path using UTF-8 without BOM. /// Writes the HTML report to the specified file path using UTF-8 without BOM.
/// </summary> /// </summary>
public async Task WriteAsync(IReadOnlyList<PermissionEntry> entries, string filePath, CancellationToken ct) public async Task WriteAsync(IReadOnlyList<PermissionEntry> entries, string filePath, CancellationToken ct, ReportBranding? branding = null)
{ {
var html = BuildHtml(entries); var html = BuildHtml(entries, branding);
await File.WriteAllTextAsync(filePath, html, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), ct); await File.WriteAllTextAsync(filePath, html, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), ct);
} }
@@ -168,7 +169,7 @@ a:hover { text-decoration: underline; }
/// Builds a self-contained HTML string from simplified permission entries. /// Builds a self-contained HTML string from simplified permission entries.
/// Includes risk-level summary cards, color-coded rows, and simplified labels column. /// Includes risk-level summary cards, color-coded rows, and simplified labels column.
/// </summary> /// </summary>
public string BuildHtml(IReadOnlyList<SimplifiedPermissionEntry> entries) public string BuildHtml(IReadOnlyList<SimplifiedPermissionEntry> entries, ReportBranding? branding = null)
{ {
var summaries = PermissionSummaryBuilder.Build(entries); var summaries = PermissionSummaryBuilder.Build(entries);
@@ -228,6 +229,7 @@ a:hover { text-decoration: underline; }
sb.AppendLine("</head>"); sb.AppendLine("</head>");
sb.AppendLine("<body>"); sb.AppendLine("<body>");
sb.Append(BrandingHtmlHelper.BuildBrandingHeader(branding));
sb.AppendLine("<h1>SharePoint Permissions Report (Simplified)</h1>"); sb.AppendLine("<h1>SharePoint Permissions Report (Simplified)</h1>");
// Stats cards // Stats cards
@@ -317,9 +319,9 @@ a:hover { text-decoration: underline; }
/// <summary> /// <summary>
/// Writes the simplified HTML report to the specified file path. /// Writes the simplified HTML report to the specified file path.
/// </summary> /// </summary>
public async Task WriteAsync(IReadOnlyList<SimplifiedPermissionEntry> entries, string filePath, CancellationToken ct) public async Task WriteAsync(IReadOnlyList<SimplifiedPermissionEntry> entries, string filePath, CancellationToken ct, ReportBranding? branding = null)
{ {
var html = BuildHtml(entries); var html = BuildHtml(entries, branding);
await File.WriteAllTextAsync(filePath, html, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), ct); await File.WriteAllTextAsync(filePath, html, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), ct);
} }

View File

@@ -11,7 +11,7 @@ namespace SharepointToolbox.Services.Export;
/// </summary> /// </summary>
public class SearchHtmlExportService public class SearchHtmlExportService
{ {
public string BuildHtml(IReadOnlyList<SearchResult> results) public string BuildHtml(IReadOnlyList<SearchResult> results, ReportBranding? branding = null)
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
@@ -43,6 +43,9 @@ public class SearchHtmlExportService
</style> </style>
</head> </head>
<body> <body>
""");
sb.Append(BrandingHtmlHelper.BuildBrandingHeader(branding));
sb.AppendLine("""
<h1>File Search Results</h1> <h1>File Search Results</h1>
<div class="toolbar"> <div class="toolbar">
<label for="filterInput">Filter:</label> <label for="filterInput">Filter:</label>
@@ -135,9 +138,9 @@ public class SearchHtmlExportService
return sb.ToString(); return sb.ToString();
} }
public async Task WriteAsync(IReadOnlyList<SearchResult> results, string filePath, CancellationToken ct) public async Task WriteAsync(IReadOnlyList<SearchResult> results, string filePath, CancellationToken ct, ReportBranding? branding = null)
{ {
var html = BuildHtml(results); var html = BuildHtml(results, branding);
await System.IO.File.WriteAllTextAsync(filePath, html, Encoding.UTF8, ct); await System.IO.File.WriteAllTextAsync(filePath, html, Encoding.UTF8, ct);
} }

View File

@@ -13,7 +13,7 @@ public class StorageHtmlExportService
{ {
private int _togIdx; private int _togIdx;
public string BuildHtml(IReadOnlyList<StorageNode> nodes) public string BuildHtml(IReadOnlyList<StorageNode> nodes, ReportBranding? branding = null)
{ {
_togIdx = 0; _togIdx = 0;
var sb = new StringBuilder(); var sb = new StringBuilder();
@@ -48,6 +48,9 @@ public class StorageHtmlExportService
</script> </script>
</head> </head>
<body> <body>
""");
sb.Append(BrandingHtmlHelper.BuildBrandingHeader(branding));
sb.AppendLine("""
<h1>SharePoint Storage Metrics</h1> <h1>SharePoint Storage Metrics</h1>
"""); """);
@@ -99,7 +102,7 @@ public class StorageHtmlExportService
/// <summary> /// <summary>
/// Builds an HTML report including a file-type breakdown chart section. /// Builds an HTML report including a file-type breakdown chart section.
/// </summary> /// </summary>
public string BuildHtml(IReadOnlyList<StorageNode> nodes, IReadOnlyList<FileTypeMetric> fileTypeMetrics) public string BuildHtml(IReadOnlyList<StorageNode> nodes, IReadOnlyList<FileTypeMetric> fileTypeMetrics, ReportBranding? branding = null)
{ {
_togIdx = 0; _togIdx = 0;
var sb = new StringBuilder(); var sb = new StringBuilder();
@@ -145,6 +148,9 @@ public class StorageHtmlExportService
</script> </script>
</head> </head>
<body> <body>
""");
sb.Append(BrandingHtmlHelper.BuildBrandingHeader(branding));
sb.AppendLine("""
<h1>SharePoint Storage Metrics</h1> <h1>SharePoint Storage Metrics</h1>
"""); """);
@@ -227,15 +233,15 @@ public class StorageHtmlExportService
return sb.ToString(); return sb.ToString();
} }
public async Task WriteAsync(IReadOnlyList<StorageNode> nodes, string filePath, CancellationToken ct) public async Task WriteAsync(IReadOnlyList<StorageNode> nodes, string filePath, CancellationToken ct, ReportBranding? branding = null)
{ {
var html = BuildHtml(nodes); var html = BuildHtml(nodes, branding);
await File.WriteAllTextAsync(filePath, html, Encoding.UTF8, ct); await File.WriteAllTextAsync(filePath, html, Encoding.UTF8, ct);
} }
public async Task WriteAsync(IReadOnlyList<StorageNode> nodes, IReadOnlyList<FileTypeMetric> fileTypeMetrics, string filePath, CancellationToken ct) public async Task WriteAsync(IReadOnlyList<StorageNode> nodes, IReadOnlyList<FileTypeMetric> fileTypeMetrics, string filePath, CancellationToken ct, ReportBranding? branding = null)
{ {
var html = BuildHtml(nodes, fileTypeMetrics); var html = BuildHtml(nodes, fileTypeMetrics, branding);
await File.WriteAllTextAsync(filePath, html, Encoding.UTF8, ct); await File.WriteAllTextAsync(filePath, html, Encoding.UTF8, ct);
} }

View File

@@ -15,7 +15,7 @@ public class UserAccessHtmlExportService
/// <summary> /// <summary>
/// Builds a self-contained HTML string from the supplied user access entries. /// Builds a self-contained HTML string from the supplied user access entries.
/// </summary> /// </summary>
public string BuildHtml(IReadOnlyList<UserAccessEntry> entries) public string BuildHtml(IReadOnlyList<UserAccessEntry> entries, ReportBranding? branding = null)
{ {
// Compute stats // Compute stats
var totalAccesses = entries.Count; var totalAccesses = entries.Count;
@@ -88,6 +88,7 @@ a:hover { text-decoration: underline; }
// ── BODY ─────────────────────────────────────────────────────────────── // ── BODY ───────────────────────────────────────────────────────────────
sb.AppendLine("<body>"); sb.AppendLine("<body>");
sb.Append(BrandingHtmlHelper.BuildBrandingHeader(branding));
sb.AppendLine("<h1>User Access Audit Report</h1>"); sb.AppendLine("<h1>User Access Audit Report</h1>");
// Stats cards // Stats cards
@@ -320,9 +321,9 @@ function sortTable(view, col) {
/// <summary> /// <summary>
/// Writes the HTML report to the specified file path using UTF-8 without BOM. /// Writes the HTML report to the specified file path using UTF-8 without BOM.
/// </summary> /// </summary>
public async Task WriteAsync(IReadOnlyList<UserAccessEntry> entries, string filePath, CancellationToken ct) public async Task WriteAsync(IReadOnlyList<UserAccessEntry> entries, string filePath, CancellationToken ct, ReportBranding? branding = null)
{ {
var html = BuildHtml(entries); var html = BuildHtml(entries, branding);
await File.WriteAllTextAsync(filePath, html, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), ct); await File.WriteAllTextAsync(filePath, html, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), ct);
} }