Skip to content

Commit 85dc8de

Browse files
authored
DN-3377 feat: Return submission and step info (#12)
1 parent c919fe9 commit 85dc8de

File tree

5 files changed

+47
-13
lines changed

5 files changed

+47
-13
lines changed

Examples/Projects/Project/Project.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: Project
22
titlePlural: Projects
3+
instanceTitle: '{{ Title }}'
34

45
headerFields:
56
- property: Title

UvA.Workflow.Api/Submissions/Dtos/SubmissionDto.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ public record SubmissionDto(
125125
string InstanceId,
126126
Answer[] Answers,
127127
DateTime? DateSubmitted,
128-
FormDto Form)
128+
FormDto Form,
129+
RoleAction[] Permissions)
129130
{
130131
public static SubmissionDto FromEntity(WorkflowInstance inst,
131132
Form form,
@@ -138,7 +139,8 @@ public static SubmissionDto FromEntity(WorkflowInstance inst,
138139
inst.Id,
139140
shownQuestionIds == null ? [] : Answer.Create(inst, form, shownQuestionIds, fileService),
140141
sub?.Date,
141-
FormDto.Create(form)
142+
FormDto.Create(form),
143+
[] // TODO: set permissions
142144
);
143145
}
144146

UvA.Workflow.Api/WorkflowInstances/Dtos/WorkflowInstanceDto.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ public record WorkflowInstanceBasicDto(
1212

1313
public record WorkflowInstanceDto(
1414
string Id,
15+
string? Title,
1516
EntityTypeDto EntityType,
1617
string? CurrentStep,
17-
Dictionary<string, object> Properties,
18-
Dictionary<string, InstanceEventDto> Events,
1918
string? ParentId,
2019
ActionDto[] Actions,
2120
FieldDto[] Fields,
@@ -26,7 +25,17 @@ RoleAction[] Permissions
2625

2726
public record FieldDto();
2827

29-
public record StepDto();
28+
public record StepDto(string Id, BilingualString Title, string? Event, DateTime? DateCompleted, StepDto[]? Children)
29+
{
30+
public static StepDto Create(Step step, WorkflowInstance instance)
31+
=> new(
32+
step.Name,
33+
step.DisplayTitle,
34+
step.EndEvent,
35+
step.GetEndDate(instance),
36+
step.Children.Length != 0 ? step.Children.Select(s => Create(s, instance)).ToArray() : null
37+
);
38+
}
3039

3140
public record ActionDto(
3241
ActionType Type,

UvA.Workflow.Api/WorkflowInstances/WorkflowInstanceDtoService.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
using UvA.Workflow.Api.EntityTypes.Dtos;
2+
using UvA.Workflow.Api.Submissions.Dtos;
23
using UvA.Workflow.Api.WorkflowInstances.Dtos;
34

45
namespace UvA.Workflow.Api.WorkflowInstances;
56

6-
public class WorkflowInstanceDtoService(InstanceService instanceService, ModelService modelService)
7+
public class WorkflowInstanceDtoService(InstanceService instanceService, ModelService modelService,
8+
FileService fileService)
79
{
810
/// <summary>
911
/// Creates a WorkflowInstanceDto from a WorkflowInstance domain entity
1012
/// </summary>
1113
public async Task<WorkflowInstanceDto> Create(WorkflowInstance instance, CancellationToken ct)
1214
{
1315
var actions = await instanceService.GetAllowedActions(instance, ct);
16+
var submissions = await instanceService.GetAllowedSubmissions(instance, ct);
17+
var entityType = modelService.EntityTypes[instance.EntityType];
1418

1519
return new WorkflowInstanceDto(
1620
instance.Id,
21+
entityType.InstanceTitleTemplate?.Apply(modelService.CreateContext(instance)),
1722
EntityTypeDto.Create(modelService.EntityTypes[instance.EntityType]),
1823
instance.CurrentStep,
19-
instance.Properties.ToDictionary(k => k.Key, v => BsonTypeMapper.MapToDotNetValue(v.Value)),
20-
instance.Events.ToDictionary(
21-
kvp => kvp.Key,
22-
kvp => InstanceEventDto.Create(kvp.Value)
23-
),
2424
instance.ParentId,
2525
actions.Select(ActionDto.Create).ToArray(),
2626
[],
27-
[],
28-
[],
27+
entityType.Steps.Select(s => StepDto.Create(s, instance)).ToArray(),
28+
submissions
29+
.Select(s => SubmissionDto.FromEntity(instance, s.Form, s.Event, s.QuestionStatus, fileService))
30+
.ToArray(),
2931
[]
3032
);
3133
}

UvA.Workflow/WorkflowInstances/InstanceService.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,24 @@ public async Task<ICollection<AllowedAction>> GetAllowedActions(WorkflowInstance
111111

112112
return actions;
113113
}
114+
115+
public record AllowedSubmission(InstanceEvent Event, Form Form, Dictionary<string, QuestionStatus> QuestionStatus);
116+
117+
public async Task<IEnumerable<AllowedSubmission>> GetAllowedSubmissions(WorkflowInstance instance, CancellationToken ct)
118+
{
119+
var allowed = await rightsService.GetAllowedActions(instance, RoleAction.View);
120+
var allowedHidden = await rightsService.GetAllowedActions(instance, RoleAction.ViewHidden);
121+
122+
var forms = allowed.SelectMany(a => a.AllForms).Distinct()
123+
.ToDictionary(f => f, f => modelService.GetForm(instance, f));
124+
var hiddenForms = allowedHidden.SelectMany(a => a.AllForms).Distinct().ToList();
125+
126+
var subs = instance.Events
127+
.Select(e => e.Value)
128+
.Where(s => forms.ContainsKey(s.Id))
129+
.OrderBy(s => s.Date)
130+
.ToList();
131+
return subs.Select(s => new AllowedSubmission(s, forms[s.Id],
132+
modelService.GetQuestionStatus(instance, forms[s.Id], hiddenForms.Contains(s.Id))));
133+
}
114134
}

0 commit comments

Comments
 (0)