From e69bfe2e31712fa7036169863767ad5b73e89f41 Mon Sep 17 00:00:00 2001 From: Simen Rekkedal <61084786+simen-rekkedal@users.noreply.github.com> Date: Tue, 9 Jan 2024 16:48:59 +0100 Subject: [PATCH] Sr integration test2 (#141) * get partyId from context instead of header * changed SystemUserDescriptor to reflect recent design changes * New API endpoint for Default Rights --- .../SystemRegister/DefaultRightsDTO.cs | 8 ++++++++ .../SystemUsers/SystemUserDescriptor.cs | 6 ------ .../SystemUsers/SystemUserClient.cs | 3 --- .../Mocks/SystemUsers/SystemUserClientMock.cs | 1 - .../Clients/SystemUserClientTest.cs | 4 ++-- .../Controllers/SystemRegisterController.cs | 15 ++++++++++++++- .../Controllers/SystemUserController.cs | 18 +++++++++++------- 7 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Core/SystemRegister/DefaultRightsDTO.cs diff --git a/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Core/SystemRegister/DefaultRightsDTO.cs b/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Core/SystemRegister/DefaultRightsDTO.cs new file mode 100644 index 00000000..70d8b33d --- /dev/null +++ b/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Core/SystemRegister/DefaultRightsDTO.cs @@ -0,0 +1,8 @@ +namespace Altinn.Authentication.UI.Core.SystemRegister +{ + public class DefaultRightsDTO + { + public string Right { get; set; } = string.Empty; + public string ServiceProvider { get; set; } = string.Empty; + } +} diff --git a/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Core/SystemUsers/SystemUserDescriptor.cs b/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Core/SystemUsers/SystemUserDescriptor.cs index 1e01fea5..eb3043df 100644 --- a/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Core/SystemUsers/SystemUserDescriptor.cs +++ b/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Core/SystemUsers/SystemUserDescriptor.cs @@ -11,12 +11,6 @@ public class SystemUserDescriptor /// public string? IntegrationTitle { get; set; } - /// - /// Either set by the end-user as instructions to self, - /// or provided by the SystemType as extra info - /// - public string? Description { get; set; } - /// /// The actual chosen systemType that this SystemUser /// creates an integration / delegation for diff --git a/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Integration/SystemUsers/SystemUserClient.cs b/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Integration/SystemUsers/SystemUserClient.cs index 912cc28b..2816963d 100644 --- a/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Integration/SystemUsers/SystemUserClient.cs +++ b/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Integration/SystemUsers/SystemUserClient.cs @@ -20,7 +20,6 @@ private static SystemUserReal MapDescriptorToSystemUserReal(SystemUserDescriptor ClientId = Guid.NewGuid().ToString(), SystemType = sysdescr.SelectedSystemType, Title = sysdescr.IntegrationTitle, - Description = sysdescr.Description, Created = DateTime.UtcNow.Date.ToString() }; @@ -66,8 +65,6 @@ public SystemUserClient(HttpClient httpClient) } return null; - - } public async Task DeleteSystemUserReal(Guid id, CancellationToken cancellationToken = default) diff --git a/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Mocks/Mocks/SystemUsers/SystemUserClientMock.cs b/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Mocks/Mocks/SystemUsers/SystemUserClientMock.cs index 84c1a6b0..dd602ccc 100644 --- a/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Mocks/Mocks/SystemUsers/SystemUserClientMock.cs +++ b/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Mocks/Mocks/SystemUsers/SystemUserClientMock.cs @@ -62,7 +62,6 @@ private static SystemUserReal MapDescriptorToSystemUserReal(SystemUserDescriptor ClientId = Guid.NewGuid().ToString(), SystemType = sysdescr.SelectedSystemType, Title = sysdescr.IntegrationTitle, - Description = sysdescr.Description, Created = DateTime.UtcNow.Date.ToString() }; diff --git a/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Tests/Clients/SystemUserClientTest.cs b/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Tests/Clients/SystemUserClientTest.cs index c5014c36..582f8238 100644 --- a/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Tests/Clients/SystemUserClientTest.cs +++ b/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI.Tests/Clients/SystemUserClientTest.cs @@ -10,11 +10,11 @@ namespace Altinn.Authentication.UI.Tests.Clients; /// Needs a running instance of the Authentication Component on localhost on port 44377 /// [Collection ("SystemUserClient Integration Test vs Authentication Component")] -public class SystemUserClientTest : IClassFixture> +public class SystemUserClientIntegrationTest : IClassFixture> { private readonly ISystemUserClient _systemUserClient; - public SystemUserClientTest() + public SystemUserClientIntegrationTest() { _systemUserClient = new SystemUserClient( new HttpClient{BaseAddress = new UriBuilder("https://localhost:44377/").Uri}); diff --git a/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI/Controllers/SystemRegisterController.cs b/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI/Controllers/SystemRegisterController.cs index 2aae3129..6389b232 100644 --- a/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI/Controllers/SystemRegisterController.cs +++ b/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI/Controllers/SystemRegisterController.cs @@ -24,8 +24,21 @@ public async Task GetListOfRegisteredSystems(CancellationToken can { List lista = new(); - lista.AddRange( await _systemRegisterService.GetListRegSys(cancellationToken)); + lista.AddRange(await _systemRegisterService.GetListRegSys(cancellationToken)); return Ok(lista); } + + [HttpGet("product/{productId}")] + public async Task GetDefaultRightsForProductName(string productId, CancellationToken cancellationToken = default) + { + List lista = new(); + DefaultRightsDTO l1 = new() { Right = "Mva Registrering", ServiceProvider = "Skatteetaten" }; + DefaultRightsDTO l2 = new() { Right = "Lønns Rapportering", ServiceProvider = "Skatteetaten" }; + DefaultRightsDTO l3 = new() { Right = "Lakselus Rapportering", ServiceProvider = "Mattilsynet" }; + lista.Add(l1); + lista.Add(l2); + lista.Add(l3); + return Ok(lista); + } } diff --git a/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI/Controllers/SystemUserController.cs b/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI/Controllers/SystemUserController.cs index 2cf63af1..7caefc6c 100644 --- a/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI/Controllers/SystemUserController.cs +++ b/bff/src/Altinn.Authentication.UI/Altinn.Authentication.UI/Controllers/SystemUserController.cs @@ -1,4 +1,5 @@ -using Altinn.Authentication.UI.Core.SystemUsers; +using Altinn.Authentication.UI.Core.Authentication; +using Altinn.Authentication.UI.Core.SystemUsers; using Altinn.Authentication.UI.Filters; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -17,13 +18,15 @@ namespace Altinn.Authentication.UI.Controllers; public class SystemUserController : ControllerBase { ISystemUserService _systemUserService; + IHttpContextAccessor _httpContextAccessor; /// /// Constructor for /// - public SystemUserController(ISystemUserService systemUserService) + public SystemUserController(ISystemUserService systemUserService, IHttpContextAccessor httpContextAccessor) { - _systemUserService = systemUserService; + _systemUserService = systemUserService; + _httpContextAccessor = httpContextAccessor; } @@ -88,9 +91,11 @@ public async Task UploadCertificate([FromForm] IFormFile file, [Fr //[Authorize] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - [HttpPost("{partyId}")] - public async Task Post(int partyId ,[FromBody] SystemUserDescriptor newSystemUserDescriptor, CancellationToken cancellationToken = default) + [HttpPost] + public async Task Post([FromBody] SystemUserDescriptor newSystemUserDescriptor, CancellationToken cancellationToken = default) { + int partyId = AuthenticationHelper.GetUsersPartyId( _httpContextAccessor.HttpContext!); + var usr = await _systemUserService.PostNewSystemUserDescriptor(partyId, newSystemUserDescriptor, cancellationToken); if (usr is not null) { @@ -105,8 +110,7 @@ public async Task Post(int partyId ,[FromBody] SystemUserDescripto [HttpPut("{id}")] public async void Put(Guid id, [FromBody] SystemUserDescriptor modifiedSystemUser, CancellationToken cancellationToken = default) { - if (modifiedSystemUser.IntegrationTitle is not null) await _systemUserService.ChangeSystemUserTitle(modifiedSystemUser.IntegrationTitle, id, cancellationToken); - if (modifiedSystemUser.Description is not null) await _systemUserService.ChangeSystemUserTitle(modifiedSystemUser.Description, id, cancellationToken); + if (modifiedSystemUser.IntegrationTitle is not null) await _systemUserService.ChangeSystemUserTitle(modifiedSystemUser.IntegrationTitle, id, cancellationToken); if (modifiedSystemUser.SelectedSystemType is not null) await _systemUserService.ChangeSystemUserProduct(modifiedSystemUser.SelectedSystemType, id, cancellationToken); }