fix(developers): fix application record creation and approval flow
All checks were successful
Build and Deploy / deploy (push) Successful in 18s
All checks were successful
Build and Deploy / deploy (push) Successful in 18s
Fix two bugs preventing developer applications from appearing in SilverDESK: 1. Application creation payload used wrong types - ticketId was parsed as int (GetInt32) but SilverDESK expects a Guid string, and appliedRole was cast to int but the DTO expects "Tester"/"Developer" strings. 2. Approval provisioning now updates the DeveloperApplication record in SilverDESK after Mattermost/Mailcow provisioning, setting status to Approved and the correct provisioning flags. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
@@ -33,12 +34,70 @@ public class ProvisioningService
|
||||
results.Add($"Mailcow: {mailMsg}");
|
||||
if (!mailOk) allSuccess = false;
|
||||
|
||||
// 3. Update the DeveloperApplication record in SilverDESK
|
||||
var (updateOk, updateMsg) = await UpdateApplicationStatusAsync(ticketId, mmOk, mailOk);
|
||||
results.Add($"Application record: {updateMsg}");
|
||||
if (!updateOk) allSuccess = false;
|
||||
|
||||
var summary = string.Join("; ", results);
|
||||
_logger.LogInformation("Provisioning for {Username} (ticket {TicketId}): {Summary}", username, ticketId, summary);
|
||||
|
||||
return (allSuccess, summary);
|
||||
}
|
||||
|
||||
private async Task<(bool Success, string Message)> UpdateApplicationStatusAsync(
|
||||
string ticketId, bool mattermostProvisioned, bool mailcowProvisioned)
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = _httpClientFactory.CreateClient("SilverDesk");
|
||||
|
||||
// Look up the application by ticketId
|
||||
var lookupResponse = await client.GetAsync($"/api/developer-program/applications?ticketId={ticketId}");
|
||||
if (!lookupResponse.IsSuccessStatusCode)
|
||||
{
|
||||
var body = await lookupResponse.Content.ReadAsStringAsync();
|
||||
_logger.LogWarning("Failed to look up application by ticket {TicketId}: {Status} {Body}",
|
||||
ticketId, lookupResponse.StatusCode, body);
|
||||
return (false, $"Lookup failed ({lookupResponse.StatusCode})");
|
||||
}
|
||||
|
||||
var apps = await lookupResponse.Content.ReadFromJsonAsync<JsonElement>();
|
||||
if (apps.GetArrayLength() == 0)
|
||||
{
|
||||
_logger.LogWarning("No application found for ticket {TicketId}", ticketId);
|
||||
return (false, "No application found for ticket");
|
||||
}
|
||||
|
||||
var appId = apps[0].GetProperty("id").GetString();
|
||||
|
||||
// Update the application status to Approved with provisioning flags
|
||||
var updatePayload = new
|
||||
{
|
||||
status = 1, // ApplicationStatus.Approved
|
||||
mattermostProvisioned,
|
||||
mailcowProvisioned
|
||||
};
|
||||
|
||||
var updateResponse = await client.PutAsJsonAsync($"/api/developer-program/applications/{appId}", updatePayload);
|
||||
if (updateResponse.IsSuccessStatusCode)
|
||||
{
|
||||
_logger.LogInformation("Application {AppId} updated to Approved for ticket {TicketId}", appId, ticketId);
|
||||
return (true, "Updated to Approved");
|
||||
}
|
||||
|
||||
var updateBody = await updateResponse.Content.ReadAsStringAsync();
|
||||
_logger.LogWarning("Failed to update application {AppId}: {Status} {Body}",
|
||||
appId, updateResponse.StatusCode, updateBody);
|
||||
return (false, $"Update failed ({updateResponse.StatusCode})");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error updating application status for ticket {TicketId}", ticketId);
|
||||
return (false, $"Error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(bool Success, string Message)> CreateSilverDeskUserAsync(string username, string email, string fullName)
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user