Skip to content
Draft
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
14 changes: 14 additions & 0 deletions roles/api/files/replace_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -36540,6 +36540,7 @@
"locked",
"assigned_group",
"external_ticket_id",
"pre_workflow_ticket_reference",
"requester_dn",
"requester_group",
"title",
Expand All @@ -36566,6 +36567,7 @@
"id",
"assigned_group",
"external_ticket_id",
"pre_workflow_ticket_reference",
"requester_dn",
"requester_group",
"title",
Expand Down Expand Up @@ -36593,6 +36595,7 @@
"id",
"assigned_group",
"external_ticket_id",
"pre_workflow_ticket_reference",
"requester_dn",
"requester_group",
"title",
Expand Down Expand Up @@ -36620,6 +36623,7 @@
"id",
"assigned_group",
"external_ticket_id",
"pre_workflow_ticket_reference",
"requester_dn",
"requester_group",
"title",
Expand All @@ -36646,6 +36650,7 @@
"id",
"assigned_group",
"external_ticket_id",
"pre_workflow_ticket_reference",
"requester_dn",
"requester_group",
"title",
Expand All @@ -36672,6 +36677,7 @@
"id",
"assigned_group",
"external_ticket_id",
"pre_workflow_ticket_reference",
"requester_dn",
"requester_group",
"title",
Expand All @@ -36698,6 +36704,7 @@
"id",
"assigned_group",
"external_ticket_id",
"pre_workflow_ticket_reference",
"requester_dn",
"requester_group",
"title",
Expand All @@ -36724,6 +36731,7 @@
"id",
"assigned_group",
"external_ticket_id",
"pre_workflow_ticket_reference",
"requester_dn",
"requester_group",
"title",
Expand Down Expand Up @@ -36751,6 +36759,7 @@
"id",
"assigned_group",
"external_ticket_id",
"pre_workflow_ticket_reference",
"requester_dn",
"requester_group",
"title",
Expand Down Expand Up @@ -36778,6 +36787,7 @@
"id",
"assigned_group",
"external_ticket_id",
"pre_workflow_ticket_reference",
"requester_dn",
"requester_group",
"title",
Expand All @@ -36804,6 +36814,7 @@
"id",
"assigned_group",
"external_ticket_id",
"pre_workflow_ticket_reference",
"requester_dn",
"requester_group",
"title",
Expand Down Expand Up @@ -36831,6 +36842,7 @@
"id",
"assigned_group",
"external_ticket_id",
"pre_workflow_ticket_reference",
"requester_dn",
"requester_group",
"title",
Expand Down Expand Up @@ -36858,6 +36870,7 @@
"id",
"assigned_group",
"external_ticket_id",
"pre_workflow_ticket_reference",
"requester_dn",
"requester_group",
"title",
Expand All @@ -36884,6 +36897,7 @@
"id",
"assigned_group",
"external_ticket_id",
"pre_workflow_ticket_reference",
"requester_dn",
"requester_group",
"title",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fragment ticketDetails on request_ticket {
reason
external_ticket_id
external_ticket_source
pre_workflow_ticket_reference
ticket_deadline
ticket_priority
locked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fragment ticketDetailsReqTaskOverview on request_ticket {
reason
external_ticket_id
external_ticket_source
pre_workflow_ticket_reference
ticket_deadline
ticket_priority
locked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fragment ticketOverview on request_ticket {
reason
external_ticket_id
external_ticket_source
pre_workflow_ticket_reference
ticket_deadline
ticket_priority
locked
Expand Down
2 changes: 2 additions & 0 deletions roles/common/files/fwo-api-calls/request/newTicket.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mutation newTicket(
$requesterId: Int
$deadline: timestamp
$priority: Int
$preWorkflowTicketReference: String
$locked: Boolean
$requestTasks: request_reqtask_arr_rel_insert_input
) {
Expand All @@ -15,6 +16,7 @@ mutation newTicket(
requester_id: $requesterId
ticket_deadline: $deadline
ticket_priority: $priority
pre_workflow_ticket_reference: $preWorkflowTicketReference
locked: $locked
reqtasks: $requestTasks
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ create table request.ticket
reason text,
external_ticket_id varchar,
external_ticket_source int,
pre_workflow_ticket_reference varchar,
ticket_deadline Timestamp,
ticket_priority int,
locked boolean NOT NULL DEFAULT FALSE
Expand Down
2 changes: 2 additions & 0 deletions roles/database/files/upgrade/9.5.2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,5 @@ CREATE INDEX IF NOT EXISTS idx_change_history_audit_proof ON public.change_histo
GRANT SELECT ON public.change_history TO fwo_ro;

GRANT SELECT ON SEQUENCE public.change_history_id_seq TO fwo_ro;

ALTER TABLE request.ticket ADD COLUMN IF NOT EXISTS pre_workflow_ticket_reference varchar;
5 changes: 5 additions & 0 deletions roles/lib/files/FWO.Data/Workflow/WfTicketBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class WfTicketBase : WfStatefulObject
[JsonProperty("external_ticket_source"), JsonPropertyName("external_ticket_source")]
public int? ExternalTicketSource { get; set; }

[JsonProperty("pre_workflow_ticket_reference"), JsonPropertyName("pre_workflow_ticket_reference")]
public string? PreWorkflowTicketReference { get; set; }

[JsonProperty("ticket_deadline"), JsonPropertyName("ticket_deadline")]
public DateTime? Deadline { get; set; }

Expand Down Expand Up @@ -66,6 +69,7 @@ public WfTicketBase(WfTicketBase ticket) : base(ticket)
Reason = ticket.Reason;
ExternalTicketId = ticket.ExternalTicketId;
ExternalTicketSource = ticket.ExternalTicketSource;
PreWorkflowTicketReference = ticket.PreWorkflowTicketReference;
Deadline = ticket.Deadline;
Priority = ticket.Priority;
Locked = ticket.Locked;
Expand All @@ -79,6 +83,7 @@ public override bool Sanitize()
RequesterGroup = RequesterGroup.SanitizeLdapPathOpt(ref shortened);
Reason = Reason.SanitizeOpt(ref shortened);
ExternalTicketId = ExternalTicketId.SanitizeOpt(ref shortened);
PreWorkflowTicketReference = PreWorkflowTicketReference.SanitizeOpt(ref shortened);
return shortened;
}
}
Expand Down
1 change: 1 addition & 0 deletions roles/lib/files/FWO.Services/Workflow/WfDbAccessTickets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public async Task<WfTicket> AddTicketToDb(WfTicket ticket)
ticket.UpdateCidrsInTaskElements();
ticket.UpdateIpStringsFromCidrInTaskElements();
var variables = BuildTicketVariables(ticket);
variables["preWorkflowTicketReference"] = ticket.PreWorkflowTicketReference;
variables["requesterId"] = ticket.Requester?.DbId;
variables["requestTasks"] = new WfTicketWriter(ticket);
variables["locked"] = ticket.Locked;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public sealed class CreateRequestRequestExample : ApiExampleProvider<CreateReque
public override CreateRequestRequest GetExample() => new()
{
RequestorName = "Alice Example",
PreWorkflowTicketReference = "Ticket-12345",
RequestorId = "alice",
RuleContactName = "Bob Approver",
RuleContactId = "bob",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ namespace FWO.Middleware.Server.Requests;
/// </summary>
public sealed class CreateRequestRequest
{
/// <summary>
/// Gets the reference of the ticket in the workflow which preceded this workflow.
/// </summary>
[JsonPropertyName("preWorkflowTicketReference")]
public string? PreWorkflowTicketReference { get; set; }

/// <summary>
/// Gets the RequestorName value.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ private static WfTicket BuildTicket(CreateRequestRequest request, int ticketStat
return new WfTicket
{
Title = request.Title,
PreWorkflowTicketReference = request.PreWorkflowTicketReference,
StateId = ticketStateId,
Requester = BuildRequester(request, requesterId),
Reason = BuildRequestReason(request),
Expand Down
10 changes: 10 additions & 0 deletions roles/tests-unit/files/FWO.Test/FlowRequestContractTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ namespace FWO.Test;
internal class FlowRequestContractTest
{

[Test]
public void CreateRequestRequest_UsesExpectedPreWorkflowTicketReferenceJsonName()
{
CreateRequestRequest request = new() { PreWorkflowTicketReference = "Ticket-12345" };

string json = JsonSerializer.Serialize(request);

Assert.That(json, Does.Contain("\"preWorkflowTicketReference\":\"Ticket-12345\""));
}

[Test]
public void GetRequestStatusRequest_RequiresTicketId()
{
Expand Down
4 changes: 4 additions & 0 deletions roles/tests-unit/files/FWO.Test/FlowRequestServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public async Task CreateRequest_ReturnsCreatedTicketAndResolvesTemporaryIds(
RequestorId = "alice",
RuleContactName = "Bob Approver",
RuleContactId = "bob",
PreWorkflowTicketReference = "Ticket-12345",
Title = "Allow HTTPS to app server",
AddressObjects =
[
Expand Down Expand Up @@ -292,6 +293,8 @@ public async Task CreateRequest_ReturnsCreatedTicketAndResolvesTemporaryIds(
Assert.That(apiConnection.SentQueries, Contains.Item(RequestQueries.getTicketById));
Assert.That(apiConnection.LastTicketWriter, Is.Not.Null);
Assert.That(apiConnection.LastTicketWriter!.Tasks, Has.Count.EqualTo(1));
Assert.That(GetVariable(apiConnection.NewTicketVariables, "preWorkflowTicketReference"), Is.EqualTo("Ticket-12345"));
Assert.That(apiConnection.CreatedTicket!.PreWorkflowTicketReference, Is.EqualTo("Ticket-12345"));
Assert.That(apiConnection.LastTicketWriter.Tasks[0].TaskType, Is.EqualTo(WfTaskType.access.ToString()));
Assert.That(apiConnection.LastTicketWriter.Tasks[0].RuleAction, Is.EqualTo(1));
Assert.That(apiConnection.LastTicketWriter.Tasks[0].Elements.WfElementList, Has.Count.EqualTo(3));
Expand Down Expand Up @@ -2807,6 +2810,7 @@ private static WfTicket BuildCreatedTicket(object? variables, long ticketId)
Title = Convert.ToString(GetVariable(variables, "title")) ?? "",
StateId = Convert.ToInt32(GetVariable(variables, "state") ?? 0),
Reason = Convert.ToString(GetVariable(variables, "reason")) ?? "",
PreWorkflowTicketReference = Convert.ToString(GetVariable(variables, "preWorkflowTicketReference")),
Locked = Convert.ToBoolean(GetVariable(variables, "locked") ?? false),
Priority = Convert.ToInt32(GetVariable(variables, "priority") ?? 0),
Deadline = GetVariable(variables, "deadline") is DateTime deadline ? deadline : null,
Expand Down
30 changes: 30 additions & 0 deletions roles/tests-unit/files/FWO.Test/WfDbAccessTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private sealed class WfDbAccessTestApiConn : SimulatedApiConnection
public int AssignImplCommentCallCount { get; private set; }
public int UpdateTicketStateCallCount { get; private set; }
public int AddHistoryEntryCallCount { get; private set; }
public object? LastUpdateTicketVariables { get; private set; }
public object? LastHistoryVariables { get; private set; }
public string? LastHistoryQuery { get; private set; }
public long NewApprovalId { get; set; } = 301;
Expand Down Expand Up @@ -123,6 +124,7 @@ public override Task<T> SendQueryAsync<T>(string query, object? variables = null
}
if (query == RequestQueries.updateTicket)
{
LastUpdateTicketVariables = variables;
return Task.FromResult((T)(object)new ReturnId { UpdatedIdLong = UpdatedTicketId });
}
if (query == RequestQueries.updateApproval)
Expand Down Expand Up @@ -604,6 +606,34 @@ await actionHandler.Init(new List<WfState>
Assert.That(result, Is.SameAs(ticket));
}

[Test]
public async Task UpdateTicketInDb_DoesNotPersistCreateOnlyPreWorkflowTicketReference()
{
WfDbAccessTestApiConn apiConn = new()
{
UpdatedTicketId = 101
};
UserConfig userConfig = new();
await userConfig.InitWithUserId(apiConn, 42, false);
WfHandler wfHandler = new();
ActionHandler actionHandler = new(apiConn, wfHandler);
await actionHandler.Init([]);
WfDbAccess dbAccess = new(DefaultInit.DoNothing, userConfig, apiConn, actionHandler, false, WorkflowPhases.request);

await dbAccess.UpdateTicketInDb(new WfTicket
{
Id = 101,
PreWorkflowTicketReference = "Changed reference"
});

Dictionary<string, object?> variables = (Dictionary<string, object?>)apiConn.LastUpdateTicketVariables!;
Assert.Multiple(() =>
{
Assert.That(variables.ContainsKey("preWorkflowTicketReference"), Is.False);
Assert.That(RequestQueries.updateTicket, Does.Not.Contain("pre_workflow_ticket_reference"));
});
}

[Test]
public async Task UpdateTicketInDb_ReportsMismatchWhenReturnedIdDiffers()
{
Expand Down
Loading