Skip to content

Commit

Permalink
prepare refactor indentity for removal of UserEntityId
Browse files Browse the repository at this point in the history
  • Loading branch information
ntruchsess committed Dec 13, 2023
1 parent d0639fa commit 08683b4
Show file tree
Hide file tree
Showing 157 changed files with 2,319 additions and 2,056 deletions.
15 changes: 15 additions & 0 deletions src/Portal.Backend.sln
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Registration.Common", "regi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Keycloak.Authentication.Tests", "..\tests\keycloak\Keycloak.Authentication.Tests\Keycloak.Authentication.Tests.csproj", "{C7ACF748-DEF4-4646-A791-F1DA437CC965}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Framework.ProcessIdentity.Tests", "..\tests\framework\Framework.ProcessIdentity.Tests\Framework.ProcessIdentity.Tests.csproj", "{996CAB8C-B43A-4E76-B906-034A395C1429}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1522,6 +1524,18 @@ Global
{C7ACF748-DEF4-4646-A791-F1DA437CC965}.Release|x64.Build.0 = Release|Any CPU
{C7ACF748-DEF4-4646-A791-F1DA437CC965}.Release|x86.ActiveCfg = Release|Any CPU
{C7ACF748-DEF4-4646-A791-F1DA437CC965}.Release|x86.Build.0 = Release|Any CPU
{996CAB8C-B43A-4E76-B906-034A395C1429}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{996CAB8C-B43A-4E76-B906-034A395C1429}.Debug|Any CPU.Build.0 = Debug|Any CPU
{996CAB8C-B43A-4E76-B906-034A395C1429}.Debug|x64.ActiveCfg = Debug|Any CPU
{996CAB8C-B43A-4E76-B906-034A395C1429}.Debug|x64.Build.0 = Debug|Any CPU
{996CAB8C-B43A-4E76-B906-034A395C1429}.Debug|x86.ActiveCfg = Debug|Any CPU
{996CAB8C-B43A-4E76-B906-034A395C1429}.Debug|x86.Build.0 = Debug|Any CPU
{996CAB8C-B43A-4E76-B906-034A395C1429}.Release|Any CPU.ActiveCfg = Release|Any CPU
{996CAB8C-B43A-4E76-B906-034A395C1429}.Release|Any CPU.Build.0 = Release|Any CPU
{996CAB8C-B43A-4E76-B906-034A395C1429}.Release|x64.ActiveCfg = Release|Any CPU
{996CAB8C-B43A-4E76-B906-034A395C1429}.Release|x64.Build.0 = Release|Any CPU
{996CAB8C-B43A-4E76-B906-034A395C1429}.Release|x86.ActiveCfg = Release|Any CPU
{996CAB8C-B43A-4E76-B906-034A395C1429}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -1530,6 +1544,7 @@ Global
SolutionGuid = {2EB6265F-323A-4BF3-969E-003D64A14B64}
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{996CAB8C-B43A-4E76-B906-034A395C1429} = {323C198D-A8C6-4EB0-8B79-72624275E35F}
{146865E5-7DFF-4CC2-8521-9E22CFCEEA20} = {323C198D-A8C6-4EB0-8B79-72624275E35F}
{A43B5ACA-1209-46E9-84DB-A48553ED623E} = {323C198D-A8C6-4EB0-8B79-72624275E35F}
{1EAF34DA-6D16-4F5E-86F4-344185F53942} = {323C198D-A8C6-4EB0-8B79-72624275E35F}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class CompanyDataBusinessLogic : ICompanyDataBusinessLogic
private readonly IMailingService _mailingService;
private readonly ICustodianService _custodianService;
private readonly IDateTimeProvider _dateTimeProvider;
private readonly IIdentityService _identityService;
private readonly IIdentityData _identityData;
private readonly CompanyDataSettings _settings;

/// <summary>
Expand All @@ -66,14 +66,14 @@ public CompanyDataBusinessLogic(IPortalRepositories portalRepositories, IMailing
_mailingService = mailingService;
_custodianService = custodianService;
_dateTimeProvider = dateTimeProvider;
_identityService = identityService;
_identityData = identityService.IdentityData;
_settings = options.Value;
}

