13 KiB
phase, plan, type, wave, depends_on, files_modified, autonomous, requirements, must_haves
| phase | plan | type | wave | depends_on | files_modified | autonomous | requirements | must_haves | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 16-report-consolidation-toggle | 02 | execute | 2 |
|
|
true |
|
|
Purpose: Completes the user-visible consolidation behavior for HTML reports — the primary export format. Output: Working consolidated HTML export with expandable site lists, full test coverage.
<execution_context> @C:/Users/SebastienQUEROL/.claude/get-shit-done/workflows/execute-plan.md @C:/Users/SebastienQUEROL/.claude/get-shit-done/templates/summary.md </execution_context>
@.planning/PROJECT.md @.planning/ROADMAP.md @.planning/STATE.md @.planning/phases/16-report-consolidation-toggle/16-CONTEXT.md @.planning/phases/16-report-consolidation-toggle/16-RESEARCH.md @.planning/phases/16-report-consolidation-toggle/16-01-SUMMARY.mdFrom SharepointToolbox/ViewModels/Tabs/UserAccessAuditViewModel.cs:
[ObservableProperty]
private bool _mergePermissions;
// ExportHtmlAsync call site (line ~526):
await _htmlExportService.WriteAsync(Results, dialog.FileName, CancellationToken.None, branding);
// Must become:
await _htmlExportService.WriteAsync(Results, dialog.FileName, CancellationToken.None, MergePermissions, branding);
From SharepointToolbox/Services/Export/UserAccessHtmlExportService.cs:
public class UserAccessHtmlExportService
{
public string BuildHtml(IReadOnlyList<UserAccessEntry> entries, ReportBranding? branding = null);
public async Task WriteAsync(IReadOnlyList<UserAccessEntry> entries, string filePath, CancellationToken ct, ReportBranding? branding = null);
}
From SharepointToolbox/Core/Helpers/PermissionConsolidator.cs:
public static IReadOnlyList<ConsolidatedPermissionEntry> Consolidate(IReadOnlyList<UserAccessEntry> entries);
From SharepointToolbox/Core/Models/ConsolidatedPermissionEntry.cs:
public record ConsolidatedPermissionEntry(
string UserDisplayName, string UserLogin, string PermissionLevel,
string AccessType, string GrantedThrough,
bool IsExternalUser, bool IsHighPrivilege,
IReadOnlyList<LocationInfo> Locations)
{
public int LocationCount => Locations.Count;
}
Existing toggleGroup JS (reuse as-is, already in BuildHtml inline JS):
function toggleGroup(id) {
var rows = document.querySelectorAll('tr[data-group="' + id + '"]');
var isHidden = rows.length > 0 && rows[0].style.display === 'none';
rows.forEach(function(r) { r.style.display = isHidden ? '' : 'none'; });
}
Consolidated HTML column layout (from RESEARCH.md Pattern 4):
| Column | Source Field |
|---|---|
| User | UserDisplayName (+ Guest badge if IsExternalUser) |
| Permission Level | PermissionLevel (+ high-priv icon if IsHighPrivilege) |
| Access Type | badge from AccessType |
| Granted Through | GrantedThrough |
| Sites | inline title OR [N sites] badge + expandable sub-list |
2. At the very beginning of `BuildHtml`, after the stats computation block, add an early-return branch:
```csharp
if (mergePermissions)
{
var consolidated = PermissionConsolidator.Consolidate(entries);
return BuildConsolidatedHtml(consolidated, entries, branding);
}
```
Leave the ENTIRE existing code path below this branch COMPLETELY UNTOUCHED. Not a single character change.
3. Create a private `BuildConsolidatedHtml` method that builds the consolidated HTML report:
- Reuse the same HTML shell (DOCTYPE, head, CSS, header, stats section, user summary cards) from the existing `BuildHtml` — extract the stats from `entries` (the original flat list) for accurate counts.
- Include the existing `toggleGroup()` and `toggleView()` JS functions (copy from existing inline JS).
- **OMIT the "By Site" button** from the view toggle bar — only render the "By User" button (or omit the view toggle entirely since there's only one view).
- **OMIT the `view-site` div** and its by-site table entirely.
- Render a single by-user table with columns: User, Permission Level, Access Type, Granted Through, Sites.
- Group consolidated entries by UserLogin (similar to existing user grouping pattern with `ugrp{n}` group headers).
- For each `ConsolidatedPermissionEntry` row:
- **Sites column — 1 location:** Render `entry.Locations[0].SiteTitle` as plain text.
- **Sites column — 2+ locations:** Render `<span class="badge" onclick="toggleGroup('loc{locIdx}')" style="cursor:pointer">{entry.LocationCount} sites</span>`. Immediately after the main `<tr>`, emit hidden sub-rows:
```html
<tr data-group="loc{locIdx}" style="display:none">
<td colspan="5" style="padding-left:2em">
<a href="{loc.SiteUrl}">{loc.SiteTitle}</a>
</td>
</tr>
```
- Use a SEPARATE counter `int locIdx = 0` for location group IDs, distinct from user group counter `int grpIdx = 0` (RESEARCH.md Pitfall 2).
- Apply the same CSS classes: `.guest-badge` for external users, `.high-priv` for high-privilege rows, `.badge` for access type badges.
- Include the same search/filter JS if present in the existing template.
4. Change `WriteAsync` signature to add `bool mergePermissions = false` after `ct` and before `branding`:
```csharp
public async Task WriteAsync(IReadOnlyList<UserAccessEntry> entries, string filePath, CancellationToken ct, bool mergePermissions = false, ReportBranding? branding = null)
```
Pass `mergePermissions` through to `BuildHtml`:
```csharp
var html = BuildHtml(entries, mergePermissions, branding);
```
5. In `UserAccessAuditViewModel.cs`, update the `ExportHtmlAsync` call site (line ~526):
Change: `await _htmlExportService.WriteAsync(Results, dialog.FileName, CancellationToken.None, branding);`
To: `await _htmlExportService.WriteAsync(Results, dialog.FileName, CancellationToken.None, MergePermissions, branding);`
6. Add test methods in `UserAccessHtmlExportServiceTests.cs`:
- **RPT-03-b test:** Capture `BuildHtml(testEntries)` output (old signature), then verify `BuildHtml(testEntries, mergePermissions: false)` produces identical string.
- **RPT-03-c test:** `BuildHtml(testEntries, mergePermissions: true)` contains "Sites" column header and consolidated row content.
- **RPT-03-d test:** Create test data with 2+ entries sharing the same consolidation key. Verify output contains `onclick="toggleGroup('loc` and `data-group="loc` patterns.
- **RPT-03-e test:** `BuildHtml(testEntries, mergePermissions: true)` does NOT contain `btn-site` or `view-site`.
- Use 3-4 UserAccessEntry test rows where 2 share the same key (same UserLogin+PermissionLevel+AccessType+GrantedThrough but different sites).
CRITICAL ANTI-PATTERNS:
- Do NOT modify any line of the existing non-consolidated code path in BuildHtml. The early-return branch guarantees isolation.
- Do NOT reuse the `ugrp` counter for location groups — use `loc{locIdx}` with its own counter.
- Do NOT forget to pass mergePermissions through WriteAsync to BuildHtml (Pitfall 3).
cd "C:/Users/dev/Documents/projets/Sharepoint" && dotnet test --filter "FullyQualifiedName~UserAccessHtmlExportServiceTests" --no-restore -v q 2>&1 | tail -10
HTML export with mergePermissions=false is byte-identical to pre-toggle output. HTML export with mergePermissions=true renders consolidated rows with Sites column, expandable location sub-lists for 2+ locations, and omits the by-site view. All tests pass.
Task 2: Full solution build and test suite verification
1. Run `dotnet build` on the entire solution to verify zero errors and zero warnings.
2. Run `dotnet test` to verify the full test suite passes — all existing tests plus new Phase 16 tests.
3. Verify test count has increased by at least 4 (RPT-03-b through RPT-03-g from Plans 01 and 02).
4. If any test fails, diagnose and fix. Common issues:
- Existing tests calling `BuildHtml(entries)` still work because `mergePermissions` defaults to `false`.
- Existing tests calling `WriteAsync(entries, path, ct, branding)` — verify the parameter order change doesn't break existing callers. Since `mergePermissions` is now between `ct` and `branding`, check that no existing call site passes `branding` positionally without the new parameter. If so, fix the call site.
- Existing tests calling `WriteSingleFileAsync(entries, path, ct)` still work because `mergePermissions` defaults to `false`.
cd "C:/Users/dev/Documents/projets/Sharepoint" && dotnet test -v q 2>&1 | tail -15
Full solution builds with 0 errors, 0 warnings. All tests pass (existing + new). No regressions.
1. `dotnet build` — 0 errors, 0 warnings
2. `dotnet test --filter "FullyQualifiedName~UserAccessHtmlExportServiceTests"` — all HTML export tests pass
3. `dotnet test` — full suite green, no regressions
4. Manual spot-check: `BuildHtml(entries, false)` output matches `BuildHtml(entries)` character-for-character
<success_criteria>
- HTML consolidated path renders expandable [N sites] badges with toggleGroup integration
- HTML non-consolidated path is byte-identical to pre-Phase-16 output
- By-site view is suppressed when consolidation is ON
- ViewModel wiring passes MergePermissions to WriteAsync
- Full test suite passes with no regressions </success_criteria>