Skip to content

Commit

Permalink
move parameter sanitization of referenced assets/value into the paylo…
Browse files Browse the repository at this point in the history
…ad construction rather than in the effect
  • Loading branch information
rfellows committed Aug 14, 2024
1 parent 19c9061 commit f3ec180
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,15 @@ import {
EditParameterRequest,
EditParameterResponse,
Parameter,
ParameterContextUpdateRequest,
ParameterEntity,
SubmitParameterContextUpdate
ParameterContextUpdateRequest
} from '../../../../state/shared';
import { EditParameterDialog } from '../../../../ui/common/edit-parameter-dialog/edit-parameter-dialog.component';
import { OkDialog } from '../../../../ui/common/ok-dialog/ok-dialog.component';
import { ErrorHelper } from '../../../../service/error-helper.service';
import { HttpErrorResponse } from '@angular/common/http';
import { isDefinedAndNotNull, MEDIUM_DIALOG, SMALL_DIALOG, XL_DIALOG } from 'libs/shared/src';
import { BackNavigation } from '../../../../state/navigation';
import { Storage, NiFiCommon } from '@nifi/shared';
import { NiFiCommon, Storage } from '@nifi/shared';

@Injectable()
export class ParameterContextListingEffects {
Expand Down Expand Up @@ -403,18 +401,6 @@ export class ParameterContextListingEffects {
this.actions$.pipe(
ofType(ParameterContextListingActions.submitParameterContextUpdateRequest),
map((action) => action.request),
map((request) => {
// The backend api doesn't support providing both a parameter value and referenced assets
// even though it returns both from the GET api. We must strip the value out if there are
// referenced assets.
const modifiedRequest: SubmitParameterContextUpdate = structuredClone(request);
modifiedRequest.payload.component.parameters.forEach((parameter: ParameterEntity) => {
if ((parameter.parameter.referencedAssets || []).length > 0) {
parameter.parameter.value = null;
}
});
return modifiedRequest;
}),
switchMap((request) =>
from(this.parameterContextService.submitParameterContextUpdate(request)).pipe(
map((response) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ export class EditParameterContext extends TabbedDialog {
this.parameters = [];
}

// The backend api doesn't support providing both a parameter value and referenced assets
// even though it returns both from the GET api. We must strip the value out if there are
// referenced assets.
const sanitizedParameters: ParameterEntity[] = this.parameters.slice();
sanitizedParameters.forEach((parameter: ParameterEntity) => {
if ((parameter.parameter.referencedAssets || []).length > 0) {
parameter.parameter.value = null;
}
});

const payload: any = {
revision: this.client.getRevision(pc),
disconnectedNodeAcknowledged: this.clusterConnectionService.isDisconnectionAcknowledged(),
Expand All @@ -175,7 +185,7 @@ export class EditParameterContext extends TabbedDialog {
id: pc.id,
name: this.editParameterContextForm.get('name')?.value,
description: this.editParameterContextForm.get('description')?.value,
parameters: this.parameters,
parameters: sanitizedParameters,
inheritedParameterContexts: this.editParameterContextForm.get('inheritedParameterContexts')?.value
}
};
Expand Down

0 comments on commit f3ec180

Please sign in to comment.