/// <inheritdoc/>
public async Task<CompanyAddressDetailData> GetCompanyDetailsAsync()
{
var companyId = _identityService.IdentityData.CompanyId;
var companyId = _identityData.CompanyId;
var result = await _portalRepositories.GetInstance<ICompanyRepository>().GetCompanyDetailsAsync(companyId).ConfigureAwait(false);
if (result == null)
{
Expand All @@ -84,12 +84,12 @@ public async Task<CompanyAddressDetailData> GetCompanyDetailsAsync()

/// <inheritdoc/>
public IAsyncEnumerable<CompanyAssignedUseCaseData> GetCompanyAssigendUseCaseDetailsAsync() =>
_portalRepositories.GetInstance<ICompanyRepository>().GetCompanyAssigendUseCaseDetailsAsync(_identityService.IdentityData.CompanyId);
_portalRepositories.GetInstance<ICompanyRepository>().GetCompanyAssigendUseCaseDetailsAsync(_identityData.CompanyId);

/// <inheritdoc/>
public async Task<bool> CreateCompanyAssignedUseCaseDetailsAsync(Guid useCaseId)
{
var companyId = _identityService.IdentityData.CompanyId;
var companyId = _identityData.CompanyId;
var companyRepositories = _portalRepositories.GetInstance<ICompanyRepository>();
var useCaseDetails = await companyRepositories.GetCompanyStatusAndUseCaseIdAsync(companyId, useCaseId).ConfigureAwait(false);
if (!useCaseDetails.IsActiveCompanyStatus)
Expand All @@ -108,7 +108,7 @@ public async Task<bool> CreateCompanyAssignedUseCaseDetailsAsync(Guid useCaseId)
/// <inheritdoc/>
public async Task RemoveCompanyAssignedUseCaseDetailsAsync(Guid useCaseId)
{
var companyId = _identityService.IdentityData.CompanyId;
var companyId = _identityData.CompanyId;
var companyRepositories = _portalRepositories.GetInstance<ICompanyRepository>();
var useCaseDetails = await companyRepositories.GetCompanyStatusAndUseCaseIdAsync(companyId, useCaseId).ConfigureAwait(false);
if (!useCaseDetails.IsActiveCompanyStatus)
Expand All @@ -125,7 +125,7 @@ public async Task RemoveCompanyAssignedUseCaseDetailsAsync(Guid useCaseId)

public async IAsyncEnumerable<CompanyRoleConsentViewData> GetCompanyRoleAndConsentAgreementDetailsAsync(string? languageShortName)
{
var companyId = _identityService.IdentityData.CompanyId;
var companyId = _identityData.CompanyId;
if (languageShortName != null && !await _portalRepositories.GetInstance<ILanguageRepository>().IsValidLanguageCode(languageShortName).ConfigureAwait(false))
{
throw new ControllerArgumentException($"language {languageShortName} is not a valid languagecode");
Expand Down Expand Up @@ -168,12 +168,11 @@ public async Task CreateCompanyRoleAndConsentAgreementDetailsAsync(IEnumerable<C
return;
}

var identity = _identityService.IdentityData;
var companyRepositories = _portalRepositories.GetInstance<ICompanyRepository>();
var result = await companyRepositories.GetCompanyRolesDataAsync(identity.CompanyId, companyRoleConsentDetails.Select(x => x.CompanyRole)).ConfigureAwait(false);
var result = await companyRepositories.GetCompanyRolesDataAsync(_identityData.CompanyId, companyRoleConsentDetails.Select(x => x.CompanyRole)).ConfigureAwait(false);
if (!result.IsValidCompany)
{
throw new ConflictException($"company {identity.CompanyId} does not exist");
throw new ConflictException($"company {_identityData.CompanyId} does not exist");
}
if (!result.IsCompanyActive)
{
Expand Down Expand Up @@ -219,14 +218,14 @@ public async Task CreateCompanyRoleAndConsentAgreementDetailsAsync(IEnumerable<C
_portalRepositories.GetInstance<IConsentRepository>().AddAttachAndModifyConsents(
result.ConsentStatusDetails,
joined.SelectMany(x => x.Agreements).DistinctBy(active => active.AgreementId).Select(active => (active.AgreementId, active.ConsentStatus)).ToList(),
identity.CompanyId,
identity.UserId,
_identityData.CompanyId,
_identityData.IdentityId,
_dateTimeProvider.OffsetNow);

var companyRolesRepository = _portalRepositories.GetInstance<ICompanyRolesRepository>();

companyRolesRepository.CreateCompanyAssignedRoles(identity.CompanyId, joined.Where(j => j.AllActiveAgreements && !result.CompanyRoleIds.Contains(j.CompanyRoleId)).Select(x => x.CompanyRoleId));
companyRolesRepository.RemoveCompanyAssignedRoles(identity.CompanyId, joined.Where(j => j.AllInActiveAgreements && result.CompanyRoleIds.Contains(j.CompanyRoleId)).Select(x => x.CompanyRoleId));
companyRolesRepository.CreateCompanyAssignedRoles(_identityData.CompanyId, joined.Where(j => j.AllActiveAgreements && !result.CompanyRoleIds.Contains(j.CompanyRoleId)).Select(x => x.CompanyRoleId));
companyRolesRepository.RemoveCompanyAssignedRoles(_identityData.CompanyId, joined.Where(j => j.AllInActiveAgreements && result.CompanyRoleIds.Contains(j.CompanyRoleId)).Select(x => x.CompanyRoleId));

await _portalRepositories.SaveAsync();
}
Expand All @@ -235,7 +234,7 @@ public async Task CreateCompanyRoleAndConsentAgreementDetailsAsync(IEnumerable<C
public async Task<IEnumerable<UseCaseParticipationData>> GetUseCaseParticipationAsync(string? language) =>
await _portalRepositories
.GetInstance<ICompanySsiDetailsRepository>()
.GetUseCaseParticipationForCompany(_identityService.IdentityData.CompanyId, language ?? Constants.DefaultLanguage)
.GetUseCaseParticipationForCompany(_identityData.CompanyId, language ?? Constants.DefaultLanguage)
.Select(x => new UseCaseParticipationData(
x.UseCase,
x.Description,
Expand All @@ -261,7 +260,7 @@ await _portalRepositories
public async Task<IEnumerable<SsiCertificateData>> GetSsiCertificatesAsync() =>
await _portalRepositories
.GetInstance<ICompanySsiDetailsRepository>()
.GetSsiCertificates(_identityService.IdentityData.CompanyId)
.GetSsiCertificates(_identityData.CompanyId)
.Select(x => new SsiCertificateData(
x.CredentialType,
x.SsiDetailData.Select(d => new CompanySsiDetailData(
Expand Down Expand Up @@ -310,8 +309,7 @@ private async Task HandleSsiCreationAsync(
ICompanySsiDetailsRepository companyCredentialDetailsRepository,
CancellationToken cancellationToken)
{
var identity = _identityService.IdentityData;
if (await companyCredentialDetailsRepository.CheckSsiDetailsExistsForCompany(identity.CompanyId, credentialTypeId, kindId, verifiedCredentialExternalTypeDetailId).ConfigureAwait(false))
if (await companyCredentialDetailsRepository.CheckSsiDetailsExistsForCompany(_identityData.CompanyId, credentialTypeId, kindId, verifiedCredentialExternalTypeDetailId).ConfigureAwait(false))
{
throw new ControllerArgumentException("Credential request already existing");
}
Expand All @@ -320,11 +318,11 @@ private async Task HandleSsiCreationAsync(
var doc = _portalRepositories.GetInstance<IDocumentRepository>().CreateDocument(document.FileName, documentContent,
hash, mediaTypeId, DocumentTypeId.PRESENTATION, x =>
{
x.CompanyUserId = identity.UserId;
x.CompanyUserId = _identityData.IdentityId;
x.DocumentStatusId = DocumentStatusId.PENDING;
});

companyCredentialDetailsRepository.CreateSsiDetails(identity.CompanyId, credentialTypeId, doc.Id, CompanySsiDetailStatusId.PENDING, identity.UserId, details =>
companyCredentialDetailsRepository.CreateSsiDetails(_identityData.CompanyId, credentialTypeId, doc.Id, CompanySsiDetailStatusId.PENDING, _identityData.IdentityId, details =>
{
if (verifiedCredentialExternalTypeDetailId != null)
{
Expand Down Expand Up @@ -381,7 +379,7 @@ private async Task HandleSsiCreationAsync(
public async Task ApproveCredential(Guid credentialId, CancellationToken cancellationToken)
{
var companySsiRepository = _portalRepositories.GetInstance<ICompanySsiDetailsRepository>();
var userId = _identityService.IdentityId;
var userId = _identityData.IdentityId;
var (exists, data) = await companySsiRepository.GetSsiApprovalData(credentialId).ConfigureAwait(false);
if (!exists)
{
Expand Down Expand Up @@ -455,7 +453,7 @@ public async Task ApproveCredential(Guid credentialId, CancellationToken cancell
public async Task RejectCredential(Guid credentialId)
{
var companySsiRepository = _portalRepositories.GetInstance<ICompanySsiDetailsRepository>();
var userId = _identityService.IdentityId;
var userId = _identityData.IdentityId;
var (exists, status, type, requesterId, requesterEmail, requesterFirstname, requesterLastname) = await companySsiRepository.GetSsiRejectionData(credentialId).ConfigureAwait(false);
if (!exists)
{
Expand Down Expand Up @@ -501,5 +499,5 @@ public async Task RejectCredential(Guid credentialId)

/// <inheritdoc />
public IAsyncEnumerable<VerifiedCredentialTypeId> GetCertificateTypes() =>
_portalRepositories.GetInstance<ICompanySsiDetailsRepository>().GetCertificateTypes(_identityService.IdentityData.CompanyId);
_portalRepositories.GetInstance<ICompanySsiDetailsRepository>().GetCertificateTypes(_identityData.CompanyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ConnectorsBusinessLogic : IConnectorsBusinessLogic
{
private readonly IPortalRepositories _portalRepositories;
private readonly ISdFactoryBusinessLogic _sdFactoryBusinessLogic;
private readonly IIdentityService _identityService;
private readonly IIdentityData _identityData;
private readonly ILogger<ConnectorsBusinessLogic> _logger;
private readonly ConnectorsSettings _settings;
private static readonly Regex bpnRegex = new(@"(\w|\d){16}", RegexOptions.None, TimeSpan.FromSeconds(1));
Expand All @@ -60,7 +60,7 @@ public ConnectorsBusinessLogic(IPortalRepositories portalRepositories, IOptions<
_portalRepositories = portalRepositories;
_settings = options.Value;
_sdFactoryBusinessLogic = sdFactoryBusinessLogic;
_identityService = identityService;
_identityData = identityService.IdentityData;
_logger = logger;
}

Expand All @@ -70,19 +70,19 @@ public ConnectorsBusinessLogic(IPortalRepositories portalRepositories, IOptions<
page,
size,
_settings.MaxPageSize,
_portalRepositories.GetInstance<IConnectorsRepository>().GetAllCompanyConnectorsForCompanyId(_identityService.IdentityData.CompanyId));
_portalRepositories.GetInstance<IConnectorsRepository>().GetAllCompanyConnectorsForCompanyId(_identityData.CompanyId));

/// <inheritdoc/>
public Task<Pagination.Response<ManagedConnectorData>> GetManagedConnectorForCompany(int page, int size) =>
Pagination.CreateResponseAsync(
page,
size,
_settings.MaxPageSize,
_portalRepositories.GetInstance<IConnectorsRepository>().GetManagedConnectorsForCompany(_identityService.IdentityData.CompanyId));
_portalRepositories.GetInstance<IConnectorsRepository>().GetManagedConnectorsForCompany(_identityData.CompanyId));

public async Task<ConnectorData> GetCompanyConnectorData(Guid connectorId)
{
var companyId = _identityService.IdentityData.CompanyId;
var companyId = _identityData.CompanyId;
var result = await _portalRepositories.GetInstance<IConnectorsRepository>().GetConnectorByIdForCompany(connectorId, companyId).ConfigureAwait(false);
if (result == default)
{
Expand All @@ -104,7 +104,7 @@ public Task<Guid> CreateManagedConnectorAsync(ManagedConnectorInputModel connect

private async Task<Guid> CreateConnectorInternalAsync(ConnectorInputModel connectorInputModel, CancellationToken cancellationToken)
{
var companyId = _identityService.IdentityData.CompanyId;
var companyId = _identityData.CompanyId;
var (name, connectorUrl, location, technicalUserId) = connectorInputModel;
await CheckLocationExists(location);

Expand Down Expand Up @@ -135,7 +135,7 @@ private async Task<Guid> CreateConnectorInternalAsync(ConnectorInputModel connec

private async Task<Guid> CreateManagedConnectorInternalAsync(ManagedConnectorInputModel connectorInputModel, CancellationToken cancellationToken)
{
var companyId = _identityService.IdentityData.CompanyId;
var companyId = _identityData.CompanyId;
var (name, connectorUrl, location, subscriptionId, technicalUserId) = connectorInputModel;
await CheckLocationExists(location).ConfigureAwait(false);

Expand Down Expand Up @@ -252,7 +252,7 @@ await _sdFactoryBusinessLogic
/// <inheritdoc/>
public async Task DeleteConnectorAsync(Guid connectorId)
{
var companyId = _identityService.IdentityData.CompanyId;
var companyId = _identityData.CompanyId;
var connectorsRepository = _portalRepositories.GetInstance<IConnectorsRepository>();
var result = await connectorsRepository.GetConnectorDeleteDataAsync(connectorId, companyId).ConfigureAwait(false) ?? throw new NotFoundException($"Connector {connectorId} does not exist");
if (!result.IsProvidingOrHostCompany)
Expand Down Expand Up @@ -369,7 +369,7 @@ public async Task ProcessClearinghouseSelfDescription(SelfDescriptionResponseDat
throw new ConflictException($"Connector {data.ExternalId} already has a document assigned");
}

await _sdFactoryBusinessLogic.ProcessFinishSelfDescriptionLpForConnector(data, _identityService.IdentityId, cancellationToken).ConfigureAwait(false);
await _sdFactoryBusinessLogic.ProcessFinishSelfDescriptionLpForConnector(data, _identityData.IdentityId, cancellationToken).ConfigureAwait(false);
await _portalRepositories.SaveAsync().ConfigureAwait(false);
}

Expand All @@ -382,11 +382,10 @@ public Task UpdateConnectorUrl(Guid connectorId, ConnectorUpdateRequest data)

private async Task UpdateConnectorUrlInternal(Guid connectorId, ConnectorUpdateRequest data)
{
var identity = _identityService.IdentityData;
var connectorsRepository = _portalRepositories
.GetInstance<IConnectorsRepository>();
var connector = await connectorsRepository
.GetConnectorUpdateInformation(connectorId, identity.CompanyId)
.GetConnectorUpdateInformation(connectorId, _identityData.CompanyId)
.ConfigureAwait(false);

if (connector == null)
Expand All @@ -401,7 +400,7 @@ private async Task UpdateConnectorUrlInternal(Guid connectorId, ConnectorUpdateR

if (!connector.IsHostCompany)
{
throw new ForbiddenException($"Company {identity.CompanyId} is not the connectors host company");
throw new ForbiddenException($"Company {_identityData.CompanyId} is not the connectors host company");
}

if (connector.Status == ConnectorStatusId.INACTIVE)
Expand All @@ -412,7 +411,7 @@ private async Task UpdateConnectorUrlInternal(Guid connectorId, ConnectorUpdateR
var bpn = connector.Type == ConnectorTypeId.CONNECTOR_AS_A_SERVICE
? connector.Bpn
: await _portalRepositories.GetInstance<IUserRepository>()
.GetCompanyBpnForIamUserAsync(identity.UserId)
.GetCompanyBpnForIamUserAsync(_identityData.IdentityId)
.ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(bpn))
{
Expand All @@ -430,5 +429,5 @@ private async Task UpdateConnectorUrlInternal(Guid connectorId, ConnectorUpdateR
/// <inheritdoc />
public IAsyncEnumerable<OfferSubscriptionConnectorData> GetConnectorOfferSubscriptionData(bool? connectorIdSet) =>
_portalRepositories.GetInstance<IOfferSubscriptionsRepository>()
.GetConnectorOfferSubscriptionData(connectorIdSet, _identityService.IdentityData.CompanyId);
.GetConnectorOfferSubscriptionData(connectorIdSet, _identityData.CompanyId);
}
Loading

0 comments on commit 08683b4

Please sign in to comment.