Skip to content

Commit

Permalink
feat(technicalUser): align delete dim user process
Browse files Browse the repository at this point in the history
Refs: #809
  • Loading branch information
Phil91 committed Jun 28, 2024
1 parent 28b049e commit 2f3aecd
Show file tree
Hide file tree
Showing 16 changed files with 9,634 additions and 420 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,13 @@ public async Task<int> DeleteOwnCompanyServiceAccountAsync(Guid serviceAccountId

if (result.IsDimServiceAccount)
{
if (result.ProcessId == null)
{
throw ConflictException.Create(AdministrationServiceAccountErrors.SERVICE_ACCOUNT_NOT_LINKED_TO_PROCESS, [new("serviceAccountId", serviceAccountId.ToString())]);
}

var processStepRepository = portalRepositories.GetInstance<ProcessStepRepository>();
var process = processStepRepository.CreateProcess(ProcessTypeId.DELETE_DIM_TECHNICAL_USER);
processStepRepository.CreateProcessStep(ProcessStepTypeId.DELETE_DIM_TECHNICAL_USER, ProcessStepStatusId.TODO, process.Id);
processStepRepository.CreateProcessStep(ProcessStepTypeId.DELETE_DIM_TECHNICAL_USER, ProcessStepStatusId.TODO, result.ProcessId.Value);
}

portalRepositories.GetInstance<IUserRolesRepository>().DeleteCompanyUserAssignedRoles(result.UserRoleIds.Select(userRoleId => (serviceAccountId, userRoleId)));
Expand Down Expand Up @@ -398,7 +402,7 @@ public async Task HandleServiceAccountDeletionCallback(Guid processId)
var processData = await portalRepositories.GetInstance<IProcessStepRepository>().GetProcessDataForServiceAccountDeletionCallback(processId, [ProcessStepTypeId.AWAIT_CREATE_DIM_TECHNICAL_USER_RESPONSE])
.ConfigureAwait(ConfigureAwaitOptions.None);

var context = processData.ProcessData.CreateManualProcessData(ProcessStepTypeId.AWAIT_CREATE_DIM_TECHNICAL_USER_RESPONSE, portalRepositories, () => $"externalId {processId}");
var context = processData.ProcessData.CreateManualProcessData(ProcessStepTypeId.AWAIT_DELETE_DIM_TECHNICAL_USER, portalRepositories, () => $"externalId {processId}");

if (processData.ServiceAccountId is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public class AdministrationServiceAccountErrorMessageContainer : IErrorMessageCo
{ AdministrationServiceAccountErrors.SERVICE_UNDEFINED_CLIENTID_CONFLICT, "undefined clientId for serviceAccount {serviceAccountId}"},
{ AdministrationServiceAccountErrors.SERVICE_ID_PATH_NOT_MATCH_ARGUMENT, "serviceAccountId {serviceAccountId} from path does not match the one in body {serviceAccountDetailsServiceAccountId}"},
{ AdministrationServiceAccountErrors.SERVICE_INACTIVE_CONFLICT, "serviceAccount {serviceAccountId} is already INACTIVE"},
{ AdministrationServiceAccountErrors.SERVICE_CLIENTID_NOT_NULL_CONFLICT, "clientClientId of serviceAccount {serviceAccountId} should not be null"}
{ AdministrationServiceAccountErrors.SERVICE_CLIENTID_NOT_NULL_CONFLICT, "clientClientId of serviceAccount {serviceAccountId} should not be null"},
{ AdministrationServiceAccountErrors.SERVICE_ACCOUNT_NOT_LINKED_TO_PROCESS, "Service Account {serviceAccountId} is not linked to a process" }
}.ToImmutableDictionary(x => (int)x.Key, x => x.Value);

public Type Type { get => typeof(AdministrationServiceAccountErrors); }
Expand All @@ -56,5 +57,6 @@ public enum AdministrationServiceAccountErrors
SERVICE_UNDEFINED_CLIENTID_CONFLICT,
SERVICE_ID_PATH_NOT_MATCH_ARGUMENT,
SERVICE_INACTIVE_CONFLICT,
SERVICE_CLIENTID_NOT_NULL_CONFLICT
SERVICE_CLIENTID_NOT_NULL_CONFLICT,
SERVICE_ACCOUNT_NOT_LINKED_TO_PROCESS
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public record OwnServiceAccountData(
OfferSubscriptionStatusId? OfferStatusId,
bool IsDimServiceAccount,
string? Bpn,
string ServiceAccountName
string ServiceAccountName,
Guid? ProcessId
);
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public IAsyncEnumerable<Process> GetActiveProcesses(IEnumerable<ProcessTypeId> p
public Task<(ProcessTypeId ProcessTypeId, VerifyProcessData ProcessData, Guid? ServiceAccountId)> GetProcessDataForServiceAccountDeletionCallback(Guid processId, IEnumerable<ProcessStepTypeId> processStepTypeIds) =>
_context.Processes
.AsNoTracking()
.Where(x => x.Id == processId && x.ProcessTypeId == ProcessTypeId.DELETE_DIM_TECHNICAL_USER)
.Where(x => x.Id == processId && x.ProcessTypeId == ProcessTypeId.DIM_TECHNICAL_USER)
.Select(x => new ValueTuple<ProcessTypeId, VerifyProcessData, Guid?>(
x.ProcessTypeId,
new VerifyProcessData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ public void AttachAndModifyCompanyServiceAccount(
sa.OfferSubscription!.OfferSubscriptionStatusId,
sa.DimCompanyServiceAccount != null,
sa.Identity!.Company!.BusinessPartnerNumber,
sa.Name))
sa.Name,
sa.DimUserCreationData!.ProcessId))
.SingleOrDefaultAsync();

public Task<CompanyServiceAccountDetailedData?> GetOwnCompanyServiceAccountDetailedDataUntrackedAsync(Guid serviceAccountId, Guid companyId) =>
Expand Down
Loading

0 comments on commit 2f3aecd

Please sign in to comment.