From 620ed3e162cc008ddfdd47bdfe12fa4e9010c484 Mon Sep 17 00:00:00 2001 From: Seyi Adebajo Date: Sun, 2 Apr 2017 14:35:51 -0700 Subject: [PATCH] ensure that fields that are classified have a value in the field format before propagating changes --- .../app/components/dataset-confidential.js | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/wherehows-web/app/components/dataset-confidential.js b/wherehows-web/app/components/dataset-confidential.js index c5eaa1dbaa..9b7f5cd20e 100644 --- a/wherehows-web/app/components/dataset-confidential.js +++ b/wherehows-web/app/components/dataset-confidential.js @@ -207,6 +207,14 @@ export default Component.extend({ return sourceClassification.setObjects([...updatedClassification]); }, + /** + * Checks that each field in a given source classification has a value + * for the logicalType + * @param {Array} sourceClassification + */ + ensureFieldsContainLogicalType: (sourceClassification = []) => + sourceClassification.every(({ logicalType }) => logicalType), + actions: { /** * Updates the logical type for a field with the provided identifierField @@ -270,7 +278,19 @@ export default Component.extend({ * @return {Boolean} */ saveSecuritySpecification() { - this.whenRequestCompletes(get(this, 'onSave')()); + /** + * For Each classifier ensure that the fields on the securitySpec + * contain a valid `logicalType` attribute + * @type {Boolean} + */ + const classedFieldsHaveLogicalType = classifiers.every(classifier => + this.ensureFieldsContainLogicalType( + getWithDefault(this, `${sourceClassificationKey}.${classifier}`, []) + )); + + if (classedFieldsHaveLogicalType) { + this.whenRequestCompletes(get(this, 'onSave')()); + } return false; },