Merge branch '19143-project-list-workflows'
[arvados-workbench2.git] / src / store / workflow-panel / workflow-panel-actions.ts
index b48252093b42ddfe823ad77a620de2942bbe6365..7c90fa6bb290fbfd6f58aa16f96b2876effc0b88 100644 (file)
@@ -3,18 +3,22 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { Dispatch } from 'redux';
-import { RootState } from '~/store/store';
-import { ServiceRepository } from '~/services/services';
-import { bindDataExplorerActions } from '~/store/data-explorer/data-explorer-action';
-import { propertiesActions } from '~/store/properties/properties-actions';
-import { getProperty } from '~/store/properties/properties';
-import { navigateToRunProcess } from '~/store/navigation/navigation-action';
-import { goToStep, runProcessPanelActions, loadPresets, getWorkflowRunnerSettings } from '~/store/run-process-panel/run-process-panel-actions';
-import { snackbarActions } from '~/store/snackbar/snackbar-actions';
+import { RootState } from 'store/store';
+import { ServiceRepository } from 'services/services';
+import { bindDataExplorerActions } from 'store/data-explorer/data-explorer-action';
+import { propertiesActions } from 'store/properties/properties-actions';
+import { getProperty } from 'store/properties/properties';
+import { navigateToRunProcess } from 'store/navigation/navigation-action';
+import { goToStep, runProcessPanelActions, loadPresets, getWorkflowRunnerSettings } from 'store/run-process-panel/run-process-panel-actions';
+import { snackbarActions } from 'store/snackbar/snackbar-actions';
 import { initialize } from 'redux-form';
-import { RUN_PROCESS_BASIC_FORM } from '~/views/run-process-panel/run-process-basic-form';
-import { RUN_PROCESS_INPUTS_FORM } from '~/views/run-process-panel/run-process-inputs-form';
-import { RUN_PROCESS_ADVANCED_FORM } from '~/views/run-process-panel/run-process-advanced-form';
+import { RUN_PROCESS_BASIC_FORM } from 'views/run-process-panel/run-process-basic-form';
+import { RUN_PROCESS_INPUTS_FORM } from 'views/run-process-panel/run-process-inputs-form';
+import { RUN_PROCESS_ADVANCED_FORM } from 'views/run-process-panel/run-process-advanced-form';
+import { getResource, ResourcesState } from 'store/resources/resources';
+import { ProjectResource } from 'models/project';
+import { UserResource } from 'models/user';
+import { getUserUuid } from "common/getuser";
 
 export const WORKFLOW_PANEL_ID = "workflowPanel";
 const UUID_PREFIX_PROPERTY_NAME = 'uuidPrefix';
@@ -50,12 +54,21 @@ export const openRunProcess = (workflowUuid: string, ownerUuid?: string, name?:
             dispatch<any>(loadPresets(workflow.uuid));
 
             dispatch(initialize(RUN_PROCESS_ADVANCED_FORM, getWorkflowRunnerSettings(workflow)));
+            let owner;
             if (ownerUuid) {
-                dispatch(runProcessPanelActions.SET_PROCESS_OWNER_UUID(ownerUuid));
+                // Must be writable.
+                const userUuid = getUserUuid(getState());
+                owner = getResource<ProjectResource | UserResource>(ownerUuid)(getState().resources);
+                if (!owner || !userUuid || owner.writableBy.indexOf(userUuid) === -1) {
+                    owner = undefined;
+                }
             }
-            if (name) {
-                dispatch(initialize(RUN_PROCESS_BASIC_FORM, { name }));
+            if (owner) {
+                dispatch(runProcessPanelActions.SET_PROCESS_OWNER_UUID(owner.uuid));
             }
+
+            dispatch(initialize(RUN_PROCESS_BASIC_FORM, { name, owner }));
+
             if (inputObj) {
                 dispatch(initialize(RUN_PROCESS_INPUTS_FORM, inputObj));
             }