mirror of
https://github.com/okieselbach/AutopilotMonitor.git
synced 2026-10-24 04:32:32 +00:00
Auto-promote tenant requester as TenantAdmin on preview approval
When a Galactic Admin approves a tenant for Private Preview, the user who originally signed up (stored in TenantConfiguration.UpdatedBy) is automatically added as TenantAdmin. This avoids manual admin assignment after approval. Also fixes GitHub repository link in the portal footer. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,15 +18,21 @@ public class PreviewWhitelistFunction
|
||||
private readonly ILogger<PreviewWhitelistFunction> _logger;
|
||||
private readonly PreviewWhitelistService _previewWhitelistService;
|
||||
private readonly GalacticAdminService _galacticAdminService;
|
||||
private readonly TenantConfigurationService _tenantConfigurationService;
|
||||
private readonly TenantAdminsService _tenantAdminsService;
|
||||
|
||||
public PreviewWhitelistFunction(
|
||||
ILogger<PreviewWhitelistFunction> logger,
|
||||
PreviewWhitelistService previewWhitelistService,
|
||||
GalacticAdminService galacticAdminService)
|
||||
GalacticAdminService galacticAdminService,
|
||||
TenantConfigurationService tenantConfigurationService,
|
||||
TenantAdminsService tenantAdminsService)
|
||||
{
|
||||
_logger = logger;
|
||||
_previewWhitelistService = previewWhitelistService;
|
||||
_galacticAdminService = galacticAdminService;
|
||||
_tenantConfigurationService = tenantConfigurationService;
|
||||
_tenantAdminsService = tenantAdminsService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -92,6 +98,48 @@ public class PreviewWhitelistFunction
|
||||
|
||||
_logger.LogInformation("Preview tenant approved: {TenantId} by {Upn}", tenantId, upn);
|
||||
|
||||
// Auto-promote the tenant requester (first user who triggered tenant config creation)
|
||||
// as TenantAdmin if they are not already one.
|
||||
// This ensures whoever signed up doesn't need manual admin assignment after approval.
|
||||
try
|
||||
{
|
||||
var tenantConfig = await _tenantConfigurationService.GetConfigurationAsync(tenantId);
|
||||
var requesterUpn = tenantConfig.UpdatedBy;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(requesterUpn)
|
||||
&& !string.Equals(requesterUpn, "System", StringComparison.OrdinalIgnoreCase)
|
||||
&& !string.Equals(requesterUpn, "System (auto-re-enable)", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var isAlreadyAdmin = await _tenantAdminsService.IsTenantAdminAsync(tenantId, requesterUpn);
|
||||
if (!isAlreadyAdmin)
|
||||
{
|
||||
await _tenantAdminsService.AddTenantAdminAsync(tenantId, requesterUpn, upn!);
|
||||
_logger.LogInformation(
|
||||
"Auto-promoted tenant requester {RequesterUpn} as TenantAdmin for tenant {TenantId} on preview approval by {ApprovedBy}",
|
||||
requesterUpn, tenantId, upn);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation(
|
||||
"Tenant requester {RequesterUpn} is already a TenantAdmin for tenant {TenantId} — skipping auto-promote",
|
||||
requesterUpn, tenantId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogInformation(
|
||||
"No valid tenant requester UPN found in TenantConfiguration for tenant {TenantId} (UpdatedBy: '{UpdatedBy}') — skipping auto-promote",
|
||||
tenantId, requesterUpn ?? "<null>");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Non-fatal: approval already succeeded, admin promotion is best-effort
|
||||
_logger.LogWarning(ex,
|
||||
"Failed to auto-promote tenant requester as TenantAdmin for tenant {TenantId} — approval still succeeded",
|
||||
tenantId);
|
||||
}
|
||||
|
||||
var response = req.CreateResponse(HttpStatusCode.Created);
|
||||
await response.WriteAsJsonAsync(new { message = "Tenant approved for preview", tenantId });
|
||||
return response;
|
||||
|
||||
@@ -550,7 +550,7 @@ export default function Home() {
|
||||
<QuickLink
|
||||
title="GitHub Repository"
|
||||
description="Source code and issue tracking"
|
||||
href="https://github.com/yourusername/autopilot-monitor"
|
||||
href="https://github.com/okieselbach/autopilot-monitor"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user