feat: swap 4949 workflow overhaul#1297
Conversation
…elated methods and types
…g and introducing WorkflowStatus model
…lowStatusId instead of id
…ntroducing CreateWorkflowConnection mutation
…rget status lookups
…vents table and updating related references
…usActionsOnConnection
…lowStructure method
…onsistency in workflow management
…efactoring IsProposalSubmittedGuard
…andling and refactoring related methods
…error for missing proposal workflow
… GuardFn and refactoring related guards
…ent metadata handling
…tatusConnectionId and refactor related properties
…authorization checks for proposal assignments
…orkflow migration scripts
… for proposal status filtering
|
What is this PR actually trying to do? The body mentions "limitations and inefficiencies" but it seems so vague I have no idea, and I don't have access to the linked ESS jira item. If this is for the "allowing a status to be on a workflow multiple times" thing mentioned at sprint planning, I thought that was going to go to a discussion thread so we could figure out what the approach to take should be? And from a review standpoint, I don't see how I'm practically going to be able to review 10k lines of code changes. |
Hi @ACLay , All valid points, and I have therefore not marked this as review:please just yet. Side note: When started on this overhaul I did not realize that workflow touches so many things in the application, and this turned out the be the biggest PR I have made. Meanwhile I will try to improve the description of the PR to give high level overview. Thanks for the proactive comment |
…mproved management
…eters and remove unused fieldMap
…tInitialStatus' and 'getInitialWorkflowStatus' for consistency
…to private for encapsulation
… workflow structure
…ks in workflow handlers
…gleInput for better flexibility
… naming consistency
…mentSafety method
… structure in InstrumentMutations tests
…mproved readability
Description
This PR
Motivation and Context
The current workflow management system has limitations and inefficiencies that are addressed by the introduction of new database structures. This change is required to enhance the system's performance and user experience.
State machine
This workflow overhaul aims to align the state changes of proposal to classical state machine behaviour. The implementation of abstract state machine can be found in

stateMachnine.ts. It matches the popularxStatelibrary interface just is much more simple.There are 5 main concepts in the state machine.
ER diagram of the new Workflow Data Structure
Entity Tables:
Transitionunder "State machine" section)Eventunder "State machine" section)Actionunder "State machine" section)Guardunder "State machine" section)Changes
This PR removes a lot of unneeded code in a way simplifying the implementation
Here are the main changes to pay attention when reviewing
Cleanup of the namings DefaultStatus and InitialStatus.
Initial statusis the status of the entity when it enters the workflow.DRAFTfor proposal andAWAITING_ESFfor safetyReview.Defaultstatusis status which system is aware of and is not created by user with through "Create status" button. These two namings were mixed and used interchangebly, but now they are separated.The table
proposal_eventsandexperiment_safety_eventshas been dropped and their alternative implementation has been implemented inguardswhich now checks if the condition is true during the transition. (see apps/backend/src/workflowEngine/guards/*.ts)2.1 There might be an important change for STFC. Since I have removed the
proposal_eventstable and along with it thisproposalEvents.proposal_all_fap_reviews_submitted. Since this is not available any more I have changed to check if all fap reviews are submited by inspecting the fap review table columns https://github.com/UserOfficeProject/user-office-core/pull/1297/changes#diff-f3b982a00651344db8c6516a09c950e0e30df0ac84e1cd543826a0d45875588eR209Statusprimary key now uses the semantic string statusId (formerly short_code), dropping the surrogate int. This removes number => string mapping in the code, and keeps IDs readable in logs/DB dumps and tables that reference status. This prevents mismatch bugs where int keys and short codes drifted. Migration 0205_RenameShortCodeToStatusId.sql rewires FK references across proposals/experiment_safety/workflow tables and reconstitutes dependent views.Operationally this makes debugging and API payloads self-describing and aligns status identity with the business identifier.
Status actions are now attached on transition. Before they were attached the status. This means, that if you change the status manually, the status action will not be run.
How Has This Been Tested?
Added and updated e2e tests
Fixes Jira Issue
https://jira.esss.lu.se/browse/SWAP-4949