Skip to content

Commit 32d9bdf

Browse files
authored
fix(orchestrator): only inputs inherited from the assessment workflow should be disabled (#1436)
1 parent f6275e2 commit 32d9bdf

File tree

2 files changed

+124
-11
lines changed

2 files changed

+124
-11
lines changed

plugins/orchestrator-backend/src/service/DataInputSchemaService.test.ts

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('workflow input schema response', () => {
4646
expect(response.schemaSteps[0].title).toEqual('Data Input Schema');
4747
});
4848

49-
it('composed schema also wihtout refs should return multiple steps', () => {
49+
it('composed schema also without refs should return multiple steps', () => {
5050
const response = service.getWorkflowInputSchemaResponse(
5151
mockComposedGreetingWorkflowData.workflowDefinition,
5252
mockComposedGreetingWorkflowData.schema,
@@ -117,4 +117,86 @@ describe('workflow input schema response', () => {
117117
});
118118
expect(response.schemaSteps[0].readonlyKeys).toEqual(['language', 'name']);
119119
});
120+
121+
it('using assessment variables on composed schema should return read only keys', () => {
122+
const newComponentValues = {
123+
orgName: 'org.example',
124+
repoName: 'example',
125+
description: 'example description',
126+
};
127+
const response = service.getWorkflowInputSchemaResponse(
128+
mockSpringBootWorkflowData.workflowDefinition,
129+
mockSpringBootWorkflowData.schema,
130+
undefined,
131+
{
132+
workflowdata: {
133+
newComponent: newComponentValues,
134+
},
135+
},
136+
);
137+
expect(response.isComposedSchema).toEqual(true);
138+
expect(response.schemaSteps[0].data).toEqual(newComponentValues);
139+
expect(response.schemaSteps[0].readonlyKeys).toEqual(
140+
Object.keys(newComponentValues),
141+
);
142+
});
143+
144+
it('using initial workflow and assessment variables should return read only keys', () => {
145+
const response = service.getWorkflowInputSchemaResponse(
146+
mockGreetingWorkflowData.workflowDefinition,
147+
mockGreetingWorkflowData.schema,
148+
{
149+
workflowdata: {
150+
name: 'John Doe',
151+
language: 'Spanish',
152+
},
153+
},
154+
{
155+
workflowdata: {
156+
name: 'John Doe',
157+
waitOrError: 'Error',
158+
},
159+
},
160+
);
161+
expect(response.isComposedSchema).toEqual(false);
162+
expect(response.schemaSteps[0].data).toEqual({
163+
language: 'Spanish',
164+
name: 'John Doe',
165+
});
166+
expect(response.schemaSteps[0].readonlyKeys).toEqual(['name']);
167+
});
168+
169+
it('using initial workflow and assessment variables on composed schema should return read only keys', () => {
170+
const newComponentValues = {
171+
orgName: 'org.example',
172+
repoName: 'example',
173+
description: 'example description',
174+
};
175+
const javaMetadataValues = {
176+
groupId: 'org.example',
177+
artifactId: 'example',
178+
version: '1.0.0',
179+
};
180+
const response = service.getWorkflowInputSchemaResponse(
181+
mockSpringBootWorkflowData.workflowDefinition,
182+
mockSpringBootWorkflowData.schema,
183+
{
184+
workflowdata: {
185+
newComponent: newComponentValues,
186+
javaMetadata: javaMetadataValues,
187+
},
188+
},
189+
{
190+
workflowdata: {
191+
newComponent: newComponentValues,
192+
},
193+
},
194+
);
195+
expect(response.isComposedSchema).toEqual(true);
196+
expect(response.schemaSteps[0].data).toEqual(newComponentValues);
197+
expect(response.schemaSteps[1].data).toEqual(javaMetadataValues);
198+
expect(response.schemaSteps[0].readonlyKeys).toEqual(
199+
Object.keys(newComponentValues),
200+
);
201+
});
120202
});

plugins/orchestrator-backend/src/service/DataInputSchemaService.ts

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,25 @@ export class DataInputSchemaService {
7070

7171
private getInputSchemaSteps(
7272
schema: ComposedSchema,
73-
isAssessment: boolean,
7473
workflowData?: JsonObject,
74+
assessmentWorkflowData?: JsonObject,
7575
): WorkflowInputSchemaStep[] {
7676
return Object.entries(schema.properties).map(([key, curSchema]) => {
77-
const data = (workflowData?.[key] as JsonObject) ?? {};
77+
const data = this.extractInnerProperty(workflowData, key);
78+
const assessmentData = this.extractInnerProperty(
79+
assessmentWorkflowData,
80+
key,
81+
);
82+
const assessmentInitialState = this.extractInitialStateFromWorkflowData(
83+
assessmentData,
84+
curSchema.properties,
85+
);
7886
return {
7987
title: curSchema.title || key,
8088
key,
8189
schema: curSchema,
8290
data,
83-
readonlyKeys: isAssessment ? Object.keys(data) : [],
91+
readonlyKeys: this.extractObjectKeys(assessmentInitialState),
8492
};
8593
});
8694
}
@@ -91,11 +99,11 @@ export class DataInputSchemaService {
9199
instanceVariables?: ProcessInstanceVariables,
92100
assessmentInstanceVariables?: ProcessInstanceVariables,
93101
): WorkflowInputSchemaResponse {
94-
const variables = instanceVariables ?? assessmentInstanceVariables;
95-
const isAssessment = !!assessmentInstanceVariables;
96-
const workflowData = variables
97-
? (variables[WORKFLOW_DATA_KEY] as JsonObject)
98-
: undefined;
102+
const instanceWorkflowData = this.extractWorkflowData(instanceVariables);
103+
const assessmentInstanceWorkflowData = this.extractWorkflowData(
104+
assessmentInstanceVariables,
105+
);
106+
const workflowData = instanceWorkflowData ?? assessmentInstanceWorkflowData;
99107

100108
const res: WorkflowInputSchemaResponse = {
101109
definition,
@@ -115,8 +123,8 @@ export class DataInputSchemaService {
115123
if (isComposedSchema(resolvedSchema)) {
116124
res.schemaSteps = this.getInputSchemaSteps(
117125
resolvedSchema,
118-
isAssessment,
119126
workflowData,
127+
assessmentInstanceWorkflowData,
120128
);
121129
res.isComposedSchema = true;
122130
} else {
@@ -126,13 +134,19 @@ export class DataInputSchemaService {
126134
resolvedSchema.properties,
127135
)
128136
: {};
137+
const assessmentData =
138+
assessmentInstanceWorkflowData &&
139+
this.extractInitialStateFromWorkflowData(
140+
assessmentInstanceWorkflowData,
141+
resolvedSchema.properties,
142+
);
129143
res.schemaSteps = [
130144
{
131145
schema: resolvedSchema,
132146
title: resolvedSchema.title ?? SINGLE_SCHEMA_TITLE,
133147
key: SINGLE_SCHEMA_KEY,
134148
data,
135-
readonlyKeys: isAssessment ? Object.keys(data) : [],
149+
readonlyKeys: this.extractObjectKeys(assessmentData),
136150
},
137151
];
138152
}
@@ -144,4 +158,21 @@ export class DataInputSchemaService {
144158
}
145159
return res;
146160
}
161+
162+
private extractWorkflowData(
163+
variables?: ProcessInstanceVariables,
164+
): JsonObject | undefined {
165+
return variables ? (variables[WORKFLOW_DATA_KEY] as JsonObject) : undefined;
166+
}
167+
168+
private extractObjectKeys(obj: JsonObject | undefined): string[] {
169+
return obj ? Object.keys(obj) : [];
170+
}
171+
172+
private extractInnerProperty(
173+
obj: JsonObject | undefined,
174+
key: string,
175+
): JsonObject {
176+
return (obj?.[key] as JsonObject) ?? {};
177+
}
147178
}

0 commit comments

Comments
 (0)