diff --git a/src/administration/Administration.Service/BusinessLogic/ServiceAccountBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/ServiceAccountBusinessLogic.cs index c25ebd9cfe..52da5b1d05 100644 --- a/src/administration/Administration.Service/BusinessLogic/ServiceAccountBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/ServiceAccountBusinessLogic.cs @@ -338,7 +338,7 @@ public async IAsyncEnumerable GetServiceAccountRolesAsy userRoles, languageShortName ?? Constants.DefaultLanguage)) { - yield return userRole; + yield return new UserRoleWithDescription(userRole.UserRoleId, userRole.UserRoleText, userRole.RoleDescription, userRole.External ? UserRoleType.External : UserRoleType.Internal); } } diff --git a/src/administration/Administration.Service/Models/UserRoleWithDescription.cs b/src/administration/Administration.Service/Models/UserRoleWithDescription.cs new file mode 100644 index 0000000000..a1b2713267 --- /dev/null +++ b/src/administration/Administration.Service/Models/UserRoleWithDescription.cs @@ -0,0 +1,33 @@ +/******************************************************************************** + * Copyright (c) 2022 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Apache License, Version 2.0 which is available at + * https://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ********************************************************************************/ + +using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; +using System.Text.Json.Serialization; + +namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models; + +/// +/// Basic model for user role data needed to display user roles with description. +/// +public record UserRoleWithDescription( + [property: JsonPropertyName("roleId")] Guid UserRoleId, + [property: JsonPropertyName("roleName")] string UserRoleText, + [property: JsonPropertyName("roleDescription")] string? RoleDescription, + [property: JsonPropertyName("roleType")] UserRoleType RoleType +); diff --git a/src/marketplace/Apps.Service/Apps.Service.csproj b/src/marketplace/Apps.Service/Apps.Service.csproj index 084d6c2092..8eabdfba92 100644 --- a/src/marketplace/Apps.Service/Apps.Service.csproj +++ b/src/marketplace/Apps.Service/Apps.Service.csproj @@ -27,6 +27,7 @@ Linux ..\..\.. True + CS1591 diff --git a/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs b/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs index 26cb8b75de..05a99ae157 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/AppReleaseBusinessLogic.cs @@ -527,7 +527,7 @@ private static (Guid AppInstanceId, Guid ClientId, string ClientClientId) GetAnd /// public Task> GetTechnicalUserProfilesForOffer(Guid offerId) => - offerService.GetTechnicalUserProfilesForOffer(offerId, OfferTypeId.APP); + offerService.GetTechnicalUserProfilesForOffer(offerId, OfferTypeId.APP, _settings.DimUserRoles); /// public Task UpdateTechnicalUserProfiles(Guid appId, IEnumerable data) => diff --git a/src/marketplace/Apps.Service/BusinessLogic/AppsSettings.cs b/src/marketplace/Apps.Service/BusinessLogic/AppsSettings.cs index 796595886a..8616d23d0d 100644 --- a/src/marketplace/Apps.Service/BusinessLogic/AppsSettings.cs +++ b/src/marketplace/Apps.Service/BusinessLogic/AppsSettings.cs @@ -234,6 +234,10 @@ public class AppsSettings [Required(AllowEmptyStrings = true)] public string BpnDidResolverUrl { get; set; } = null!; + + [Required] + [DistinctValues("x => x.ClientId")] + public IEnumerable DimUserRoles { get; set; } = null!; } /// diff --git a/src/marketplace/Apps.Service/appsettings.json b/src/marketplace/Apps.Service/appsettings.json index 06e79ce0b2..a55d370940 100644 --- a/src/marketplace/Apps.Service/appsettings.json +++ b/src/marketplace/Apps.Service/appsettings.json @@ -76,7 +76,8 @@ "DeleteDocumentTypeIds": [], "SubmitAppDocumentTypeIds": [], "OfferSubscriptionAddress": "", - "OfferDetailAddress": "" + "OfferDetailAddress": "", + "DimUserRoles": [] }, "Provisioning": { "CentralRealm": "", diff --git a/src/marketplace/Offers.Library/Service/IOfferService.cs b/src/marketplace/Offers.Library/Service/IOfferService.cs index 09ad726b3a..15697e083f 100644 --- a/src/marketplace/Offers.Library/Service/IOfferService.cs +++ b/src/marketplace/Offers.Library/Service/IOfferService.cs @@ -200,8 +200,9 @@ Task CreateOrUpdateOfferSubscriptionAgreementConsentAsync(Guid subscriptionId, /// /// Id of the offer /// Id of the offer type + /// The ExternalUserRoles /// IEnumerable with the technical user profile information - Task> GetTechnicalUserProfilesForOffer(Guid offerId, OfferTypeId offerTypeId); + Task> GetTechnicalUserProfilesForOffer(Guid offerId, OfferTypeId offerTypeId, IEnumerable externalUserRoles); /// /// Creates or updates the technical user profiles diff --git a/src/marketplace/Offers.Library/Service/OfferService.cs b/src/marketplace/Offers.Library/Service/OfferService.cs index d57b49ce3d..d6bd98a8d0 100644 --- a/src/marketplace/Offers.Library/Service/OfferService.cs +++ b/src/marketplace/Offers.Library/Service/OfferService.cs @@ -699,11 +699,14 @@ public async Task DeleteDocumentsAsync(Guid documentId, IEnumerable> GetTechnicalUserProfilesForOffer(Guid offerId, OfferTypeId offerTypeId) + public async Task> GetTechnicalUserProfilesForOffer(Guid offerId, OfferTypeId offerTypeId, IEnumerable externalUserRoles) { var companyId = _identityData.CompanyId; + var userRoles = await portalRepositories.GetInstance().GetUserRoleIdsUntrackedAsync(externalUserRoles) + .ToListAsync() + .ConfigureAwait(false); var result = await portalRepositories.GetInstance() - .GetTechnicalUserProfileInformation(offerId, companyId, offerTypeId).ConfigureAwait(ConfigureAwaitOptions.None); + .GetTechnicalUserProfileInformation(offerId, companyId, offerTypeId, userRoles).ConfigureAwait(ConfigureAwaitOptions.None); if (result == default) { throw new NotFoundException($"Offer {offerId} does not exist"); @@ -714,7 +717,15 @@ public async Task> GetTechnicalUser throw new ForbiddenException($"Company {companyId} is not the providing company"); } - return result.Information; + return result.Information + .Select(x => new TechnicalUserProfileInformation( + x.TechnicalUserProfileId, + x.UserRoles + .Select(ur => new UserRoleInformation( + ur.UserRoleId, + ur.UserRoleText, + ur.External ? UserRoleType.External : UserRoleType.Internal)) + )); } /// diff --git a/src/marketplace/Services.Service/BusinessLogic/ServiceReleaseBusinessLogic.cs b/src/marketplace/Services.Service/BusinessLogic/ServiceReleaseBusinessLogic.cs index 1c0be97985..6d087d4e9e 100644 --- a/src/marketplace/Services.Service/BusinessLogic/ServiceReleaseBusinessLogic.cs +++ b/src/marketplace/Services.Service/BusinessLogic/ServiceReleaseBusinessLogic.cs @@ -257,7 +257,7 @@ public Task DeleteServiceDocumentsAsync(Guid documentId) => /// public Task> GetTechnicalUserProfilesForOffer(Guid offerId) => - _offerService.GetTechnicalUserProfilesForOffer(offerId, OfferTypeId.SERVICE); + _offerService.GetTechnicalUserProfilesForOffer(offerId, OfferTypeId.SERVICE, _settings.DimUserRoles); /// public Task UpdateTechnicalUserProfiles(Guid serviceId, IEnumerable data) => diff --git a/src/marketplace/Services.Service/ServiceSettings.cs b/src/marketplace/Services.Service/ServiceSettings.cs index bcf84edf18..bd8f6af5e7 100644 --- a/src/marketplace/Services.Service/ServiceSettings.cs +++ b/src/marketplace/Services.Service/ServiceSettings.cs @@ -165,6 +165,10 @@ public class ServiceSettings /// [Required(AllowEmptyStrings = false)] public string OfferDetailAddress { get; init; } = null!; + + [Required] + [DistinctValues("x => x.ClientId")] + public IEnumerable DimUserRoles { get; set; } = null!; } public static class ServiceSettingsExtension diff --git a/src/marketplace/Services.Service/appsettings.json b/src/marketplace/Services.Service/appsettings.json index 0b41253028..2ad98828cd 100644 --- a/src/marketplace/Services.Service/appsettings.json +++ b/src/marketplace/Services.Service/appsettings.json @@ -70,7 +70,8 @@ "DeleteDocumentTypeIds": [], "TechnicalUserProfileClient": "", "OfferSubscriptionAddress": "", - "OfferDetailAddress": "" + "OfferDetailAddress": "", + "DimUserRoles": [] }, "Provisioning": { "CentralRealm": "", diff --git a/src/portalbackend/PortalBackend.DBAccess/Models/TechnicalUserProfileInformation.cs b/src/portalbackend/PortalBackend.DBAccess/Models/TechnicalUserProfileInformation.cs index 4015d765f9..2950d4d457 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Models/TechnicalUserProfileInformation.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Models/TechnicalUserProfileInformation.cs @@ -18,9 +18,21 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ +using System.Text.Json.Serialization; + namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; public record TechnicalUserProfileInformation( + [property: JsonPropertyName("technicalUserProfileId")] Guid TechnicalUserProfileId, + [property: JsonPropertyName("userRoles")] IEnumerable UserRoles +); + +public record TechnicalUserProfileInformationTransferData( Guid TechnicalUserProfileId, - IEnumerable UserRoles + IEnumerable UserRoles ); + +public record UserRoleInformationTransferData( + Guid UserRoleId, + string UserRoleText, + bool External); diff --git a/src/portalbackend/PortalBackend.DBAccess/Models/UserRoleData.cs b/src/portalbackend/PortalBackend.DBAccess/Models/UserRoleData.cs index edf9681b12..66eb6c24bc 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Models/UserRoleData.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Models/UserRoleData.cs @@ -32,16 +32,17 @@ public record UserRoleData( /// /// Basic model for user role data needed to display user roles with description. /// -public record UserRoleWithDescription( - [property: JsonPropertyName("roleId")] Guid UserRoleId, - [property: JsonPropertyName("roleName")] string UserRoleText, - [property: JsonPropertyName("roleDescription")] string? RoleDescription, - [property: JsonPropertyName("roleType")] UserRoleType RoleType - ); +public record UserRoleWithDescriptionTransferData( + Guid UserRoleId, + string UserRoleText, + string? RoleDescription, + bool External +); public record UserRoleInformation( [property: JsonPropertyName("roleId")] Guid UserRoleId, - [property: JsonPropertyName("roleName")] string UserRoleText); + [property: JsonPropertyName("roleName")] string UserRoleText, + [property: JsonPropertyName("type")] UserRoleType RoleType); public enum UserRoleType { diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/ITechnicalUserProfileRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/ITechnicalUserProfileRepository.cs index 427006536d..4e2876d4eb 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/ITechnicalUserProfileRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/ITechnicalUserProfileRepository.cs @@ -18,6 +18,7 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Configuration; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Entities; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums; @@ -67,6 +68,7 @@ public interface ITechnicalUserProfileRepository /// Id of the offer /// /// Id of the offertype + /// The external user roles /// List of the technical user profile information - Task<(bool IsUserOfProvidingCompany, IEnumerable Information)> GetTechnicalUserProfileInformation(Guid offerId, Guid usersCompanyId, OfferTypeId offerTypeId); + Task<(bool IsUserOfProvidingCompany, IEnumerable Information)> GetTechnicalUserProfileInformation(Guid offerId, Guid usersCompanyId, OfferTypeId offerTypeId, IEnumerable externalUserRoles); } diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/IUserRolesRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/IUserRolesRepository.cs index 510693ae00..6c9d7e4342 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/IUserRolesRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/IUserRolesRepository.cs @@ -48,7 +48,7 @@ public interface IUserRolesRepository IAsyncEnumerable GetAppRolesAsync(Guid offerId, Guid companyId, string languageShortName); IAsyncEnumerable GetClientRolesCompositeAsync(string keyCloakClientId); - IAsyncEnumerable GetServiceAccountRolesAsync(Guid companyId, string clientId, IEnumerable externalRoleIds, string languageShortName); + IAsyncEnumerable GetServiceAccountRolesAsync(Guid companyId, string clientId, IEnumerable externalRoleIds, string languageShortName); /// /// Gets all user role ids for the given offerId diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/TechnicalUserProfileRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/TechnicalUserProfileRepository.cs index 52fc89dee6..d4d4e70b6c 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/TechnicalUserProfileRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/TechnicalUserProfileRepository.cs @@ -20,6 +20,7 @@ using Microsoft.EntityFrameworkCore; using Org.Eclipse.TractusX.Portal.Backend.Framework.DBAccess; +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Configuration; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Entities; @@ -69,14 +70,17 @@ public void RemoveTechnicalUserProfilesForOffer(Guid offerId) } /// - public Task<(bool IsUserOfProvidingCompany, IEnumerable Information)> - GetTechnicalUserProfileInformation(Guid offerId, Guid usersCompanyId, OfferTypeId offerTypeId) => + public Task<(bool IsUserOfProvidingCompany, IEnumerable Information)> GetTechnicalUserProfileInformation(Guid offerId, Guid usersCompanyId, OfferTypeId offerTypeId, IEnumerable externalUserRoles) => _context.Offers .Where(x => x.Id == offerId && x.OfferTypeId == offerTypeId) - .Select(x => new ValueTuple>( + .Select(x => new ValueTuple>( x.ProviderCompanyId == usersCompanyId, - x.TechnicalUserProfiles.Select(tup => new TechnicalUserProfileInformation( + x.TechnicalUserProfiles.Select(tup => new TechnicalUserProfileInformationTransferData( tup.Id, - tup.TechnicalUserProfileAssignedUserRoles.Select(ur => new UserRoleInformation(ur.UserRole!.Id, ur.UserRole.UserRoleText)))))) + tup.TechnicalUserProfileAssignedUserRoles + .Select(ur => new UserRoleInformationTransferData( + ur.UserRole!.Id, + ur.UserRole.UserRoleText, + externalUserRoles.Contains(ur.UserRoleId))))))) .SingleOrDefaultAsync(); } diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/UserRolesRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/UserRolesRepository.cs index c054419fb7..cfdca6706d 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/UserRolesRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/UserRolesRepository.cs @@ -214,19 +214,19 @@ public IAsyncEnumerable GetClientRolesCompositeAsync(string keyCloakClie .Select(userRole => userRole.UserRoleText) .AsAsyncEnumerable(); - IAsyncEnumerable IUserRolesRepository.GetServiceAccountRolesAsync(Guid companyId, string clientId, IEnumerable externalRoleIds, string languageShortName) => + IAsyncEnumerable IUserRolesRepository.GetServiceAccountRolesAsync(Guid companyId, string clientId, IEnumerable externalRoleIds, string languageShortName) => _dbContext.UserRoles .AsNoTracking() .Where(ur => ur.Offer!.AppInstances.Any(ai => ai.IamClient!.ClientClientId == clientId) && ur.UserRoleCollections.Any(urc => urc.CompanyRoleAssignedRoleCollection!.CompanyRole!.CompanyAssignedRoles.Any(car => car.CompanyId == companyId))) - .Select(userRole => new UserRoleWithDescription( + .Select(userRole => new UserRoleWithDescriptionTransferData( userRole.Id, userRole.UserRoleText, userRole.UserRoleDescriptions.SingleOrDefault(desc => desc.LanguageShortName == languageShortName)!.Description, - externalRoleIds.Contains(userRole.Id) ? UserRoleType.External : UserRoleType.Internal)) + externalRoleIds.Contains(userRole.Id))) .AsAsyncEnumerable(); /// diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/ServiceAccountBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/ServiceAccountBusinessLogicTests.cs index 2685551322..081501a30c 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/ServiceAccountBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/ServiceAccountBusinessLogicTests.cs @@ -656,7 +656,7 @@ public async Task DeleteOwnCompanyServiceAccountAsync_WithoutClient_CallsExpecte public async Task GetServiceAccountRolesAsync_GetsExpectedData() { // Arrange - var data = _fixture.CreateMany(15); + var data = _fixture.CreateMany(15); A.CallTo(() => _userRolesRepository.GetServiceAccountRolesAsync(A._, A._, A>._, A._)) .Returns(data.ToAsyncEnumerable()); @@ -676,7 +676,8 @@ public async Task GetServiceAccountRolesAsync_GetsExpectedData() // Sonar fix -> Return value of pure method is not used result.Should().AllSatisfy(ur => { - data.Contains(ur).Should().BeTrue(); + var transferData = new UserRoleWithDescriptionTransferData(ur.UserRoleId, ur.UserRoleText, ur.RoleDescription, ur.RoleType == UserRoleType.External); + data.Contains(transferData).Should().BeTrue(); }); } diff --git a/tests/endtoend/CreateAppScenario/CreateNewTestAppScenario.cs b/tests/endtoend/CreateAppScenario/CreateNewTestAppScenario.cs index 2f80bb6b3a..c380c48649 100644 --- a/tests/endtoend/CreateAppScenario/CreateNewTestAppScenario.cs +++ b/tests/endtoend/CreateAppScenario/CreateNewTestAppScenario.cs @@ -18,6 +18,7 @@ ********************************************************************************/ using FluentAssertions; +using Org.Eclipse.TractusX.Portal.Backend.Administration.Service.Models; using Org.Eclipse.TractusX.Portal.Backend.Apps.Service.ViewModels; using Org.Eclipse.TractusX.Portal.Backend.Framework.Linq; using Org.Eclipse.TractusX.Portal.Backend.Offers.Library.Models; diff --git a/tests/marketplace/Apps.Service.Tests/BusinessLogic/AppReleaseBusinessLogicTest.cs b/tests/marketplace/Apps.Service.Tests/BusinessLogic/AppReleaseBusinessLogicTest.cs index dc721b4fec..383ba2db3c 100644 --- a/tests/marketplace/Apps.Service.Tests/BusinessLogic/AppReleaseBusinessLogicTest.cs +++ b/tests/marketplace/Apps.Service.Tests/BusinessLogic/AppReleaseBusinessLogicTest.cs @@ -1264,7 +1264,7 @@ public async Task GetTechnicalUserProfilesForOffer_ReturnsExpected() { // Arrange var appId = Guid.NewGuid(); - A.CallTo(() => _offerService.GetTechnicalUserProfilesForOffer(appId, OfferTypeId.APP)) + A.CallTo(() => _offerService.GetTechnicalUserProfilesForOffer(appId, OfferTypeId.APP, A>._)) .Returns(_fixture.CreateMany(5)); var sut = new AppReleaseBusinessLogic(null!, Options.Create(new AppsSettings()), _offerService, _offerDocumentService, null!, _identityService); diff --git a/tests/marketplace/Apps.Service.Tests/appsettings.IntegrationTests.json b/tests/marketplace/Apps.Service.Tests/appsettings.IntegrationTests.json index 1617190390..f51e1913e0 100644 --- a/tests/marketplace/Apps.Service.Tests/appsettings.IntegrationTests.json +++ b/tests/marketplace/Apps.Service.Tests/appsettings.IntegrationTests.json @@ -237,7 +237,15 @@ "OfferDetailAddress": "https://detail.de", "DecentralIdentityManagementAuthUrl": "https://test.org/auth", "IssuerDid": "did:web:example.org:test123", - "BpnDidResolverUrl": "https://test.org/bpn-did" + "BpnDidResolverUrl": "https://test.org/bpn-did", + "DimUserRoles": [ + { + "ClientId": "technical_roles_management", + "UserRoleNames": [ + "Identity Wallet Management" + ] + } + ] }, "Provisioning": { "CentralRealm": "CX-Central", diff --git a/tests/marketplace/Offers.Library.Tests/Service/OfferServiceTests.cs b/tests/marketplace/Offers.Library.Tests/Service/OfferServiceTests.cs index 310292217f..c4abeaf861 100644 --- a/tests/marketplace/Offers.Library.Tests/Service/OfferServiceTests.cs +++ b/tests/marketplace/Offers.Library.Tests/Service/OfferServiceTests.cs @@ -1823,16 +1823,16 @@ public async Task GetTechnicalUserProfileData_ReturnsExpectedResult(OfferTypeId { // Arrange var offerId = _fixture.Create(); - var data = _fixture.CreateMany(5); - A.CallTo(() => _technicalUserProfileRepository.GetTechnicalUserProfileInformation(offerId, _companyId, offerTypeId)) + var data = _fixture.CreateMany(5); + A.CallTo(() => _technicalUserProfileRepository.GetTechnicalUserProfileInformation(offerId, _companyId, offerTypeId, A>._)) .Returns((true, data)); // Act - var result = await _sut.GetTechnicalUserProfilesForOffer(offerId, offerTypeId); + var result = await _sut.GetTechnicalUserProfilesForOffer(offerId, offerTypeId, Enumerable.Empty()); // Assert result.Should().HaveCount(5); - A.CallTo(() => _technicalUserProfileRepository.GetTechnicalUserProfileInformation(offerId, _companyId, offerTypeId)).MustHaveHappenedOnceExactly(); + A.CallTo(() => _technicalUserProfileRepository.GetTechnicalUserProfileInformation(offerId, _companyId, offerTypeId, A>._)).MustHaveHappenedOnceExactly(); } [Theory] @@ -1842,16 +1842,16 @@ public async Task GetTechnicalUserProfileData_WithoutOffer_ThrowsNotFoundExcepti { // Arrange var offerId = _fixture.Create(); - A.CallTo(() => _technicalUserProfileRepository.GetTechnicalUserProfileInformation(offerId, _companyId, offerTypeId)) - .Returns<(bool, IEnumerable)>(default); + A.CallTo(() => _technicalUserProfileRepository.GetTechnicalUserProfileInformation(offerId, _companyId, offerTypeId, A>._)) + .Returns<(bool, IEnumerable)>(default); // Act - async Task Act() => await _sut.GetTechnicalUserProfilesForOffer(offerId, offerTypeId); + async Task Act() => await _sut.GetTechnicalUserProfilesForOffer(offerId, offerTypeId, Enumerable.Empty()); // Assert var ex = await Assert.ThrowsAsync(Act); ex.Message.Should().Be($"Offer {offerId} does not exist"); - A.CallTo(() => _technicalUserProfileRepository.GetTechnicalUserProfileInformation(offerId, _companyId, offerTypeId)).MustHaveHappenedOnceExactly(); + A.CallTo(() => _technicalUserProfileRepository.GetTechnicalUserProfileInformation(offerId, _companyId, offerTypeId, A>._)).MustHaveHappenedOnceExactly(); } [Theory] @@ -1861,16 +1861,16 @@ public async Task GetTechnicalUserProfileData_WithUserNotInProvidingCompany_Thro { // Arrange var offerId = _fixture.Create(); - A.CallTo(() => _technicalUserProfileRepository.GetTechnicalUserProfileInformation(offerId, _companyId, offerTypeId)) - .Returns((false, Enumerable.Empty())); + A.CallTo(() => _technicalUserProfileRepository.GetTechnicalUserProfileInformation(offerId, _companyId, offerTypeId, A>._)) + .Returns((false, Enumerable.Empty())); // Act - async Task Act() => await _sut.GetTechnicalUserProfilesForOffer(offerId, offerTypeId); + async Task Act() => await _sut.GetTechnicalUserProfilesForOffer(offerId, offerTypeId, Enumerable.Empty()); // Assert var ex = await Assert.ThrowsAsync(Act); ex.Message.Should().Be($"Company {_companyId} is not the providing company"); - A.CallTo(() => _technicalUserProfileRepository.GetTechnicalUserProfileInformation(offerId, _companyId, offerTypeId)).MustHaveHappenedOnceExactly(); + A.CallTo(() => _technicalUserProfileRepository.GetTechnicalUserProfileInformation(offerId, _companyId, offerTypeId, A>._)).MustHaveHappenedOnceExactly(); } #endregion diff --git a/tests/marketplace/Services.Service.Tests/BusinessLogic/ServiceReleaseBusinessLogicTest.cs b/tests/marketplace/Services.Service.Tests/BusinessLogic/ServiceReleaseBusinessLogicTest.cs index d78467bf90..3df2af73a3 100644 --- a/tests/marketplace/Services.Service.Tests/BusinessLogic/ServiceReleaseBusinessLogicTest.cs +++ b/tests/marketplace/Services.Service.Tests/BusinessLogic/ServiceReleaseBusinessLogicTest.cs @@ -585,7 +585,7 @@ public async Task ApproveServiceRequestAsync_WithValid_CallsExpected() public async Task GetTechnicalUserProfilesForOffer_ReturnsExpected() { // Arrange - A.CallTo(() => _offerService.GetTechnicalUserProfilesForOffer(_existingServiceId, OfferTypeId.SERVICE)) + A.CallTo(() => _offerService.GetTechnicalUserProfilesForOffer(_existingServiceId, OfferTypeId.SERVICE, A>._)) .Returns(_fixture.CreateMany(5)); var sut = new ServiceReleaseBusinessLogic(null!, _offerService, _offerDocumentService, _identityService, Options.Create(new ServiceSettings())); diff --git a/tests/marketplace/Services.Service.Tests/appsettings.IntegrationTests.json b/tests/marketplace/Services.Service.Tests/appsettings.IntegrationTests.json index a697823515..fd49a2ca33 100644 --- a/tests/marketplace/Services.Service.Tests/appsettings.IntegrationTests.json +++ b/tests/marketplace/Services.Service.Tests/appsettings.IntegrationTests.json @@ -157,7 +157,15 @@ "IN_REVIEW" ], "OfferSubscriptionAddress": "https://test.de", - "OfferDetailAddress": "https://detail.de" + "OfferDetailAddress": "https://detail.de", + "DimUserRoles": [ + { + "ClientId": "technical_roles_management", + "UserRoleNames": [ + "Identity Wallet Management" + ] + } + ] }, "Dim": { "Username": "empty", diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/TechnicalUserProfileRepositoryTests.cs b/tests/portalbackend/PortalBackend.DBAccess.Tests/TechnicalUserProfileRepositoryTests.cs index 2a9ecdaa0e..02db20c197 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/TechnicalUserProfileRepositoryTests.cs +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/TechnicalUserProfileRepositoryTests.cs @@ -18,6 +18,7 @@ ********************************************************************************/ using Microsoft.EntityFrameworkCore; +using Org.Eclipse.TractusX.Portal.Backend.Framework.Models.Configuration; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Tests.Setup; using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities; @@ -251,12 +252,14 @@ public async Task GetTechnicalUserProfileInformation_ReturnsExpectedResult() var sut = await CreateSut(); // Act - var result = await sut.GetTechnicalUserProfileInformation(_validServiceId, _validCompanyId, OfferTypeId.SERVICE); + var result = await sut.GetTechnicalUserProfileInformation(_validServiceId, _validCompanyId, OfferTypeId.SERVICE, Enumerable.Repeat(new Guid("607818be-4978-41f4-bf63-fa8d2de51157"), 1)); // Assert result.Should().NotBeNull(); result.IsUserOfProvidingCompany.Should().BeTrue(); - result.Information.Should().HaveCount(2); + result.Information.Should().HaveCount(2).And.Satisfy( + x => x.UserRoles.Count(x => !x.External) == 2, + x => x.UserRoles.Count(x => !x.External) == 1); } [Fact] @@ -266,7 +269,7 @@ public async Task GetTechnicalUserProfileInformation_WithUnknownUser_ReturnsExpe var sut = await CreateSut(); // Act - var result = await sut.GetTechnicalUserProfileInformation(_validServiceId, Guid.NewGuid(), OfferTypeId.SERVICE); + var result = await sut.GetTechnicalUserProfileInformation(_validServiceId, Guid.NewGuid(), OfferTypeId.SERVICE, Enumerable.Repeat(new Guid("607818be-4978-41f4-bf63-fa8d2de51157"), 1)); // Assert result.Should().NotBeNull(); @@ -280,7 +283,7 @@ public async Task GetTechnicalUserProfileInformation_WithoutExistingProfile_Retu var sut = await CreateSut(); // Act - var result = await sut.GetTechnicalUserProfileInformation(Guid.NewGuid(), _validCompanyId, OfferTypeId.SERVICE); + var result = await sut.GetTechnicalUserProfileInformation(Guid.NewGuid(), _validCompanyId, OfferTypeId.SERVICE, Enumerable.Repeat(new Guid("607818be-4978-41f4-bf63-fa8d2de51157"), 1)); // Assert result.Should().Be(default); @@ -293,7 +296,7 @@ public async Task GetTechnicalUserProfileInformation_WithWrongType_ReturnsNull() var sut = await CreateSut(); // Act - var result = await sut.GetTechnicalUserProfileInformation(_validServiceId, _validCompanyId, OfferTypeId.APP); + var result = await sut.GetTechnicalUserProfileInformation(_validServiceId, _validCompanyId, OfferTypeId.APP, Enumerable.Repeat(new Guid("607818be-4978-41f4-bf63-fa8d2de51157"), 1)); // Assert result.Should().Be(default); diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/UserRolesRepositoryTests.cs b/tests/portalbackend/PortalBackend.DBAccess.Tests/UserRolesRepositoryTests.cs index b8ea838d09..d399f03ee3 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/UserRolesRepositoryTests.cs +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/UserRolesRepositoryTests.cs @@ -137,8 +137,8 @@ public async Task GetServiceAccountRolesAsync_WithValidData_ReturnsExpected() // Assert data.Should().HaveCount(14); data.Should().OnlyHaveUniqueItems(); - data.Where(x => x.RoleType == UserRoleType.Internal).Should().HaveCount(13); - data.Where(x => x.RoleType == UserRoleType.External).Should().ContainSingle(); + data.Where(x => !x.External).Should().HaveCount(13); + data.Where(x => x.External).Should().ContainSingle(); } #endregion