Editing a template version is now immutable.

This commit is contained in:
Colin Dawson 2026-03-02 23:57:35 +00:00
parent 007522ceba
commit 9a360feb7f
2 changed files with 32 additions and 18 deletions

View File

@ -19,12 +19,12 @@ public class WorkflowVersion : IGeneralId, ISoftDeletable
public long Id { get; set; }
[Required]
public Guid Guid { get; set; }
public Guid Guid { get; set; } = Guid.NewGuid();
public long WorkflowId { get; set; }
[Required]
public long Version { get; set; } = 0;
public long Version { get; set; } = 1;
[Required]
public long DomainId { get; set; }

View File

@ -100,14 +100,21 @@ public class WorkflowTemplateManager : IWorkflowTemplateManager
{
var domain = await _domainRepository.GetDomainById(template.DomainId!, cancellationToken) ?? throw new NotFoundException("Unable to find Domain with provided id");
version.Domain = domain;
version.DomainId = domain.Id;
version.Description = template.Description;
version.ActivityNameTemplate = template.ActivityNameTemplate;
version.Deleted = false;
version.Version = template.Version+1;
version.Tasks = template.Tasks;
version.Workflow.Name = template.WorkflowName;
var workflow = version.Workflow;
workflow.Name = template.WorkflowName;
var newVersion = new e_suite.Database.Core.Tables.Workflow.WorkflowVersion
{
Domain = domain,
DomainId = domain.Id,
Description = template.Description,
ActivityNameTemplate = template.ActivityNameTemplate,
Deleted = false,
Version = template.Version + 1,
Tasks = template.Tasks,
Workflow = workflow
};
return newVersion;
}, cancellationToken);
}
@ -122,6 +129,7 @@ public class WorkflowTemplateManager : IWorkflowTemplateManager
await AlterWorkflowTemplateVersionAsync(auditUserDetails, templateId, async version =>
{
await patch.ApplyTo(version);
return version;
}, cancellationToken);
}
@ -151,13 +159,11 @@ public class WorkflowTemplateManager : IWorkflowTemplateManager
var dbWorkflowTemplate = new WorkflowVersion
{
Guid = Guid.NewGuid(),
ActivityNameTemplate = template.ActivityNameTemplate,
Description = template.Description,
Domain = workflowDomain,
Tasks = template.Tasks,
Workflow = workflow,
Version = 1
};
//This will attempt to parse the data onto the internal workflow structure.
@ -179,23 +185,31 @@ public class WorkflowTemplateManager : IWorkflowTemplateManager
await AlterWorkflowTemplateVersionAsync(auditUserDetails, templateId, async version =>
{
version.Deleted = true;
return version;
}, cancellationToken);
}
private async Task AlterWorkflowTemplateVersionAsync(
AuditUserDetails auditUserDetails,
IGeneralIdRef generalIdRef,
Func<e_suite.Database.Core.Tables.Workflow.WorkflowVersion, Task> applyChanges,
Func<e_suite.Database.Core.Tables.Workflow.WorkflowVersion,
Task<e_suite.Database.Core.Tables.Workflow.WorkflowVersion?>> applyChanges,
CancellationToken cancellationToken
)
{
await _workflowTemplateRepository.TransactionAsync(async () =>
{
var workflowVersion = await _workflowTemplateRepository.GetWorkflowVersions().FindByGeneralIdRefAsync(generalIdRef, cancellationToken) ?? throw new NotFoundException("SsoProvider with this id does not exists");
var workflowVersion =
await _workflowTemplateRepository.GetWorkflowVersions()
.FindByGeneralIdRefAsync(generalIdRef, cancellationToken) ??
throw new NotFoundException("SsoProvider with this id does not exists");
await applyChanges(workflowVersion);
await _workflowTemplateRepository.EditWorkflowVersionAsync(auditUserDetails, workflowVersion, cancellationToken);
var newVersion = await applyChanges(workflowVersion);
if (newVersion != workflowVersion)
await _workflowTemplateRepository.AddWorkflowVersion(auditUserDetails, newVersion, cancellationToken);
else
await _workflowTemplateRepository.EditWorkflowVersionAsync(auditUserDetails, workflowVersion,
cancellationToken);
});
}