Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(connector): only provider should update connector #1086

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
dhiren-singh-007 marked this conversation as resolved.
Show resolved Hide resolved
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 @@
}

[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 @@

// 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 @@
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 @@
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 @@
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 @@
.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 Expand Up @@ -1144,7 +1144,7 @@
var connectorId = Guid.NewGuid();
var data = _fixture.Build<ConnectorUpdateInformation>()
.With(x => x.ConnectorUrl, "https://old.de")
.With(x => x.IsHostCompany, true)

Check failure on line 1147 in tests/administration/Administration.Service.Tests/BusinessLogic/ConnectorsBusinessLogicTests.cs

View workflow job for this annotation

GitHub Actions / Build, check and test services (8.0)

'ConnectorUpdateInformation' does not contain a definition for 'IsHostCompany' and no accessible extension method 'IsHostCompany' accepting a first argument of type 'ConnectorUpdateInformation' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 1147 in tests/administration/Administration.Service.Tests/BusinessLogic/ConnectorsBusinessLogicTests.cs

View workflow job for this annotation

GitHub Actions / Build, check and test services (8.0)

'ConnectorUpdateInformation' does not contain a definition for 'IsHostCompany' and no accessible extension method 'IsHostCompany' accepting a first argument of type 'ConnectorUpdateInformation' could be found (are you missing a using directive or an assembly reference?)
.With(x => x.Status, ConnectorStatusId.ACTIVE)
.With(x => x.Type, ConnectorTypeId.CONNECTOR_AS_A_SERVICE)
.With(x => x.Bpn, "BPNL123456789")
Expand Down
Loading