@page "/permissions" @attribute [Authorize] @inject IUserSessionService Session @inject ISessionManager SessionMgr @inject IElevationCoordinator Elevation @inject IPermissionsService PermSvc @inject CsvExportService CsvExport @inject HtmlExportService HtmlExport @inject WebExportService WebExport @inject IAuditService Audit @rendermode InteractiveServer

Permissions Audit

@if (!Session.HasProfile) { return; }
Scan Options
@if (_running) { }
@if (!string.IsNullOrEmpty(_error)) {
@_error
} @if (_results.Count > 0) {
Results @_results.Count
@foreach (var r in _results.Take(500)) { }
Type Title Users Permission Granted Through
@r.ObjectType @r.Title @r.Users @r.PermissionLevels @r.GrantedThrough
@if (_results.Count > 500) {
Showing first 500 of @_results.Count rows. Export for full results.
}
} @code { private List _sites = new(); private bool _includeInherited, _includeSubsites; private bool _scanFolders = true; private int _folderDepth = 1; private bool _running; private string _status = string.Empty; private string _error = string.Empty; private int _current, _total; private List _results = new(); private List<(string Label, IReadOnlyList Results)> _bySite = new(); private ReportMergeMode _mergeMode = ReportMergeMode.SingleMerged; private CancellationTokenSource? _cts; private async Task RunScan() { _error = string.Empty; _results = new(); _bySite = new(); _running = true; _cts = new CancellationTokenSource(); if (_sites.Count == 0) { _error = "Please select at least one site."; _running = false; return; } var progress = new Progress(p => { _status = p.Message; _current = p.Current; _total = p.Total; InvokeAsync(StateHasChanged); }); try { var opts = new ScanOptions(_includeInherited, _scanFolders, _folderDepth, _includeSubsites); var bySite = new List<(string, IReadOnlyList)>(); var flat = new List(); int i = 0; foreach (var site in _sites) { _cts.Token.ThrowIfCancellationRequested(); _status = $"Scanning {site.Title} ({++i}/{_sites.Count})…"; await InvokeAsync(StateHasChanged); var entries = await Elevation.RunAsync(async c => { var ctx = await SessionMgr.GetOrCreateContextAsync(site.Url, Session.CurrentProfile!, c); return await PermSvc.ScanSiteAsync(ctx, opts, progress, c); }, _cts.Token); bySite.Add((site.Title, entries)); flat.AddRange(entries); } _bySite = bySite; _results = flat; _status = $"Scan complete: {_results.Count} entries across {_sites.Count} site(s)."; await Audit.LogAsync("PermissionsScan", Session.CurrentProfile?.Name ?? "", _sites.Select(s => s.Url), $"{_results.Count} entries; inherited={_includeInherited} folders={_scanFolders} depth={_folderDepth} subsites={_includeSubsites}"); } catch (OperationCanceledException) { _status = "Cancelled."; } catch (Exception ex) { _error = ex.Message; } finally { _running = false; await InvokeAsync(StateHasChanged); } } private void Cancel() => _cts?.Cancel(); private async Task ExportCsv() { var ts = DateTime.Now.ToString("yyyyMMdd_HHmmss"); var output = ReportMergeHelper.Build(_bySite, _mergeMode, "permissions", ts, ReportFormat.Csv, rs => CsvExport.BuildCsv(rs)); await WebExport.DownloadBytesAsync(output.Bytes, output.FileName, output.Mime); } private async Task ExportHtml() { var ts = DateTime.Now.ToString("yyyyMMdd_HHmmss"); var output = ReportMergeHelper.Build(_bySite, _mergeMode, "permissions", ts, ReportFormat.Html, rs => HtmlExport.BuildHtml(rs, Session.CurrentBranding)); await WebExport.DownloadBytesAsync(output.Bytes, output.FileName, output.Mime); } }