Skip to content

Commit

Permalink
fix(connector): only provider should update connector
Browse files Browse the repository at this point in the history
  • Loading branch information
dhiren-singh-007 committed Nov 14, 2024
1 parent 28fb429 commit 22f4b07
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,22 +402,22 @@ 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)
{
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
Expand All @@ -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 =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public Connector AttachAndModifyConnector(Guid connectorId, Action<Connector>? i
.Select(c => new ConnectorUpdateInformation(
c.StatusId,
c.TypeId,
c.HostId == companyId,
c.ProviderId == companyId,
c.ConnectorUrl,
c.Provider!.BusinessPartnerNumber,
c.SelfDescriptionDocumentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConnectorUpdateInformation>()
.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);
Expand All @@ -1017,7 +1017,7 @@ public async Task UpdateConnectorUrl_WithUserNotOfHostCompany_ThrowsForbiddenExc

// Assert
var ex = await Assert.ThrowsAsync<ForbiddenException>(Act);
ex.Message.Should().Be(AdministrationConnectorErrors.CONNECTOR_NOT_HOST_COMPANY.ToString());
ex.Message.Should().Be(AdministrationConnectorErrors.CONNECTOR_NOT_PROVIDER_COMPANY.ToString());
}

[Fact]
Expand All @@ -1027,7 +1027,7 @@ public async Task UpdateConnectorUrl_WithInactiveConnector_ThrowsConflictExcepti
var connectorId = Guid.NewGuid();
var data = _fixture.Build<ConnectorUpdateInformation>()
.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))
Expand All @@ -1048,7 +1048,7 @@ public async Task UpdateConnectorUrl_WithBpnNotSet_ThrowsConflictException()
var connectorId = Guid.NewGuid();
var data = _fixture.Build<ConnectorUpdateInformation>()
.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?))
Expand All @@ -1071,7 +1071,7 @@ public async Task UpdateConnectorUrl_WithCompanyBpnNotSet_ThrowsConflictExceptio
var connectorId = Guid.NewGuid();
var data = _fixture.Build<ConnectorUpdateInformation>()
.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")
Expand Down Expand Up @@ -1101,7 +1101,7 @@ public async Task UpdateConnectorUrl_WithValidData_CallsExpected()
.Create();
var data = _fixture.Build<ConnectorUpdateInformation>()
.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")
Expand Down

0 comments on commit 22f4b07

Please sign in to comment.