From 024d9fb154310d7f1246738a9d35565a72b3ccb4 Mon Sep 17 00:00:00 2001 From: Alan Leung Date: Wed, 18 Sep 2024 14:28:19 -0600 Subject: [PATCH 1/2] Initial commit (#2591) --- .../ProvisionerAccessController.cs | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/prime-dotnet-webapi/Controllers/ProvisionerAccessController.cs b/prime-dotnet-webapi/Controllers/ProvisionerAccessController.cs index aa07d3403b..4a5f08b1d8 100644 --- a/prime-dotnet-webapi/Controllers/ProvisionerAccessController.cs +++ b/prime-dotnet-webapi/Controllers/ProvisionerAccessController.cs @@ -1,19 +1,22 @@ using System; using System.Linq; using System.Collections.Generic; +using System.IdentityModel.Tokens.Jwt; using System.Threading.Tasks; using AutoMapper; +using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using Serilog; using Prime.Configuration.Auth; using Prime.Models; using Prime.Models.Api; using Prime.Services; using Prime.HttpClients.Mail; -using Newtonsoft.Json.Serialization; namespace Prime.Controllers { @@ -174,16 +177,26 @@ public async Task GetGpid() [ProducesResponseType(typeof(ApiResultResponse), StatusCodes.Status200OK)] public async Task GetGpidDetail() { + string accessToken = await HttpContext.GetTokenAsync("access_token"); + JwtPayload jwtPayload = new JwtSecurityToken(accessToken).Payload; + string authorizedParty = jwtPayload.Azp; + var logId = await _vendorAPILogService.CreateLogAsync(authorizedParty, Request.Path.Value, null); + var result = new GpidDetailLookup(); var enrollee = await _enrolleeService.GetActiveGpidDetailAsync(User.GetPrimeUsername()); if (enrollee != null) { - return Ok(_mapper.Map(enrollee, result)); + _mapper.Map(enrollee, result); + await _vendorAPILogService.UpdateLogAsync(logId, SerializeObjectForLog(result)); + var enrolleeStub = await _enrolleeService.GetEnrolleeStubAsync(User.GetPrimeUsername()); + await _businessEventService.CreateEnrolleeEventAsync(enrolleeStub.Id, + $"First-time provisioning API (aka GetGpidDetail) returned data to calling entity {TranslateAuthorizedParty(authorizedParty)}"); + return Ok(result); } + return Ok(enrollee); } - // POST: api/provisioner-access/gpid-lookup /// /// Gets the enrollee licence information by providing GPID, Firstname, Lastname and Care Setting code. @@ -274,5 +287,23 @@ private static string SerializeObjectForLog(object obj) }; return JsonConvert.SerializeObject(obj, serializerSettings); } + + /// + /// Translate given to something PRIME administrator would understand + /// + /// + /// + private string TranslateAuthorizedParty(string authorizedParty) + { + switch (authorizedParty) + { + case "PRIME-POS-GPID": + return "Medinet"; + case "PRIME-APPLICATION-LOCAL": + return "PRIME (testing)"; + default: + return "N/A"; + } + } } -} +} \ No newline at end of file From 3b988c3966e6b56f5b78ff9f1160d444971c4a8f Mon Sep 17 00:00:00 2001 From: Alan Leung Date: Thu, 19 Sep 2024 16:58:03 -0600 Subject: [PATCH 2/2] PRIME-2789 - Adjustments based on demo feedback (#2592) * Initial commit * Adjustments based on demo feedback * Change to cause build --------- Co-authored-by: Jack Wong <108699279+bergomi02@users.noreply.github.com> --- .../Controllers/ProvisionerAccessController.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/prime-dotnet-webapi/Controllers/ProvisionerAccessController.cs b/prime-dotnet-webapi/Controllers/ProvisionerAccessController.cs index 4a5f08b1d8..00f44d12c1 100644 --- a/prime-dotnet-webapi/Controllers/ProvisionerAccessController.cs +++ b/prime-dotnet-webapi/Controllers/ProvisionerAccessController.cs @@ -190,7 +190,7 @@ public async Task GetGpidDetail() await _vendorAPILogService.UpdateLogAsync(logId, SerializeObjectForLog(result)); var enrolleeStub = await _enrolleeService.GetEnrolleeStubAsync(User.GetPrimeUsername()); await _businessEventService.CreateEnrolleeEventAsync(enrolleeStub.Id, - $"First-time provisioning API (aka GetGpidDetail) returned data to calling entity {TranslateAuthorizedParty(authorizedParty)}"); + $"\"First-Time Provisioning API\" (aka GetGpidDetail) returned data to calling entity {TranslateAuthorizedParty(authorizedParty)}"); return Ok(result); } @@ -289,7 +289,7 @@ private static string SerializeObjectForLog(object obj) } /// - /// Translate given to something PRIME administrator would understand + /// Translate given to something PRIME administrator would understand /// /// /// @@ -300,7 +300,9 @@ private string TranslateAuthorizedParty(string authorizedParty) case "PRIME-POS-GPID": return "Medinet"; case "PRIME-APPLICATION-LOCAL": - return "PRIME (testing)"; + return "PRIME (testing in `dev`)"; + case "PRIME-APPLICATION-TEST": + return "PRIME (testing in `test`)"; default: return "N/A"; }