Editing a template version is now immutable.
This commit is contained in:
parent
007522ceba
commit
9a360feb7f
@ -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; }
|
||||
|
||||
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user