Wire auto-elevate ownership across all SharePoint operations
The "Auto-elevate ownership when permission scan is denied" setting was dead code: the toggle was persisted but never read, the audit flow never passed its onAccessDenied callback, and EnrichException wrapped every CSOM error (including ServerUnauthorizedAccessException) into a generic InvalidOperationException so the access-denied catch could never match. Centralize elevation instead of per-call-site callbacks: - Throw typed SharePointAccessDeniedException from EnrichException on access-denied, preserving the failing site URL and enriched diagnostic. - Add scoped IElevationCoordinator that catches it, and when AutoTakeOwnership is enabled takes site-collection admin via the tenant admin endpoint and retries the operation once. Per-site dedupe prevents loops; admin-host denials are not treated as ownership issues. Retry is safe because each wrapped operation closure re-issues its own CSOM loads. - Wrap all site-scoped operations (Storage, Permissions, Duplicates, Search, VersionCleanup, FolderStructure, BulkMembers, FileTransfer, Templates) and the UserAccessAudit per-site scan in the coordinator. - Drop the unused onAccessDenied parameter from IUserAccessAuditService. Elevation still requires SharePoint tenant admin rights on the signed-in account; the coordinator surfaces a clear message when that is missing. Also keeps the prior StorageService change that avoids admin-gated folder.StorageMetrics (403 for delegated non-admin tokens). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
namespace SharepointToolbox.Web.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Wraps a SharePoint operation so that, when the "Auto-elevate ownership when permission
|
||||
/// scan is denied" setting is enabled, an access-denied failure triggers taking
|
||||
/// site-collection admin ownership of the failing site and re-running the operation once.
|
||||
/// When the setting is off (or elevation is impossible/unsuccessful) the original
|
||||
/// access-denied error propagates unchanged.
|
||||
/// </summary>
|
||||
public interface IElevationCoordinator
|
||||
{
|
||||
Task<T> RunAsync<T>(Func<CancellationToken, Task<T>> operation, CancellationToken ct);
|
||||
Task RunAsync(Func<CancellationToken, Task> operation, CancellationToken ct);
|
||||
}
|
||||
Reference in New Issue
Block a user