From 22f4b0790f334eb6c449101ab31cc49f6e370655 Mon Sep 17 00:00:00 2001 From: Dhirender Singh Date: Mon, 21 Oct 2024 16:10:46 +0200 Subject: [PATCH] fix(connector): only provider should update connector --- .../BusinessLogic/ConnectorsBusinessLogic.cs | 10 +++++----- .../Models/ConnectorUpdateInformation.cs | 2 +- .../Repositories/ConnectorsRepository.cs | 2 +- .../BusinessLogic/ConnectorsBusinessLogicTests.cs | 14 +++++++------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/administration/Administration.Service/BusinessLogic/ConnectorsBusinessLogic.cs b/src/administration/Administration.Service/BusinessLogic/ConnectorsBusinessLogic.cs index 0de31768de..4ce2c0684b 100644 --- a/src/administration/Administration.Service/BusinessLogic/ConnectorsBusinessLogic.cs +++ b/src/administration/Administration.Service/BusinessLogic/ConnectorsBusinessLogic.cs @@ -402,7 +402,7 @@ private async Task UpdateConnectorUrlInternal(Guid connectorId, ConnectorUpdateR if (connector == null) { - throw NotFoundException.Create(AdministrationConnectorErrors.CONNECTOR_NOT_FOUND, new ErrorParameter[] { new("connectorId", connectorId.ToString()) }); + throw NotFoundException.Create(AdministrationConnectorErrors.CONNECTOR_NOT_FOUND, [new("connectorId", connectorId.ToString())]); } if (connector.ConnectorUrl == data.ConnectorUrl) @@ -410,14 +410,14 @@ private async Task UpdateConnectorUrlInternal(Guid connectorId, ConnectorUpdateR return; } - if (!connector.IsHostCompany) + if (!connector.IsProviderCompany) { - throw ForbiddenException.Create(AdministrationConnectorErrors.CONNECTOR_NOT_HOST_COMPANY, new ErrorParameter[] { new("companyId", _identityData.CompanyId.ToString()) }); + throw ForbiddenException.Create(AdministrationConnectorErrors.CONNECTOR_NOT_PROVIDER_COMPANY, [new("companyId", _identityData.CompanyId.ToString()), new("connectorId", connectorId.ToString())]); } if (connector.Status == ConnectorStatusId.INACTIVE) { - throw ConflictException.Create(AdministrationConnectorErrors.CONNECTOR_CONFLICT_INACTIVE_STATE, new ErrorParameter[] { new("connectorId", connectorId.ToString()), new("connectorStatusId", ConnectorStatusId.INACTIVE.ToString()) }); + throw ConflictException.Create(AdministrationConnectorErrors.CONNECTOR_CONFLICT_INACTIVE_STATE, [new("connectorId", connectorId.ToString()), new("connectorStatusId", ConnectorStatusId.INACTIVE.ToString())]); } var bpn = connector.Type == ConnectorTypeId.CONNECTOR_AS_A_SERVICE @@ -427,7 +427,7 @@ private async Task UpdateConnectorUrlInternal(Guid connectorId, ConnectorUpdateR .ConfigureAwait(ConfigureAwaitOptions.None); if (string.IsNullOrWhiteSpace(bpn)) { - throw ConflictException.Create(AdministrationConnectorErrors.CONNECTOR_CONFLICT_SET_BPN, new ErrorParameter[] { new("companyId", _identityData.CompanyId.ToString()) }); + throw ConflictException.Create(AdministrationConnectorErrors.CONNECTOR_CONFLICT_SET_BPN, [new("companyId", _identityData.CompanyId.ToString())]); } connectorsRepository.AttachAndModifyConnector(connectorId, null, con => diff --git a/src/portalbackend/PortalBackend.DBAccess/Models/ConnectorUpdateInformation.cs b/src/portalbackend/PortalBackend.DBAccess/Models/ConnectorUpdateInformation.cs index 4b01548453..4cfbcf012c 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Models/ConnectorUpdateInformation.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Models/ConnectorUpdateInformation.cs @@ -28,7 +28,7 @@ namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; public record ConnectorUpdateInformation( ConnectorStatusId Status, ConnectorTypeId Type, - bool IsHostCompany, + bool IsProviderCompany, string ConnectorUrl, string? Bpn, Guid? SelfDescriptionDocumentId, diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/ConnectorsRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/ConnectorsRepository.cs index f18ab6817a..5243c83284 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/ConnectorsRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/ConnectorsRepository.cs @@ -190,7 +190,7 @@ public Connector AttachAndModifyConnector(Guid connectorId, Action? i .Select(c => new ConnectorUpdateInformation( c.StatusId, c.TypeId, - c.HostId == companyId, + c.ProviderId == companyId, c.ConnectorUrl, c.Provider!.BusinessPartnerNumber, c.SelfDescriptionDocumentId, diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/ConnectorsBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/ConnectorsBusinessLogicTests.cs index f285541d23..f6a33bc6d4 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/ConnectorsBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/ConnectorsBusinessLogicTests.cs @@ -1001,13 +1001,13 @@ public async Task UpdateConnectorUrl_WithSameUrlAsStored_ReturnsWithoutDoing() } [Fact] - public async Task UpdateConnectorUrl_WithUserNotOfHostCompany_ThrowsForbiddenException() + public async Task UpdateConnectorUrl_WithUserNotOfProviderCompany_ThrowsForbiddenException() { // Arrange var connectorId = Guid.NewGuid(); var data = _fixture.Build() .With(x => x.ConnectorUrl, "https://old.de") - .With(x => x.IsHostCompany, false) + .With(x => x.IsProviderCompany, false) .Create(); A.CallTo(() => _connectorsRepository.GetConnectorUpdateInformation(connectorId, _identity.CompanyId)) .Returns(data); @@ -1017,7 +1017,7 @@ public async Task UpdateConnectorUrl_WithUserNotOfHostCompany_ThrowsForbiddenExc // Assert var ex = await Assert.ThrowsAsync(Act); - ex.Message.Should().Be(AdministrationConnectorErrors.CONNECTOR_NOT_HOST_COMPANY.ToString()); + ex.Message.Should().Be(AdministrationConnectorErrors.CONNECTOR_NOT_PROVIDER_COMPANY.ToString()); } [Fact] @@ -1027,7 +1027,7 @@ public async Task UpdateConnectorUrl_WithInactiveConnector_ThrowsConflictExcepti var connectorId = Guid.NewGuid(); var data = _fixture.Build() .With(x => x.ConnectorUrl, "https://old.de") - .With(x => x.IsHostCompany, true) + .With(x => x.IsProviderCompany, true) .With(x => x.Status, ConnectorStatusId.INACTIVE) .Create(); A.CallTo(() => _connectorsRepository.GetConnectorUpdateInformation(connectorId, _identity.CompanyId)) @@ -1048,7 +1048,7 @@ public async Task UpdateConnectorUrl_WithBpnNotSet_ThrowsConflictException() var connectorId = Guid.NewGuid(); var data = _fixture.Build() .With(x => x.ConnectorUrl, "https://old.de") - .With(x => x.IsHostCompany, true) + .With(x => x.IsProviderCompany, true) .With(x => x.Status, ConnectorStatusId.ACTIVE) .With(x => x.Type, ConnectorTypeId.CONNECTOR_AS_A_SERVICE) .With(x => x.Bpn, default(string?)) @@ -1071,7 +1071,7 @@ public async Task UpdateConnectorUrl_WithCompanyBpnNotSet_ThrowsConflictExceptio var connectorId = Guid.NewGuid(); var data = _fixture.Build() .With(x => x.ConnectorUrl, "https://old.de") - .With(x => x.IsHostCompany, true) + .With(x => x.IsProviderCompany, true) .With(x => x.Status, ConnectorStatusId.ACTIVE) .With(x => x.Type, ConnectorTypeId.COMPANY_CONNECTOR) .With(x => x.Bpn, "BPNL123456789") @@ -1101,7 +1101,7 @@ public async Task UpdateConnectorUrl_WithValidData_CallsExpected() .Create(); var data = _fixture.Build() .With(x => x.ConnectorUrl, "https://old.de") - .With(x => x.IsHostCompany, true) + .With(x => x.IsProviderCompany, true) .With(x => x.Status, ConnectorStatusId.ACTIVE) .With(x => x.Type, ConnectorTypeId.CONNECTOR_AS_A_SERVICE) .With(x => x.Bpn, "BPNL123456789")