Skip to content

Commit

Permalink
Pages Editor: check if workflow is part of project (#7156)
Browse files Browse the repository at this point in the history
* DataManager: WIP add checks to ensure WF is part of project

* Implement checkIsWorkflowPartOfProject()

* checkIsWorkflowPartOfProject: correct checking logic. We're looking at WF ID, not Subject Sets.
  • Loading branch information
shaunanoordin authored Nov 4, 2024
1 parent bf8ffe0 commit d296600
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/pages/lab-pages-editor/DataManager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import PropTypes from 'prop-types';
import apiClient from 'panoptes-client/lib/api-client';
import { WorkflowContext } from './context.js';
import checkIsPFEWorkflow from './helpers/checkIsPFEWorkflow.js';
import checkIsWorkflowPartOfProject from './helpers/checkIsWorkflowPartOfProject.js';

function DataManager({
// key: to ensure DataManager renders FRESH (with states reset) whenever workflowId changes, use <DataManager key={workflowId} ... />
Expand Down Expand Up @@ -118,8 +119,24 @@ function DataManager({
};
}, [apiData.project, apiData.workflow, apiData.status, updateCounter]);

// Safety check: did this component receive its minimum input?
if (!workflowId) return (<div>ERROR: no Workflow ID specified</div>);
// if (!workflow) return null

// Safety check: does this workflow belong to this project?
if (apiData.workflow && apiData.project) {
const isWorkflowPartOfProject = checkIsWorkflowPartOfProject(apiData.workflow, apiData.project);
if (!isWorkflowPartOfProject) {
return (
<div className="status-banner error">
ERROR: workflow {apiData.workflow.id} doesn't belong to project {apiData.project.id}
</div>
);
}
}

// NOTE: no need to check for !workflow.
// This is automatically handled by "Error: could not fetch data"
// // if (!workflow) return null

return (
<WorkflowContext.Provider
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Checks if a workflow belongs to a project.
*/

export default function checkIsWorkflowPartOfProject(workflow, project) {
if (!workflow || !project) return false;
return !!project.links?.workflows?.includes(workflow.id);
}

0 comments on commit d296600

Please sign in to comment.