Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ntruchsess committed Jul 27, 2023
1 parent c761c19 commit 6543a39
Show file tree
Hide file tree
Showing 108 changed files with 295 additions and 379 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
using PortalBackend.PortalEntities.Identity;
using System.Globalization;
using System.Text.Json;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,19 @@ await _sdFactoryBusinessLogic
public async Task DeleteConnectorAsync(Guid connectorId, Guid companyId, CancellationToken cancellationToken)
{
var connectorsRepository = _portalRepositories.GetInstance<IConnectorsRepository>();
var (isValidConnectorId, dapsClientId, selfDescriptionDocumentId,
var (isValidConnectorId, isProvidingOrHostCompany, dapsClientId, selfDescriptionDocumentId,
documentStatus, connectorStatus, dapsRegistrationSuccess) = await connectorsRepository.GetConnectorDeleteDataAsync(connectorId, companyId).ConfigureAwait(false);

if (!isValidConnectorId)
{
throw new NotFoundException($"Connector {connectorId} does not exist");
}

if (!isProvidingOrHostCompany)
{
throw new ForbiddenException($"company {companyId} is neither provider nor host-company of connector {connectorId}");
}

switch ((dapsRegistrationSuccess ?? false, connectorStatus))
{
case (true, ConnectorStatusId.ACTIVE) when selfDescriptionDocumentId == null:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLog
{
public interface IInvitationBusinessLogic
{
Task ExecuteInvitation(CompanyInvitationData invitationData, Guid userId);
Task ExecuteInvitation(CompanyInvitationData invitationData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public interface IRegistrationBusinessLogic
/// </summary>
/// <param name="applicationId">Id of the application</param>
/// <param name="comment">Reason of decline</param>
/// <param name="userId"></param>
Task DeclineRegistrationVerification(Guid applicationId, string comment, Guid userId);
Task DeclineRegistrationVerification(Guid applicationId, string comment);

/// <summary>
/// Processes the clearinghouse response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Org.Eclipse.TractusX.Portal.Backend.Administration.Service.BusinessLog
public interface IServiceAccountBusinessLogic
{
Task<ServiceAccountDetails> CreateOwnCompanyServiceAccountAsync(ServiceAccountCreationInfo serviceAccountCreationInfos, Guid companyId);
Task<int> DeleteOwnCompanyServiceAccountAsync(Guid serviceAccountId, (Guid UserId, Guid CompanyId) identity);
Task<int> DeleteOwnCompanyServiceAccountAsync(Guid serviceAccountId, Guid companyId);
Task<ServiceAccountConnectorOfferData> GetOwnCompanyServiceAccountDetailsAsync(Guid serviceAccountId, Guid companyId);
Task<ServiceAccountDetails> UpdateOwnCompanyServiceAccountDetailsAsync(Guid serviceAccountId, ServiceAccountEditableDetails serviceAccountDetails, Guid companyId);
Task<ServiceAccountDetails> ExecuteResetOwnCompanyServiceAccountSecretAsync(Guid serviceAccountId, Guid companyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ public interface ISubscriptionConfigurationBusinessLogic
/// Sets service provider company details
/// </summary>
/// <param name="data">Detail data for the service provider</param>
/// <param name="identity">Id of the users and the users company</param>
Task SetProviderCompanyDetailsAsync(ProviderDetailData data, (Guid UserId, Guid CompanyId) identity);
/// <param name="companyId">Id of the users company</param>
Task SetProviderCompanyDetailsAsync(ProviderDetailData data, Guid companyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public InvitationBusinessLogic(
_settings = settings.Value;
}

public Task ExecuteInvitation(CompanyInvitationData invitationData, Guid userId)
public Task ExecuteInvitation(CompanyInvitationData invitationData)
{
if (string.IsNullOrWhiteSpace(invitationData.email))
{
Expand All @@ -72,10 +72,10 @@ public Task ExecuteInvitation(CompanyInvitationData invitationData, Guid userId)
{
throw new ControllerArgumentException("organisationName must not be empty", "organisationName");
}
return ExecuteInvitationInternalAsync(invitationData, userId);
return ExecuteInvitationInternalAsync(invitationData);
}

private async Task ExecuteInvitationInternalAsync(CompanyInvitationData invitationData, Guid userId)
private async Task ExecuteInvitationInternalAsync(CompanyInvitationData invitationData)
{
var idpName = await _provisioningManager.GetNextCentralIdentityProviderNameAsync().ConfigureAwait(false);
await _provisioningManager.SetupSharedIdpAsync(idpName, invitationData.organisationName, _settings.InitialLoginTheme).ConfigureAwait(false);
Expand All @@ -96,7 +96,6 @@ private async Task ExecuteInvitationInternalAsync(CompanyInvitationData invitati
company.Id,
company.Name,
null,
userId,
idpName,
true
);
Expand All @@ -120,7 +119,7 @@ private async Task ExecuteInvitationInternalAsync(CompanyInvitationData invitati
""
)}.ToAsyncEnumerable();

var (companyUserId, _, password, error) = await _userProvisioningService.CreateOwnCompanyIdpUsersAsync(companyNameIdpAliasData, userCreationInfoIdps, userId).SingleAsync().ConfigureAwait(false);
var (companyUserId, _, password, error) = await _userProvisioningService.CreateOwnCompanyIdpUsersAsync(companyNameIdpAliasData, userCreationInfoIdps).SingleAsync().ConfigureAwait(false);

if (error != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public async Task ApproveRegistrationVerification(Guid applicationId)
await _portalRepositories.SaveAsync().ConfigureAwait(false);
}

public async Task DeclineRegistrationVerification(Guid applicationId, string comment, Guid userId)
public async Task DeclineRegistrationVerification(Guid applicationId, string comment)
{
var result = await _portalRepositories.GetInstance<IApplicationRepository>().GetCompanyIdNameForSubmittedApplication(applicationId).ConfigureAwait(false);
if (result == default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ public async Task<ServiceAccountDetails> CreateOwnCompanyServiceAccountAsync(Ser
serviceAccountData.AuthData.Secret);
}

public async Task<int> DeleteOwnCompanyServiceAccountAsync(Guid serviceAccountId, (Guid UserId, Guid CompanyId) identity)
public async Task<int> DeleteOwnCompanyServiceAccountAsync(Guid serviceAccountId, Guid companyId)
{
var serviceAccountRepository = _portalRepositories.GetInstance<IServiceAccountRepository>();
var result = await serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(serviceAccountId, identity.CompanyId).ConfigureAwait(false);
var result = await serviceAccountRepository.GetOwnCompanyServiceAccountWithIamServiceAccountRolesAsync(serviceAccountId, companyId).ConfigureAwait(false);
if (result == default)
{
throw new ConflictException($"serviceAccount {serviceAccountId} not found for company {identity.CompanyId}");
throw new ConflictException($"serviceAccount {serviceAccountId} not found for company {companyId}");
}
if (result.statusId == ConnectorStatusId.ACTIVE || result.statusId == ConnectorStatusId.PENDING)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task<ProviderDetailReturnData> GetProviderCompanyDetailsAsync(Guid
}

/// <inheritdoc />
public Task SetProviderCompanyDetailsAsync(ProviderDetailData data, (Guid UserId, Guid CompanyId) identity)
public Task SetProviderCompanyDetailsAsync(ProviderDetailData data, Guid companyId)
{
data.Url.EnsureValidHttpsUrl(() => nameof(data.Url));
data.CallbackUrl?.EnsureValidHttpsUrl(() => nameof(data.CallbackUrl));
Expand All @@ -70,29 +70,29 @@ public Task SetProviderCompanyDetailsAsync(ProviderDetailData data, (Guid UserId
"the maximum allowed length is 100 characters", nameof(data.Url));
}

return SetOfferProviderCompanyDetailsInternalAsync(data, identity);
return SetOfferProviderCompanyDetailsInternalAsync(data, companyId);
}

private async Task SetOfferProviderCompanyDetailsInternalAsync(ProviderDetailData data, (Guid UserId, Guid CompanyId) identity)
private async Task SetOfferProviderCompanyDetailsInternalAsync(ProviderDetailData data, Guid companyId)
{
var companyRepository = _portalRepositories.GetInstance<ICompanyRepository>();
var providerDetailData = await companyRepository
.GetProviderCompanyDetailsExistsForUser(identity.CompanyId)
.GetProviderCompanyDetailsExistsForUser(companyId)
.ConfigureAwait(false);
if (providerDetailData == default)
{
var result = await companyRepository
.IsValidCompanyRoleOwner(identity.CompanyId, new[] { CompanyRoleId.APP_PROVIDER, CompanyRoleId.SERVICE_PROVIDER })
.IsValidCompanyRoleOwner(companyId, new[] { CompanyRoleId.APP_PROVIDER, CompanyRoleId.SERVICE_PROVIDER })
.ConfigureAwait(false);
if (!result.IsValidCompanyId)
{
throw new ConflictException($"Company {identity.CompanyId} not found");
throw new ConflictException($"Company {companyId} not found");
}
if (!result.IsCompanyRoleOwner)
{
throw new ForbiddenException($"Company {identity.CompanyId} is not an app- or service-provider");
throw new ForbiddenException($"Company {companyId} is not an app- or service-provider");
}
companyRepository.CreateProviderCompanyDetail(identity.CompanyId, data.Url, providerDetails =>
companyRepository.CreateProviderCompanyDetail(companyId, data.Url, providerDetails =>
{
if (data.CallbackUrl != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private async IAsyncEnumerable<string> CreateOwnCompanyUsersInternalAsync(IEnume

var companyDisplayName = await _userProvisioningService.GetIdentityProviderDisplayName(companyNameIdpAliasData.IdpAlias).ConfigureAwait(false);

await foreach (var (_, userName, password, error) in _userProvisioningService.CreateOwnCompanyIdpUsersAsync(companyNameIdpAliasData, userCreationInfoIdps, identity.UserId).ConfigureAwait(false))
await foreach (var (_, userName, password, error) in _userProvisioningService.CreateOwnCompanyIdpUsersAsync(companyNameIdpAliasData, userCreationInfoIdps).ConfigureAwait(false))
{
var email = emailData[userName];

Expand Down Expand Up @@ -177,8 +177,7 @@ public async Task<Guid> CreateOwnCompanyIdpUserAsync(Guid identityProviderId, Us
roleDatas,
userCreationInfo.UserName,
userCreationInfo.UserId
), 1).ToAsyncEnumerable(),
identity.UserId)
), 1).ToAsyncEnumerable())
.FirstAsync()
.ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,19 @@ await GetUserRoleDatas(parsed.Roles, validRoleData, identity.CompanyId).Configur
.CreateOwnCompanyIdpUsersAsync(
companyNameIdpAliasData,
lines,
identity.UserId,
cancellationToken)
: CreateOwnCompanyIdpUsersWithEmailAsync(
nameCreatedBy,
companyNameIdpAliasData,
lines,
identity.UserId,
cancellationToken))
.Select(x => (x.CompanyUserId != Guid.Empty, x.Error)),
cancellationToken).ConfigureAwait(false);

return new UserCreationStats(numCreated, errors.Count(), numLines, errors.Select(x => $"line: {x.Line}, message: {x.Error.Message}"));
}

private async IAsyncEnumerable<(Guid CompanyUserId, string UserName, string? Password, Exception? Error)> CreateOwnCompanyIdpUsersWithEmailAsync(string nameCreatedBy, CompanyNameIdpAliasData companyNameIdpAliasData, IAsyncEnumerable<UserCreationRoleDataIdpInfo> userCreationInfos, Guid userId, [EnumeratorCancellation] CancellationToken cancellationToken)
private async IAsyncEnumerable<(Guid CompanyUserId, string UserName, string? Password, Exception? Error)> CreateOwnCompanyIdpUsersWithEmailAsync(string nameCreatedBy, CompanyNameIdpAliasData companyNameIdpAliasData, IAsyncEnumerable<UserCreationRoleDataIdpInfo> userCreationInfos, [EnumeratorCancellation] CancellationToken cancellationToken)
{
if (companyNameIdpAliasData.IsSharedIdp)
{
Expand All @@ -123,7 +121,6 @@ await GetUserRoleDatas(parsed.Roles, validRoleData, identity.CompanyId).Configur
userCreationInfo = info;
return info;
}),
userId,
cancellationToken)
.WithCancellation(cancellationToken)
.ConfigureAwait(false))
Expand Down Expand Up @@ -221,7 +218,6 @@ await GetUserRoleDatas(parsed.Roles, validRoleData, identity.CompanyId).Configur
.CreateOwnCompanyIdpUsersAsync(
companyNameIdpAliasData,
lines,
identity.UserId,
cancellationToken)
.Select(x => (x.CompanyUserId != Guid.Empty, x.Error)),
cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ public InvitationController(IInvitationBusinessLogic logic)
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status502BadGateway)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status409Conflict)]
public Task ExecuteInvitation([FromBody] CompanyInvitationData invitationData) =>
this.WithUserId(userId => _logic.ExecuteInvitation(invitationData, userId));
_logic.ExecuteInvitation(invitationData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public async Task<NoContentResult> ApproveApplication([FromRoute] Guid applicati
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
public async Task<NoContentResult> DeclineApplication([FromRoute] Guid applicationId, [FromBody] RegistrationDeclineData data)
{
await this.WithUserId(userId => _logic.DeclineRegistrationVerification(applicationId, data.Comment, userId)).ConfigureAwait(false);
await _logic.DeclineRegistrationVerification(applicationId, data.Comment).ConfigureAwait(false);
return NoContent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task<CreatedAtRouteResult> ExecuteCompanyUserCreation([FromBody] Se
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status409Conflict)]
public Task<int> DeleteServiceAccount([FromRoute] Guid serviceAccountId) =>
this.WithUserIdAndCompanyId(identity => _logic.DeleteOwnCompanyServiceAccountAsync(serviceAccountId, identity));
this.WithCompanyId(companyId => _logic.DeleteOwnCompanyServiceAccountAsync(serviceAccountId, companyId));

/// <summary>
/// Gets the service account details for the given id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Task<ProviderDetailReturnData> GetServiceProviderCompanyDetail() =>
[ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status404NotFound)]
public async Task<NoContentResult> SetProviderCompanyDetail([FromBody] ProviderDetailData data)
{
await this.WithUserIdAndCompanyId(identity => _businessLogic.SetProviderCompanyDetailsAsync(data, identity)).ConfigureAwait(false);
await this.WithCompanyId(companyId => _businessLogic.SetProviderCompanyDetailsAsync(data, companyId)).ConfigureAwait(false);
return NoContent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Identity;
using PortalBackend.PortalEntities.Identity;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Identities;

namespace Org.Eclipse.TractusX.Portal.Backend.Framework.ProcessIdentity.DependencyInjection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public class ProcessIdentitySettings
public string UserEntityId { get; set; } = null!;

[Required]
public Guid ProcessUserId { get; set; } = default;
public Guid ProcessUserId { get; set; } = Guid.Empty;

[Required]
public IdentityTypeId IdentityTypeId { get; set; } = default;

[Required]
public Guid ProcessUserCompanyId { get; set; } = default;
public Guid ProcessUserCompanyId { get; set; } = Guid.Empty;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

using Microsoft.Extensions.Options;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ProcessIdentity.DependencyInjection;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Identity;
using PortalBackend.PortalEntities.Identity;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Identities;

namespace Org.Eclipse.TractusX.Portal.Backend.Framework.ProcessIdentity;

Expand Down
3 changes: 1 addition & 2 deletions src/framework/Framework.Web/IdentityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
using Microsoft.AspNetCore.Http;
using Org.Eclipse.TractusX.Portal.Backend.Framework.ErrorHandling;
using Org.Eclipse.TractusX.Portal.Backend.Keycloak.Authentication;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Identity;
using PortalBackend.PortalEntities.Identity;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Identities;

namespace Org.Eclipse.TractusX.Portal.Backend.Framework.Web;

Expand Down
4 changes: 1 addition & 3 deletions src/framework/Framework.Web/StartupServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@
using Org.Eclipse.TractusX.Portal.Backend.Framework.Authorization;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Cors;
using Org.Eclipse.TractusX.Portal.Backend.Framework.DateTimeProvider.DependencyInjection;
using Org.Eclipse.TractusX.Portal.Backend.Framework.DBAccess;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Models;
using Org.Eclipse.TractusX.Portal.Backend.Framework.Swagger;
using Org.Eclipse.TractusX.Portal.Backend.Keycloak.Authentication;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Identity;
using PortalBackend.PortalEntities.Identity;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Identities;
using System.IdentityModel.Tokens.Jwt;
using System.Text.Json.Serialization;

Expand Down
Loading

0 comments on commit 6543a39

Please sign in to comment.