@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 @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 string _siteUrl = string.Empty; 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 CancellationTokenSource? _cts; private async Task RunScan() { _error = string.Empty; _results.Clear(); _running = true; _cts = new CancellationTokenSource(); var siteUrl = string.IsNullOrWhiteSpace(_siteUrl) ? Session.CurrentProfile!.TenantUrl : _siteUrl.Trim(); 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); _results = (await Elevation.RunAsync(async c => { var ctx = await SessionMgr.GetOrCreateContextAsync(siteUrl, Session.CurrentProfile!, c); return await PermSvc.ScanSiteAsync(ctx, opts, progress, c); }, _cts.Token)).ToList(); _status = $"Scan complete: {_results.Count} entries found."; } 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 csv = CsvExport.BuildCsv(_results); await WebExport.DownloadCsvAsync(csv, $"permissions_{DateTime.Now:yyyyMMdd_HHmmss}.csv"); } private async Task ExportHtml() { var html = HtmlExport.BuildHtml(_results); await WebExport.DownloadHtmlAsync(html, $"permissions_{DateTime.Now:yyyyMMdd_HHmmss}.html"); } }