Skip to content

Commit

Permalink
Merge branch 'test'
Browse files Browse the repository at this point in the history
  • Loading branch information
neophyte57 committed Sep 23, 2024
2 parents df5ec40 + 5651988 commit 2268e38
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions prime-dotnet-webapi/Controllers/ProvisionerAccessController.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -174,16 +177,26 @@ public async Task<ActionResult> GetGpid()
[ProducesResponseType(typeof(ApiResultResponse<GpidDetailLookup>), StatusCodes.Status200OK)]
public async Task<ActionResult> 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
/// <summary>
/// Gets the enrollee licence information by providing GPID, Firstname, Lastname and Care Setting code.
Expand Down Expand Up @@ -274,5 +287,25 @@ private static string SerializeObjectForLog(object obj)
};
return JsonConvert.SerializeObject(obj, serializerSettings);
}

/// <summary>
/// Translate given <paramref name="authorizedParty"/> to something PRIME administrator would understand
/// </summary>
/// <param name="authorizedParty"></param>
/// <returns></returns>
private string TranslateAuthorizedParty(string authorizedParty)
{
switch (authorizedParty)
{
case "PRIME-POS-GPID":
return "Medinet";
case "PRIME-APPLICATION-LOCAL":
return "PRIME (testing in `dev`)";
case "PRIME-APPLICATION-TEST":
return "PRIME (testing in `test`)";
default:
return "N/A";
}
}
}
}
}

0 comments on commit 2268e38

Please sign in to comment.