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:
@@ -100,7 +100,7 @@ public class DeveloperApplicationService
|
|||||||
{
|
{
|
||||||
var userId = authResult.GetProperty("user").GetProperty("id").GetString();
|
var userId = authResult.GetProperty("user").GetProperty("id").GetString();
|
||||||
var ticketResult = await ticketResponse.Content.ReadFromJsonAsync<JsonElement>();
|
var ticketResult = await ticketResponse.Content.ReadFromJsonAsync<JsonElement>();
|
||||||
var ticketId = ticketResult.GetProperty("id").GetInt32();
|
var ticketId = ticketResult.GetProperty("id").GetString();
|
||||||
|
|
||||||
var applicationPayload = new
|
var applicationPayload = new
|
||||||
{
|
{
|
||||||
@@ -110,7 +110,7 @@ public class DeveloperApplicationService
|
|||||||
email = application.Email,
|
email = application.Email,
|
||||||
desiredUsername = application.DesiredUsername,
|
desiredUsername = application.DesiredUsername,
|
||||||
timezone = application.Timezone,
|
timezone = application.Timezone,
|
||||||
appliedRole = (int)application.Role,
|
appliedRole = application.Role.ToString(),
|
||||||
platforms = application.Platforms,
|
platforms = application.Platforms,
|
||||||
skills = application.Skills ?? "",
|
skills = application.Skills ?? "",
|
||||||
motivation = application.Motivation,
|
motivation = application.Motivation,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Net.Http.Json;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
@@ -33,12 +34,70 @@ public class ProvisioningService
|
|||||||
results.Add($"Mailcow: {mailMsg}");
|
results.Add($"Mailcow: {mailMsg}");
|
||||||
if (!mailOk) allSuccess = false;
|
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);
|
var summary = string.Join("; ", results);
|
||||||
_logger.LogInformation("Provisioning for {Username} (ticket {TicketId}): {Summary}", username, ticketId, summary);
|
_logger.LogInformation("Provisioning for {Username} (ticket {TicketId}): {Summary}", username, ticketId, summary);
|
||||||
|
|
||||||
return (allSuccess, 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)
|
public async Task<(bool Success, string Message)> CreateSilverDeskUserAsync(string username, string email, string fullName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|||||||
Reference in New Issue
Block a user