feat(18-01): models, SettingsService, OwnershipElevationService + tests
- AppSettings.AutoTakeOwnership bool property defaulting to false - PermissionEntry.WasAutoElevated optional param (default false, last position) - SettingsService.SetAutoTakeOwnershipAsync persists toggle - IOwnershipElevationService interface + OwnershipElevationService wrapping Tenant.SetSiteAdmin - SettingsViewModel.AutoTakeOwnership property loads and persists via SetAutoTakeOwnershipAsync - DI registration in App.xaml.cs (Phase 18 section) - 8 new tests: models, persistence, service, viewmodel
This commit is contained in:
8
SharepointToolbox/Services/IOwnershipElevationService.cs
Normal file
8
SharepointToolbox/Services/IOwnershipElevationService.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Microsoft.SharePoint.Client;
|
||||
|
||||
namespace SharepointToolbox.Services;
|
||||
|
||||
public interface IOwnershipElevationService
|
||||
{
|
||||
Task ElevateAsync(ClientContext tenantAdminCtx, string siteUrl, string loginName, CancellationToken ct);
|
||||
}
|
||||
14
SharepointToolbox/Services/OwnershipElevationService.cs
Normal file
14
SharepointToolbox/Services/OwnershipElevationService.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Microsoft.Online.SharePoint.TenantAdministration;
|
||||
using Microsoft.SharePoint.Client;
|
||||
|
||||
namespace SharepointToolbox.Services;
|
||||
|
||||
public class OwnershipElevationService : IOwnershipElevationService
|
||||
{
|
||||
public async Task ElevateAsync(ClientContext tenantAdminCtx, string siteUrl, string loginName, CancellationToken ct)
|
||||
{
|
||||
var tenant = new Tenant(tenantAdminCtx);
|
||||
tenant.SetSiteAdmin(siteUrl, loginName, isSiteAdmin: true);
|
||||
await tenantAdminCtx.ExecuteQueryAsync();
|
||||
}
|
||||
}
|
||||
@@ -36,4 +36,11 @@ public class SettingsService
|
||||
settings.DataFolder = path;
|
||||
await _repository.SaveAsync(settings);
|
||||
}
|
||||
|
||||
public async Task SetAutoTakeOwnershipAsync(bool enabled)
|
||||
{
|
||||
var settings = await _repository.LoadAsync();
|
||||
settings.AutoTakeOwnership = enabled;
|
||||
await _repository.SaveAsync(settings);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user