Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Examples/Projects/Project/Project.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Project
titlePlural: Projects
instanceTitle: '{{ Title }}'

headerFields:
- property: Title
Expand Down
6 changes: 4 additions & 2 deletions UvA.Workflow.Api/Submissions/Dtos/SubmissionDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ public record SubmissionDto(
string InstanceId,
Answer[] Answers,
DateTime? DateSubmitted,
FormDto Form)
FormDto Form,
RoleAction[] Permissions)
{
public static SubmissionDto FromEntity(WorkflowInstance inst,
Form form,
Expand All @@ -138,7 +139,8 @@ public static SubmissionDto FromEntity(WorkflowInstance inst,
inst.Id,
shownQuestionIds == null ? [] : Answer.Create(inst, form, shownQuestionIds, fileService),
sub?.Date,
FormDto.Create(form)
FormDto.Create(form),
[] // TODO: set permissions
);
}

Expand Down
15 changes: 12 additions & 3 deletions UvA.Workflow.Api/WorkflowInstances/Dtos/WorkflowInstanceDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ public record WorkflowInstanceBasicDto(

public record WorkflowInstanceDto(
string Id,
string? Title,
EntityTypeDto EntityType,
string? CurrentStep,
Dictionary<string, object> Properties,
Dictionary<string, InstanceEventDto> Events,
string? ParentId,
ActionDto[] Actions,
FieldDto[] Fields,
Expand All @@ -26,7 +25,17 @@ RoleAction[] Permissions

public record FieldDto();

public record StepDto();
public record StepDto(string Id, BilingualString Title, string? Event, DateTime? DateCompleted, StepDto[]? Children)
{
public static StepDto Create(Step step, WorkflowInstance instance)
=> new(
step.Name,
step.DisplayTitle,
step.EndEvent,
step.GetEndDate(instance),
step.Children.Length != 0 ? step.Children.Select(s => Create(s, instance)).ToArray() : null
);
}

public record ActionDto(
ActionType Type,
Expand Down
18 changes: 10 additions & 8 deletions UvA.Workflow.Api/WorkflowInstances/WorkflowInstanceDtoService.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
using UvA.Workflow.Api.EntityTypes.Dtos;
using UvA.Workflow.Api.Submissions.Dtos;
using UvA.Workflow.Api.WorkflowInstances.Dtos;

namespace UvA.Workflow.Api.WorkflowInstances;

public class WorkflowInstanceDtoService(InstanceService instanceService, ModelService modelService)
public class WorkflowInstanceDtoService(InstanceService instanceService, ModelService modelService,
FileService fileService)
{
/// <summary>
/// Creates a WorkflowInstanceDto from a WorkflowInstance domain entity
/// </summary>
public async Task<WorkflowInstanceDto> Create(WorkflowInstance instance, CancellationToken ct)
{
var actions = await instanceService.GetAllowedActions(instance, ct);
var submissions = await instanceService.GetAllowedSubmissions(instance, ct);
var entityType = modelService.EntityTypes[instance.EntityType];

return new WorkflowInstanceDto(
instance.Id,
entityType.InstanceTitleTemplate?.Apply(modelService.CreateContext(instance)),
EntityTypeDto.Create(modelService.EntityTypes[instance.EntityType]),
instance.CurrentStep,
instance.Properties.ToDictionary(k => k.Key, v => BsonTypeMapper.MapToDotNetValue(v.Value)),
instance.Events.ToDictionary(
kvp => kvp.Key,
kvp => InstanceEventDto.Create(kvp.Value)
),
instance.ParentId,
actions.Select(ActionDto.Create).ToArray(),
[],
[],
[],
entityType.Steps.Select(s => StepDto.Create(s, instance)).ToArray(),
submissions
.Select(s => SubmissionDto.FromEntity(instance, s.Form, s.Event, s.QuestionStatus, fileService))
.ToArray(),
[]
);
}
Expand Down
20 changes: 20 additions & 0 deletions UvA.Workflow/WorkflowInstances/InstanceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,24 @@ public async Task<ICollection<AllowedAction>> GetAllowedActions(WorkflowInstance

return actions;
}

public record AllowedSubmission(InstanceEvent Event, Form Form, Dictionary<string, QuestionStatus> QuestionStatus);

public async Task<IEnumerable<AllowedSubmission>> GetAllowedSubmissions(WorkflowInstance instance, CancellationToken ct)
{
var allowed = await rightsService.GetAllowedActions(instance, RoleAction.View);
var allowedHidden = await rightsService.GetAllowedActions(instance, RoleAction.ViewHidden);

var forms = allowed.SelectMany(a => a.AllForms).Distinct()
.ToDictionary(f => f, f => modelService.GetForm(instance, f));
var hiddenForms = allowedHidden.SelectMany(a => a.AllForms).Distinct().ToList();

var subs = instance.Events
.Select(e => e.Value)
.Where(s => forms.ContainsKey(s.Id))
.OrderBy(s => s.Date)
.ToList();
return subs.Select(s => new AllowedSubmission(s, forms[s.Id],
modelService.GetQuestionStatus(instance, forms[s.Id], hiddenForms.Contains(s.Id))));
}
}