2017-02-13 14:51:31 -08:00
|
|
|
import Ember from 'ember';
|
2017-04-25 10:50:02 -07:00
|
|
|
import isTrackingHeaderField from 'wherehows-web/utils/validators/tracking-headers';
|
2017-05-19 08:45:05 -07:00
|
|
|
import {
|
|
|
|
classifiers,
|
|
|
|
datasetClassifiers,
|
|
|
|
fieldIdentifierTypes,
|
|
|
|
idLogicalTypes,
|
2017-05-23 12:18:55 -07:00
|
|
|
nonIdFieldLogicalTypes,
|
2017-07-18 15:01:28 -07:00
|
|
|
defaultFieldDataTypeClassification,
|
|
|
|
compliancePolicyStrings
|
2017-05-19 08:45:05 -07:00
|
|
|
} from 'wherehows-web/constants';
|
2017-06-01 13:11:26 -07:00
|
|
|
import { isPolicyExpectedShape } from 'wherehows-web/utils/datasets/functions';
|
2017-08-07 22:21:05 -07:00
|
|
|
import scrollMonitor from 'scrollmonitor';
|
2017-06-01 13:11:26 -07:00
|
|
|
|
|
|
|
const {
|
2017-06-05 09:49:37 -07:00
|
|
|
assert,
|
2017-06-01 13:11:26 -07:00
|
|
|
Component,
|
|
|
|
computed,
|
|
|
|
set,
|
|
|
|
get,
|
|
|
|
setProperties,
|
|
|
|
getProperties,
|
|
|
|
getWithDefault,
|
2017-08-28 01:38:47 -07:00
|
|
|
String: { htmlSafe },
|
|
|
|
inject: { service }
|
2017-06-01 13:11:26 -07:00
|
|
|
} = Ember;
|
2017-03-24 20:27:43 -07:00
|
|
|
|
2017-08-30 10:26:44 -07:00
|
|
|
const {
|
|
|
|
complianceDataException,
|
|
|
|
missingTypes,
|
|
|
|
successUpdating,
|
|
|
|
failedUpdating,
|
|
|
|
helpText,
|
|
|
|
successUploading,
|
|
|
|
invalidPolicyData
|
|
|
|
} = compliancePolicyStrings;
|
2017-07-18 15:01:28 -07:00
|
|
|
|
2017-04-18 15:02:45 -07:00
|
|
|
const hiddenTrackingFieldsMsg = htmlSafe(
|
2017-05-19 08:45:05 -07:00
|
|
|
'<p>Some fields in this dataset have been hidden from the table(s) below. ' +
|
2017-05-01 09:57:17 -07:00
|
|
|
"These are tracking fields for which we've been able to predetermine the compliance classification.</p>" +
|
|
|
|
'<p>For example: <code>header.memberId</code>, <code>requestHeader</code>. ' +
|
|
|
|
'Hopefully, this saves you some scrolling!</p>'
|
2017-04-18 15:02:45 -07:00
|
|
|
);
|
2017-04-02 15:40:43 -07:00
|
|
|
|
2017-05-19 08:45:05 -07:00
|
|
|
/**
|
|
|
|
* Takes a string, returns a formatted string. Niche , single use case
|
|
|
|
* for now, so no need to make into a helper
|
|
|
|
* @param {String} string
|
|
|
|
*/
|
|
|
|
const formatAsCapitalizedStringWithSpaces = string => string.replace(/[A-Z]/g, match => ` ${match}`).capitalize();
|
|
|
|
|
2017-05-23 12:18:55 -07:00
|
|
|
/**
|
|
|
|
* List of non Id field data type classifications
|
|
|
|
* @type {Array}
|
|
|
|
*/
|
|
|
|
const genericLogicalTypes = Object.keys(nonIdFieldLogicalTypes).sort();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Merged object of logicalTypes
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
const logicalTypes = Object.assign({}, nonIdFieldLogicalTypes);
|
2017-05-19 08:45:05 -07:00
|
|
|
/**
|
|
|
|
* String constant referencing the datasetClassification on the privacy policy
|
|
|
|
* @type {String}
|
|
|
|
*/
|
|
|
|
const datasetClassificationKey = 'complianceInfo.datasetClassification';
|
|
|
|
/**
|
|
|
|
* A list of available keys for the datasetClassification map on the security specification
|
|
|
|
* @type {Array}
|
|
|
|
*/
|
|
|
|
const datasetClassifiersKeys = Object.keys(datasetClassifiers);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A reference to the compliance policy entities on the complianceInfo map
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
const policyComplianceEntitiesKey = 'complianceInfo.complianceEntities';
|
2017-03-30 15:08:12 -07:00
|
|
|
/**
|
|
|
|
* Duplicate check using every to short-circuit iteration
|
2017-07-18 15:01:28 -07:00
|
|
|
* @param {Array} list = [] the list to check for dupes
|
2017-03-30 15:08:12 -07:00
|
|
|
* @return {Boolean} true is unique, false otherwise
|
|
|
|
*/
|
2017-07-18 15:01:28 -07:00
|
|
|
const listIsUnique = (list = []) => new Set(list).size === list.length;
|
2017-03-24 20:27:43 -07:00
|
|
|
|
2017-06-05 09:49:37 -07:00
|
|
|
assert('`fieldIdentifierTypes` contains an object with a key `none`', typeof fieldIdentifierTypes.none === 'object');
|
|
|
|
const fieldIdentifierTypeKeysBarNone = Object.keys(fieldIdentifierTypes).filter(k => k !== 'none');
|
|
|
|
const fieldDisplayKeys = ['none', '_', ...fieldIdentifierTypeKeysBarNone];
|
|
|
|
|
2017-03-24 20:27:43 -07:00
|
|
|
/**
|
2017-05-19 08:45:05 -07:00
|
|
|
* A list of field identifier types mapped to label, value options for select display
|
|
|
|
* @type {any[]|Array.<{value: String, label: String}>}
|
2017-03-24 20:27:43 -07:00
|
|
|
*/
|
2017-06-05 09:49:37 -07:00
|
|
|
const fieldIdentifierOptions = fieldDisplayKeys.map(fieldIdentifierType => {
|
|
|
|
const divider = '──────────';
|
|
|
|
const { value = fieldIdentifierType, displayAs: label = divider } = fieldIdentifierTypes[fieldIdentifierType] || {};
|
|
|
|
|
|
|
|
// Adds a divider for a value of _
|
|
|
|
// Visually this separates ID from none fieldIdentifierTypes
|
|
|
|
return {
|
|
|
|
value,
|
|
|
|
label,
|
|
|
|
isDisabled: fieldIdentifierType === '_'
|
|
|
|
};
|
|
|
|
});
|
2017-03-24 20:27:43 -07:00
|
|
|
|
2017-05-19 08:45:05 -07:00
|
|
|
/**
|
|
|
|
* A list of field identifier types that are Ids i.e member ID, org ID, group ID
|
|
|
|
* @type {any[]|Array.<String>}
|
|
|
|
*/
|
2017-08-07 22:21:05 -07:00
|
|
|
export const fieldIdentifierTypeIds = Object.keys(fieldIdentifierTypes)
|
2017-05-19 08:45:05 -07:00
|
|
|
.map(fieldIdentifierType => fieldIdentifierTypes[fieldIdentifierType])
|
|
|
|
.filter(({ isId }) => isId)
|
|
|
|
.mapBy('value');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Caches a list of logicalType mappings for displaying its value and a label by logicalType
|
|
|
|
* @param {String} logicalType
|
|
|
|
*/
|
|
|
|
const cachedLogicalTypes = logicalType =>
|
|
|
|
computed(function() {
|
|
|
|
return {
|
|
|
|
id: idLogicalTypes,
|
|
|
|
generic: genericLogicalTypes
|
|
|
|
}[logicalType].map(value => ({
|
|
|
|
value,
|
2017-05-23 12:18:55 -07:00
|
|
|
label: logicalTypes[value]
|
|
|
|
? logicalTypes[value].displayAs
|
|
|
|
: value.replace(/_/g, ' ').replace(/([A-Z]{3,})/g, f => f.toLowerCase().capitalize())
|
2017-05-19 08:45:05 -07:00
|
|
|
}));
|
2017-03-24 20:27:43 -07:00
|
|
|
});
|
|
|
|
|
2017-08-07 22:21:05 -07:00
|
|
|
// Map logicalTypes to options consumable by DOM
|
|
|
|
export const logicalTypesForIds = cachedLogicalTypes('id');
|
|
|
|
|
|
|
|
// Map generic logical type to options consumable in DOM
|
|
|
|
export const logicalTypesForGeneric = cachedLogicalTypes('generic');
|
|
|
|
|
2017-03-24 20:27:43 -07:00
|
|
|
export default Component.extend({
|
2017-03-27 20:12:09 -07:00
|
|
|
sortColumnWithName: 'identifierField',
|
2017-03-27 18:26:09 -07:00
|
|
|
filterBy: 'identifierField',
|
2017-03-24 20:27:43 -07:00
|
|
|
sortDirection: 'asc',
|
2017-02-13 14:51:31 -08:00
|
|
|
searchTerm: '',
|
2017-05-19 08:45:05 -07:00
|
|
|
helpText,
|
|
|
|
fieldIdentifierOptions,
|
2017-04-18 15:02:45 -07:00
|
|
|
hiddenTrackingFields: hiddenTrackingFieldsMsg,
|
2017-06-05 09:49:37 -07:00
|
|
|
classNames: ['compliance-container'],
|
|
|
|
classNameBindings: ['isEditing:compliance-container--edit-mode'],
|
2017-07-18 15:01:28 -07:00
|
|
|
/**
|
|
|
|
* Flag indicating that the component is in edit mode
|
|
|
|
* @type {String}
|
|
|
|
*/
|
2017-08-29 16:50:44 -07:00
|
|
|
isEditing: computed('isNewComplianceInfo', 'isEditingDatasetClassification', 'isEditingCompliancePolicy', function() {
|
|
|
|
const { isNewComplianceInfo, isEditingDatasetClassification, isEditingCompliancePolicy } = getProperties(
|
|
|
|
this,
|
|
|
|
'isNewComplianceInfo',
|
|
|
|
'isEditingDatasetClassification',
|
|
|
|
'isEditingCompliancePolicy'
|
|
|
|
);
|
|
|
|
return isNewComplianceInfo || isEditingDatasetClassification || isEditingCompliancePolicy;
|
|
|
|
}),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience flag indicating the policy is not currently being edited
|
|
|
|
* @type {Ember.computed}
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
isReadOnly: computed.not('isEditing'),
|
2017-07-18 15:01:28 -07:00
|
|
|
/**
|
|
|
|
* Flag indicating that the component is currently saving / attempting to save the privacy policy
|
|
|
|
* @type {String}
|
|
|
|
*/
|
|
|
|
isSaving: false,
|
2017-03-24 20:27:43 -07:00
|
|
|
|
2017-08-29 16:50:44 -07:00
|
|
|
/**
|
|
|
|
* Determines if the the compliance policy update form should be shown
|
|
|
|
* @type {Ember.computed}
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
isShowingComplianceEditMode: computed('isNewComplianceInfo', 'isEditingCompliancePolicy', function() {
|
|
|
|
const { isNewComplianceInfo, isEditingCompliancePolicy, isEditingDatasetClassification } = getProperties(
|
|
|
|
this,
|
|
|
|
'isNewComplianceInfo',
|
|
|
|
'isEditingCompliancePolicy',
|
|
|
|
'isEditingDatasetClassification'
|
|
|
|
);
|
|
|
|
|
|
|
|
return (isNewComplianceInfo || isEditingCompliancePolicy) && !isEditingDatasetClassification;
|
|
|
|
}),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Proxy to the check if the dataset classification form is being edited and should be shown
|
|
|
|
* @type {Ember.computed}
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
isShowingDatasetClassificationEditMode: computed.bool('isEditingDatasetClassification'),
|
|
|
|
|
|
|
|
datasetComplianceSteps: computed('isEditingCompliancePolicy', 'isEditingDatasetClassification', function() {
|
|
|
|
const { isEditingCompliancePolicy, isEditingDatasetClassification } = getProperties(
|
|
|
|
this,
|
|
|
|
'isEditingCompliancePolicy',
|
|
|
|
'isEditingDatasetClassification'
|
|
|
|
);
|
|
|
|
|
|
|
|
return [isEditingCompliancePolicy, isEditingDatasetClassification].map((_step, index) => ({
|
|
|
|
done: !index ? !!isEditingDatasetClassification : false
|
|
|
|
}));
|
|
|
|
}),
|
|
|
|
|
2017-08-28 01:38:47 -07:00
|
|
|
/**
|
|
|
|
* Reference to the application notifications Service
|
|
|
|
* @type {Ember.Service}
|
|
|
|
*/
|
|
|
|
notifications: service(),
|
|
|
|
|
2017-03-30 15:08:12 -07:00
|
|
|
didReceiveAttrs() {
|
2017-08-29 16:50:44 -07:00
|
|
|
this._super(...Array.from(arguments));
|
2017-03-30 15:08:12 -07:00
|
|
|
// Perform validation step on the received component attributes
|
|
|
|
this.validateAttrs();
|
|
|
|
},
|
|
|
|
|
2017-08-07 22:21:05 -07:00
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
didRender() {
|
|
|
|
this._super(...arguments);
|
|
|
|
// Hides DOM elements that are not currently visible in the UI and unhides them once the user scrolls the
|
|
|
|
// elements into view
|
|
|
|
this.enableDomCloaking();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A `lite` / intermediary step to occlusion culling, this helps to improve the rendering of
|
|
|
|
* elements that are currently rendered in the viewport by hiding that aren't.
|
|
|
|
* Setting them to visibility hidden doesn't remove them from the document flow, but the browser
|
|
|
|
* doesn't have to deal with layout for the affected elements since they are off-screen
|
|
|
|
*/
|
|
|
|
enableDomCloaking() {
|
|
|
|
const [dom] = this.$('.dataset-compliance-fields');
|
|
|
|
const triggerCount = 100;
|
|
|
|
if (dom) {
|
|
|
|
const rows = dom.querySelectorAll('tbody tr');
|
|
|
|
|
|
|
|
// if we already have watchers for elements, or if the elements previously cached are no longer valid,
|
|
|
|
// e.g. those elements were destroyed when new data was received, pagination etc
|
|
|
|
if (rows.length > triggerCount && (!this.complianceWatchers || !this.complianceWatchers.has(rows[0]))) {
|
|
|
|
/**
|
|
|
|
* If an item is not in the viewport add a class to occlude it
|
|
|
|
*/
|
|
|
|
const cloaker = function() {
|
|
|
|
if (!this.isInViewport) {
|
|
|
|
return this.watchItem.classList.add('compliance-row--off-screen');
|
|
|
|
}
|
|
|
|
this.watchItem.classList.remove('compliance-row--off-screen');
|
|
|
|
};
|
|
|
|
this.watchers = [];
|
|
|
|
|
|
|
|
// Retain a weak reference to DOM nodes
|
|
|
|
this.complianceWatchers = new WeakMap(
|
|
|
|
[...rows].map(row => {
|
|
|
|
const watcher = scrollMonitor.create(row);
|
|
|
|
watcher['stateChange'](cloaker);
|
|
|
|
cloaker.call(watcher);
|
|
|
|
this.watchers = [...this.watchers, watcher];
|
|
|
|
|
|
|
|
return [watcher.watchItem, watcher];
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cleans up the artifacts from the dom cloaking operation, drops references held by scroll monitor
|
|
|
|
*/
|
|
|
|
disableDomCloaking() {
|
|
|
|
if (!this.watchers || !Array.isArray(this.watchers)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.watchers.forEach(watcher => watcher.destroy());
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @override
|
|
|
|
*/
|
|
|
|
willDestroyElement() {
|
|
|
|
this.disableDomCloaking();
|
|
|
|
},
|
|
|
|
|
2017-03-30 15:08:12 -07:00
|
|
|
/**
|
|
|
|
* Ensure that props received from on this component
|
|
|
|
* are valid, otherwise flag
|
|
|
|
*/
|
|
|
|
validateAttrs() {
|
2017-05-01 09:57:17 -07:00
|
|
|
const fieldNames = getWithDefault(this, 'schemaFieldNamesMappedToDataTypes', []).mapBy('fieldName');
|
2017-03-30 15:08:12 -07:00
|
|
|
|
2017-07-18 15:01:28 -07:00
|
|
|
// identifier field names from the column api should be unique
|
|
|
|
if (listIsUnique(fieldNames.sort())) {
|
2017-03-31 17:30:21 -07:00
|
|
|
return set(this, '_hasBadData', false);
|
2017-03-30 15:08:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Flag this component's data as problematic
|
|
|
|
set(this, '_hasBadData', true);
|
|
|
|
},
|
|
|
|
|
2017-05-19 08:45:05 -07:00
|
|
|
// Map logicalTypes to options consumable by DOM
|
2017-08-07 22:21:05 -07:00
|
|
|
idLogicalTypes: logicalTypesForIds,
|
2017-05-19 08:45:05 -07:00
|
|
|
|
|
|
|
// Map generic logical type to options consumable in DOM
|
2017-08-07 22:21:05 -07:00
|
|
|
genericLogicalTypes: logicalTypesForGeneric,
|
2017-05-19 08:45:05 -07:00
|
|
|
|
|
|
|
// Map classifiers to options better consumed in DOM
|
|
|
|
classifiers: ['', ...classifiers.sort()].map(value => ({
|
2017-03-27 18:26:09 -07:00
|
|
|
value,
|
2017-05-19 08:45:05 -07:00
|
|
|
label: value ? formatAsCapitalizedStringWithSpaces(value) : '...'
|
2017-03-24 20:27:43 -07:00
|
|
|
})),
|
|
|
|
|
2017-06-01 13:11:26 -07:00
|
|
|
/**
|
|
|
|
* Caches the policy's modification time in milliseconds
|
|
|
|
*/
|
|
|
|
policyModificationTimeInEpoch: computed('complianceInfo', function() {
|
2017-08-21 15:22:28 -07:00
|
|
|
return getWithDefault(this, 'complianceInfo.modifiedTime', 0);
|
2017-06-01 13:11:26 -07:00
|
|
|
}),
|
|
|
|
|
2017-08-20 20:05:18 -07:00
|
|
|
/**
|
|
|
|
* Checks that suggested values postdate the last save date or that suggestions exist
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
hasRecentSuggestions: computed('policyModificationTimeInEpoch', 'complianceSuggestion', function() {
|
|
|
|
const { policyModificationTimeInEpoch, complianceSuggestion = {} } = getProperties(this, [
|
|
|
|
'policyModificationTimeInEpoch',
|
|
|
|
'complianceSuggestion'
|
|
|
|
]);
|
|
|
|
const { lastModified: suggestionsLastModified, complianceSuggestions = [] } = complianceSuggestion;
|
|
|
|
|
|
|
|
// If modification dates exist, check that the suggestions are newer than the last time the policy was saved
|
|
|
|
// and we have at least 1 suggestion, otherwise check that the count of suggestions is at least 1
|
|
|
|
if (policyModificationTimeInEpoch && suggestionsLastModified) {
|
|
|
|
return complianceSuggestions.length && suggestionsLastModified > policyModificationTimeInEpoch;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !!complianceSuggestions.length;
|
|
|
|
}),
|
|
|
|
|
2017-04-18 15:02:45 -07:00
|
|
|
/**
|
|
|
|
* @type {Boolean} cached boolean flag indicating that fields do contain a `kafka type`
|
|
|
|
* tracking header.
|
|
|
|
* Used to indicate to viewer that these fields are hidden.
|
|
|
|
*/
|
2017-08-07 22:21:05 -07:00
|
|
|
containsHiddenTrackingFields: computed('truncatedColumnFields.length', function() {
|
|
|
|
// If their is a diff in schemaFieldNamesMappedToDataTypes and truncatedColumnFields,
|
2017-05-01 09:57:17 -07:00
|
|
|
// then we have hidden tracking fields
|
2017-08-07 22:21:05 -07:00
|
|
|
return get(this, 'truncatedColumnFields.length') !== get(this, 'schemaFieldNamesMappedToDataTypes.length');
|
2017-05-01 09:57:17 -07:00
|
|
|
}),
|
2017-04-18 15:02:45 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {Array.<Object>} Filters the mapped compliance data fields without `kafka type`
|
|
|
|
* tracking headers
|
|
|
|
*/
|
2017-08-07 22:21:05 -07:00
|
|
|
truncatedColumnFields: computed('schemaFieldNamesMappedToDataTypes', function() {
|
2017-07-18 17:09:43 -07:00
|
|
|
return getWithDefault(this, 'schemaFieldNamesMappedToDataTypes', []).filter(
|
|
|
|
({ fieldName }) => !isTrackingHeaderField(fieldName)
|
|
|
|
);
|
2017-04-18 15:02:45 -07:00
|
|
|
}),
|
|
|
|
|
2017-05-19 08:45:05 -07:00
|
|
|
/**
|
|
|
|
* Checks that all tags/ dataset content types have a boolean value
|
|
|
|
* @type {Ember.computed}
|
|
|
|
*/
|
|
|
|
isDatasetFullyClassified: computed('datasetClassification', function() {
|
|
|
|
const datasetClassification = get(this, 'datasetClassification');
|
|
|
|
|
|
|
|
return Object.keys(datasetClassification)
|
|
|
|
.map(key => ({ value: datasetClassification[key].value }))
|
|
|
|
.every(({ value }) => [true, false].includes(value));
|
|
|
|
}),
|
|
|
|
|
2017-08-20 18:53:01 -07:00
|
|
|
/**
|
|
|
|
* Determines if all member data fields should be shown in the member data table i.e. show only fields contained in
|
|
|
|
* this dataset or otherwise
|
|
|
|
*/
|
|
|
|
isShowingAllMemberData: computed.or('showAllDatasetMemberData', 'isEditing'),
|
|
|
|
|
2017-07-18 15:01:28 -07:00
|
|
|
/**
|
|
|
|
* Determines if the save feature is allowed for the current dataset, otherwise e.g. interface should be disabled
|
|
|
|
* @type {Ember.computed}
|
|
|
|
*/
|
|
|
|
isSavingDisabled: computed('isDatasetFullyClassified', 'isSaving', function() {
|
|
|
|
const { isDatasetFullyClassified, isSaving } = getProperties(this, ['isDatasetFullyClassified', 'isSaving']);
|
|
|
|
|
|
|
|
return !isDatasetFullyClassified || isSaving;
|
|
|
|
}),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to ensure the the number of fields added to compliance entities is less than or equal
|
|
|
|
* to what is available on the dataset schema
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
isSchemaFieldLengthGreaterThanComplianceEntities() {
|
|
|
|
const { length: columnFieldsLength } = getWithDefault(this, 'schemaFieldNamesMappedToDataTypes', []);
|
|
|
|
const { length: complianceListLength } = get(this, policyComplianceEntitiesKey);
|
|
|
|
|
|
|
|
return columnFieldsLength >= complianceListLength;
|
|
|
|
},
|
|
|
|
|
2017-05-19 08:45:05 -07:00
|
|
|
/**
|
|
|
|
* Computed property that is dependent on all the keys in the datasetClassification map
|
|
|
|
* Returns a new map of datasetClassificationKey: String-> Object.<Boolean|undefined,String>
|
|
|
|
* @type {Ember.computed}
|
|
|
|
*/
|
|
|
|
datasetClassification: computed(`${datasetClassificationKey}.{${datasetClassifiersKeys.join(',')}}`, function() {
|
|
|
|
const sourceDatasetClassification = get(this, datasetClassificationKey) || {};
|
|
|
|
|
2017-08-20 18:12:56 -07:00
|
|
|
return datasetClassifiersKeys.sort().reduce((classifiers, classifier) => {
|
2017-08-20 16:46:43 -07:00
|
|
|
return [
|
|
|
|
...classifiers,
|
|
|
|
{
|
|
|
|
classifier,
|
2017-05-19 08:45:05 -07:00
|
|
|
value: sourceDatasetClassification[classifier],
|
|
|
|
label: datasetClassifiers[classifier]
|
|
|
|
}
|
2017-08-20 16:46:43 -07:00
|
|
|
];
|
|
|
|
}, []);
|
2017-05-19 08:45:05 -07:00
|
|
|
}),
|
|
|
|
|
2017-03-27 18:26:09 -07:00
|
|
|
/**
|
|
|
|
* Lists all dataset fields found in the `columns` performs an intersection
|
|
|
|
* of fields with the currently persisted and/or updated
|
2017-05-19 08:45:05 -07:00
|
|
|
* privacyCompliancePolicy.complianceEntities.
|
2017-03-27 18:26:09 -07:00
|
|
|
* The returned list is a map of fields with current or default privacy properties
|
|
|
|
*/
|
2017-08-18 03:42:40 -07:00
|
|
|
mergeComplianceEntitiesAndColumnFields(
|
|
|
|
columnIdFieldsToCurrentPrivacyPolicy = {},
|
|
|
|
truncatedColumnFields = [],
|
|
|
|
identifierFieldMappedToSuggestions = {}
|
|
|
|
) {
|
2017-08-07 22:21:05 -07:00
|
|
|
return truncatedColumnFields.map(({ fieldName: identifierField, dataType }) => {
|
2017-08-15 23:16:38 -07:00
|
|
|
const {
|
|
|
|
[identifierField]: { identifierType, logicalType, securityClassification }
|
|
|
|
} = columnIdFieldsToCurrentPrivacyPolicy;
|
|
|
|
|
2017-08-18 03:42:40 -07:00
|
|
|
//Cache the mapped suggestion into a local
|
|
|
|
const suggestion = identifierFieldMappedToSuggestions[identifierField];
|
|
|
|
let field = {
|
2017-08-07 22:21:05 -07:00
|
|
|
identifierField,
|
|
|
|
dataType,
|
|
|
|
identifierType,
|
|
|
|
logicalType,
|
2017-08-15 23:16:38 -07:00
|
|
|
classification: securityClassification
|
2017-03-27 18:26:09 -07:00
|
|
|
};
|
2017-08-18 03:42:40 -07:00
|
|
|
|
|
|
|
// If a suggestion exists for this field add the suggestion attribute to the field properties
|
|
|
|
if (suggestion) {
|
|
|
|
field = { ...field, suggestion };
|
|
|
|
}
|
|
|
|
|
|
|
|
return field;
|
2017-08-07 22:21:05 -07:00
|
|
|
});
|
|
|
|
},
|
2017-03-27 18:26:09 -07:00
|
|
|
|
2017-08-07 22:21:05 -07:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Array} columnFieldNames
|
|
|
|
* @return {*|{}|any}
|
|
|
|
*/
|
|
|
|
mapColumnIdFieldsToCurrentPrivacyPolicy(columnFieldNames) {
|
|
|
|
const complianceEntities = get(this, policyComplianceEntitiesKey) || [];
|
|
|
|
const getKeysOnField = (keys = [], fieldName, source = []) => {
|
|
|
|
const sourceField = source.find(({ identifierField }) => identifierField === fieldName) || {};
|
|
|
|
let ret = {};
|
|
|
|
|
|
|
|
for (const [key, value] of Object.entries(sourceField)) {
|
|
|
|
if (keys.includes(key)) {
|
|
|
|
ret = { ...ret, [key]: value };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
return columnFieldNames.reduce((acc, identifierField) => {
|
|
|
|
const currentPrivacyAttrs = getKeysOnField(
|
2017-08-15 23:16:38 -07:00
|
|
|
['identifierType', 'logicalType', 'securityClassification'],
|
2017-08-07 22:21:05 -07:00
|
|
|
identifierField,
|
|
|
|
complianceEntities
|
|
|
|
);
|
|
|
|
|
|
|
|
return { ...acc, ...{ [identifierField]: currentPrivacyAttrs } };
|
|
|
|
}, {});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Computed prop over the current Id fields in the Privacy Policy
|
|
|
|
* @type {Ember.computed}
|
|
|
|
*/
|
|
|
|
columnIdFieldsToCurrentPrivacyPolicy: computed(
|
|
|
|
'truncatedColumnFields',
|
|
|
|
`${policyComplianceEntitiesKey}.[]`,
|
|
|
|
function() {
|
|
|
|
const columnFieldNames = get(this, 'truncatedColumnFields').map(({ fieldName }) => fieldName);
|
|
|
|
return this.mapColumnIdFieldsToCurrentPrivacyPolicy(columnFieldNames);
|
2017-03-27 18:26:09 -07:00
|
|
|
}
|
|
|
|
),
|
|
|
|
|
2017-08-07 22:21:05 -07:00
|
|
|
/**
|
|
|
|
* Caches a reference to the generated list of merged data between the column api and the current compliance entities list
|
|
|
|
* @type {Ember.computed}
|
|
|
|
*/
|
|
|
|
mergedComplianceEntitiesAndColumnFields: computed('columnIdFieldsToCurrentPrivacyPolicy', function() {
|
|
|
|
// truncatedColumnFields is a dependency for cp columnIdFieldsToCurrentPrivacyPolicy, so no need to dep on that directly
|
|
|
|
return this.mergeComplianceEntitiesAndColumnFields(
|
|
|
|
get(this, 'columnIdFieldsToCurrentPrivacyPolicy'),
|
2017-08-18 03:42:40 -07:00
|
|
|
get(this, 'truncatedColumnFields'),
|
|
|
|
get(this, 'identifierFieldToSuggestion')
|
2017-08-07 22:21:05 -07:00
|
|
|
);
|
|
|
|
}),
|
|
|
|
|
2017-08-18 03:42:40 -07:00
|
|
|
/**
|
|
|
|
* Creates a mapping of compliance suggestions to identifierField
|
|
|
|
* This improves performance in a subsequent merge op since this loop
|
|
|
|
* happens only once and is cached
|
|
|
|
* @type {Ember.computed}
|
|
|
|
*/
|
2017-08-20 20:05:18 -07:00
|
|
|
identifierFieldToSuggestion: computed('complianceSuggestion', function() {
|
2017-08-18 03:42:40 -07:00
|
|
|
const identifierFieldToSuggestion = {};
|
2017-08-20 20:05:18 -07:00
|
|
|
const complianceSuggestions = getWithDefault(this, 'complianceSuggestion.complianceSuggestions', []);
|
2017-08-18 03:42:40 -07:00
|
|
|
// If the compliance suggestions array contains suggestions the create reduced map,
|
|
|
|
// otherwise, ignore
|
|
|
|
if (complianceSuggestions.length) {
|
|
|
|
return complianceSuggestions.reduce(
|
|
|
|
(identifierFieldToSuggestion, { fieldName, identifierTypePrediction, logicalTypePrediction }) => ({
|
|
|
|
...identifierFieldToSuggestion,
|
|
|
|
[fieldName]: {
|
|
|
|
identifierTypePrediction,
|
|
|
|
logicalTypePrediction
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
identifierFieldToSuggestion
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return identifierFieldToSuggestion;
|
|
|
|
}),
|
|
|
|
|
2017-03-27 18:50:55 -07:00
|
|
|
/**
|
2017-05-19 18:26:38 -07:00
|
|
|
* Checks that each entity in sourceEntities has a generic
|
|
|
|
* @param {Array} sourceEntities = [] the source entities to be matched against
|
|
|
|
* @param {Array} logicalTypes = [] list of logicalTypes to check against
|
2017-03-27 18:50:55 -07:00
|
|
|
*/
|
2017-05-19 18:26:38 -07:00
|
|
|
checkEachEntityByLogicalType: (sourceEntities = [], logicalTypes = []) =>
|
|
|
|
sourceEntities.every(
|
|
|
|
({ logicalType }) =>
|
2017-06-12 17:57:53 -07:00
|
|
|
typeof logicalType === 'object' ? logicalTypes.includes(logicalType.value) : logicalTypes.includes(logicalType)
|
2017-05-19 18:26:38 -07:00
|
|
|
),
|
2017-03-24 20:27:43 -07:00
|
|
|
|
2017-04-02 15:40:43 -07:00
|
|
|
/**
|
|
|
|
* TODO:DSS-6719 refactor into mixin
|
|
|
|
* Clears recently shown user messages
|
|
|
|
*/
|
|
|
|
clearMessages() {
|
|
|
|
return setProperties(this, {
|
|
|
|
_message: '',
|
|
|
|
_alertType: ''
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method to update user when an async server update to the
|
|
|
|
* security specification is handled.
|
2017-05-19 08:45:05 -07:00
|
|
|
* @param {Promise|*} request the server request
|
2017-08-30 11:09:33 -07:00
|
|
|
* @param {String} [successMessage] optional message for successful response
|
2017-05-19 08:45:05 -07:00
|
|
|
* @param { Boolean} [isSaving = false] optional flag indicating when the user intends to persist / save
|
2017-04-02 15:40:43 -07:00
|
|
|
*/
|
2017-05-19 08:45:05 -07:00
|
|
|
whenRequestCompletes(request, { successMessage, isSaving = false } = {}) {
|
2017-08-30 11:09:33 -07:00
|
|
|
const notify = get(this, 'notifications.notify');
|
|
|
|
|
2017-07-18 15:01:28 -07:00
|
|
|
return Promise.resolve(request)
|
2017-04-11 16:02:41 -07:00
|
|
|
.then(({ status = 'error' }) => {
|
2017-05-01 09:57:17 -07:00
|
|
|
return status === 'ok'
|
2017-08-30 11:09:33 -07:00
|
|
|
? notify('success', { content: successMessage || successUpdating })
|
2017-05-01 09:57:17 -07:00
|
|
|
: Promise.reject(new Error(`Reason code for this is ${status}`));
|
2017-04-02 15:40:43 -07:00
|
|
|
})
|
2017-04-11 16:02:41 -07:00
|
|
|
.catch(err => {
|
2017-08-30 11:09:33 -07:00
|
|
|
let message = `${failedUpdating} \n ${err}`;
|
2017-04-02 15:40:43 -07:00
|
|
|
|
2017-05-19 08:45:05 -07:00
|
|
|
if (get(this, 'isNewComplianceInfo') && !isSaving) {
|
2017-08-30 11:09:33 -07:00
|
|
|
return notify('info', {
|
2017-08-30 10:26:44 -07:00
|
|
|
content: 'This dataset does not have any previously saved fields with a identifying information.'
|
|
|
|
});
|
2017-04-02 15:40:43 -07:00
|
|
|
}
|
|
|
|
|
2017-08-30 11:09:33 -07:00
|
|
|
notify('error', { content: message });
|
2017-04-02 15:40:43 -07:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-05-19 08:45:05 -07:00
|
|
|
/**
|
|
|
|
* Sets the default classification for the given identifier field
|
2017-06-06 11:34:53 -07:00
|
|
|
* Using the provided logicalType, or in some cases the identifierType, determines the fields
|
|
|
|
* default security classification based on a lookup
|
|
|
|
* @param {String} identifierField the field for which the default classification should apply
|
|
|
|
* @param {String} [identifierType] the current identifier type for the field
|
|
|
|
* @param {String} [logicalType] the logicalType / (field format) for the identifierField
|
2017-05-19 08:45:05 -07:00
|
|
|
*/
|
2017-06-06 11:34:53 -07:00
|
|
|
setDefaultClassification({ identifierField, identifierType }, { value: logicalType = '' } = {}) {
|
|
|
|
let defaultTypeClassification = defaultFieldDataTypeClassification[logicalType] || null;
|
|
|
|
// If the identifierType is of custom, set the default classification to the of a CUSTOM_ID, otherwise use value
|
|
|
|
// based on logicalType
|
2017-08-15 23:16:38 -07:00
|
|
|
defaultTypeClassification =
|
|
|
|
identifierType === fieldIdentifierTypes.custom.value
|
|
|
|
? defaultFieldDataTypeClassification['CUSTOM_ID']
|
|
|
|
: defaultTypeClassification;
|
2017-05-19 08:45:05 -07:00
|
|
|
this.actions.onFieldClassificationChange.call(this, { identifierField }, { value: defaultTypeClassification });
|
|
|
|
},
|
|
|
|
|
2017-05-19 18:26:38 -07:00
|
|
|
/**
|
|
|
|
* Requires that the user confirm that any non-id fields are ok to be saved without a field format specified
|
|
|
|
* @return {Boolean}
|
|
|
|
*/
|
2017-08-28 01:38:47 -07:00
|
|
|
async confirmUnformattedFields() {
|
2017-05-19 18:26:38 -07:00
|
|
|
// Current list of compliance entities on policy
|
2017-07-18 15:01:28 -07:00
|
|
|
const complianceEntities = get(this, policyComplianceEntitiesKey);
|
2017-07-18 17:09:43 -07:00
|
|
|
// All candidate fields that can be on policy, excluding tracking type fields
|
2017-08-07 22:21:05 -07:00
|
|
|
const datasetFields = get(
|
|
|
|
this,
|
|
|
|
'mergedComplianceEntitiesAndColumnFields'
|
2017-08-18 03:42:40 -07:00
|
|
|
).map(({ identifierField, identifierType, logicalType, classification }) => ({
|
2017-08-07 22:21:05 -07:00
|
|
|
identifierField,
|
|
|
|
identifierType,
|
2017-08-18 03:42:40 -07:00
|
|
|
logicalType,
|
2017-08-23 11:00:10 -07:00
|
|
|
securityClassification: classification
|
2017-08-07 22:21:05 -07:00
|
|
|
}));
|
2017-07-18 15:01:28 -07:00
|
|
|
// Fields that do not have a logicalType, and no identifierType or identifierType is `fieldIdentifierTypes.none`
|
2017-08-07 22:21:05 -07:00
|
|
|
const { formatted, unformatted } = datasetFields.reduce(
|
|
|
|
({ formatted, unformatted }, field) => {
|
|
|
|
const { identifierType, logicalType } = getProperties(field, ['identifierType', 'logicalType']);
|
|
|
|
if (!logicalType && (fieldIdentifierTypes.none.value === identifierType || !identifierType)) {
|
|
|
|
unformatted = [...unformatted, field];
|
|
|
|
} else {
|
|
|
|
formatted = [...formatted, field];
|
|
|
|
}
|
2017-08-18 03:42:40 -07:00
|
|
|
|
2017-08-07 22:21:05 -07:00
|
|
|
return { formatted, unformatted };
|
|
|
|
},
|
|
|
|
{ formatted: [], unformatted: [] }
|
2017-05-19 18:26:38 -07:00
|
|
|
);
|
2017-08-28 01:38:47 -07:00
|
|
|
|
2017-08-29 16:50:44 -07:00
|
|
|
const dialogActions = {};
|
2017-05-19 18:26:38 -07:00
|
|
|
let isConfirmed = true;
|
2017-08-07 22:21:05 -07:00
|
|
|
let unformattedComplianceEntities = [];
|
2017-05-19 18:26:38 -07:00
|
|
|
|
|
|
|
// If there are unformatted fields, require confirmation from user
|
2017-08-07 22:21:05 -07:00
|
|
|
if (unformatted.length) {
|
|
|
|
unformattedComplianceEntities = unformatted.map(({ identifierField }) => ({
|
|
|
|
identifierField,
|
|
|
|
identifierType: fieldIdentifierTypes.none.value,
|
2017-08-23 11:00:10 -07:00
|
|
|
logicalType: null,
|
|
|
|
securityClassification: null
|
2017-08-07 22:21:05 -07:00
|
|
|
}));
|
2017-07-18 15:01:28 -07:00
|
|
|
|
2017-08-28 01:38:47 -07:00
|
|
|
const confirmHandler = (function() {
|
|
|
|
return new Promise((resolve, reject) => {
|
2017-08-29 16:50:44 -07:00
|
|
|
dialogActions['didConfirm'] = () => resolve();
|
|
|
|
dialogActions['didDismiss'] = () => reject();
|
2017-08-28 01:38:47 -07:00
|
|
|
});
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Create confirmation dialog
|
|
|
|
get(this, 'notifications').notify('confirm', {
|
|
|
|
header: 'Some field formats are unspecified',
|
|
|
|
content:
|
|
|
|
`There are ${unformatted.length} non-ID fields that have no field format specified. ` +
|
2017-06-14 12:39:25 -07:00
|
|
|
`Are you sure they don't contain any of the following PII?\n\n` +
|
2017-08-28 01:38:47 -07:00
|
|
|
`Name, Email, Phone, Address, Location, IP Address, Payment Info, Password, National ID, Device ID etc.`,
|
2017-08-29 16:50:44 -07:00
|
|
|
dialogActions: dialogActions
|
2017-08-28 01:38:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
await confirmHandler;
|
|
|
|
} catch (e) {
|
|
|
|
isConfirmed = false;
|
|
|
|
}
|
2017-05-19 18:26:38 -07:00
|
|
|
}
|
|
|
|
|
2017-08-30 18:07:01 -07:00
|
|
|
isConfirmed && complianceEntities.setObjects([...formatted, ...unformattedComplianceEntities]);
|
|
|
|
|
2017-05-19 18:26:38 -07:00
|
|
|
return isConfirmed;
|
|
|
|
},
|
|
|
|
|
2017-07-18 15:01:28 -07:00
|
|
|
/**
|
|
|
|
* Ensures the fields in the updated list of compliance entities meet the criteria
|
|
|
|
* checked in the function. If criteria is not met, an the returned promise is settled
|
|
|
|
* in a rejected state, otherwise fulfilled
|
|
|
|
* @method
|
|
|
|
* @return {any | Promise<any>}
|
|
|
|
*/
|
|
|
|
validateFields() {
|
2017-08-30 18:41:23 -07:00
|
|
|
const notify = get(this, 'notifications.notify');
|
2017-07-18 15:01:28 -07:00
|
|
|
const complianceEntities = get(this, policyComplianceEntitiesKey);
|
|
|
|
const idFieldsHaveValidLogicalType = this.checkEachEntityByLogicalType(
|
|
|
|
complianceEntities.filter(({ identifierType }) => fieldIdentifierTypeIds.includes(identifierType)),
|
|
|
|
[...genericLogicalTypes, ...idLogicalTypes]
|
|
|
|
);
|
|
|
|
const fieldIdentifiersAreUnique = listIsUnique(complianceEntities.mapBy('identifierField'));
|
|
|
|
const schemaFieldLengthGreaterThanComplianceEntities = this.isSchemaFieldLengthGreaterThanComplianceEntities();
|
|
|
|
|
|
|
|
if (!fieldIdentifiersAreUnique || !schemaFieldLengthGreaterThanComplianceEntities) {
|
2017-08-30 18:41:23 -07:00
|
|
|
notify('error', { content: complianceDataException });
|
2017-07-18 15:01:28 -07:00
|
|
|
return Promise.reject(new Error(complianceDataException));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!idFieldsHaveValidLogicalType) {
|
2017-08-30 18:41:23 -07:00
|
|
|
return Promise.reject(notify('error', { content: missingTypes }));
|
2017-07-18 15:01:28 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-08-20 18:12:56 -07:00
|
|
|
/**
|
|
|
|
* Gets a reference to the current dataset classification object
|
|
|
|
*/
|
|
|
|
getDatasetClassificationRef() {
|
|
|
|
let sourceDatasetClassification = getWithDefault(this, datasetClassificationKey, {});
|
|
|
|
|
|
|
|
// For datasets initially without a datasetClassification, the default value is null
|
|
|
|
if (sourceDatasetClassification === null) {
|
|
|
|
sourceDatasetClassification = set(this, datasetClassificationKey, {});
|
|
|
|
}
|
|
|
|
|
|
|
|
return sourceDatasetClassification;
|
|
|
|
},
|
|
|
|
|
2017-02-13 14:51:31 -08:00
|
|
|
actions: {
|
2017-08-20 18:12:56 -07:00
|
|
|
/**
|
|
|
|
* Sets each datasetClassification value as false
|
|
|
|
*/
|
2017-08-29 16:50:44 -07:00
|
|
|
async markDatasetAsNotContainingMemberData() {
|
|
|
|
const dialogActions = {};
|
|
|
|
const confirmMarkAllHandler = new Promise((resolve, reject) => {
|
|
|
|
dialogActions.didDismiss = () => reject();
|
|
|
|
dialogActions.didConfirm = () => resolve();
|
|
|
|
});
|
|
|
|
let willMarkAllAsNo = true;
|
|
|
|
|
|
|
|
get(this, 'notifications').notify('confirm', {
|
2017-08-30 10:26:44 -07:00
|
|
|
content: 'Are you sure that any this dataset does not contain any of the listed types of member data?',
|
|
|
|
header: 'Dataset contains no member data',
|
2017-08-29 16:50:44 -07:00
|
|
|
dialogActions
|
|
|
|
});
|
|
|
|
|
|
|
|
try {
|
|
|
|
await confirmMarkAllHandler;
|
|
|
|
} catch (e) {
|
|
|
|
willMarkAllAsNo = false;
|
|
|
|
}
|
2017-08-20 18:12:56 -07:00
|
|
|
|
|
|
|
return (
|
|
|
|
willMarkAllAsNo &&
|
|
|
|
setProperties(
|
|
|
|
this.getDatasetClassificationRef(),
|
|
|
|
datasetClassifiersKeys.reduce(
|
|
|
|
(classification, classifier) => ({ ...classification, ...{ [classifier]: false } }),
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2017-08-20 18:53:01 -07:00
|
|
|
/**
|
|
|
|
* Sets the flag to show all member potential member data fields that may be contained in this dataset
|
|
|
|
*/
|
|
|
|
onShowAllDatasetMemberData() {
|
|
|
|
return set(this, 'showAllDatasetMemberData', true);
|
|
|
|
},
|
|
|
|
|
2017-06-05 09:49:37 -07:00
|
|
|
/**
|
2017-08-29 16:50:44 -07:00
|
|
|
* Handler for setting the compliance policy into edit mode and rendering
|
2017-06-05 09:49:37 -07:00
|
|
|
*/
|
2017-08-29 16:50:44 -07:00
|
|
|
onEditCompliancePolicy() {
|
|
|
|
setProperties(this, { isEditingCompliancePolicy: true, isEditingDatasetClassification: false });
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for setting the dataset classification into edit mode and rendering into DOM
|
|
|
|
*/
|
|
|
|
async onEditDatasetClassification() {
|
|
|
|
const isConfirmed = await this.confirmUnformattedFields();
|
|
|
|
|
2017-08-30 18:41:23 -07:00
|
|
|
// Ensure that the fields on the policy meet the validation criteria before proceeding
|
|
|
|
// Otherwise exit early
|
|
|
|
try {
|
|
|
|
await this.validateFields();
|
|
|
|
} catch (e) {
|
|
|
|
// Flag this dataset's data as problematic
|
|
|
|
if (e instanceof Error && e.message === complianceDataException) {
|
|
|
|
set(this, '_hasBadData', true);
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-29 16:50:44 -07:00
|
|
|
// If user provides confirmation for unformatted fields or there are none,
|
|
|
|
// then validate fields against expectations
|
|
|
|
// otherwise inform user of validation exception
|
|
|
|
if (isConfirmed) {
|
|
|
|
setProperties(this, { isEditingCompliancePolicy: false, isEditingDatasetClassification: true });
|
|
|
|
}
|
2017-06-05 09:49:37 -07:00
|
|
|
},
|
|
|
|
|
2017-08-18 11:10:08 -07:00
|
|
|
/**
|
|
|
|
* Augments the field props with w a suggestionAuthority indicating that the field
|
|
|
|
* suggestion has either been accepted or ignored, and assigns the value of that change to the prop
|
|
|
|
* @param {object} field field for which this suggestion intent should apply
|
|
|
|
* @param {string | void} [intent] user's intended action for suggestion, Defaults to `ignore`
|
|
|
|
*/
|
|
|
|
onFieldSuggestionIntentChange(field, intent = 'ignore') {
|
|
|
|
set(field, 'suggestionAuthority', intent);
|
|
|
|
},
|
|
|
|
|
2017-06-01 13:11:26 -07:00
|
|
|
/**
|
|
|
|
* Receives the json representation for compliance and applies each key to the policy
|
2017-08-30 10:26:44 -07:00
|
|
|
* @param {string} textString string representation for the JSON file
|
2017-06-01 13:11:26 -07:00
|
|
|
*/
|
|
|
|
onComplianceJsonUpload(textString) {
|
2017-08-30 10:26:44 -07:00
|
|
|
let policy;
|
|
|
|
try {
|
|
|
|
policy = JSON.parse(textString);
|
|
|
|
} catch (e) {
|
|
|
|
get(this, 'notifications').notify('error', {
|
|
|
|
content: invalidPolicyData
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-01 13:11:26 -07:00
|
|
|
if (isPolicyExpectedShape(policy)) {
|
2017-08-30 10:26:44 -07:00
|
|
|
setProperties(this, {
|
|
|
|
'complianceInfo.complianceEntities': policy.complianceEntities,
|
|
|
|
'complianceInfo.datasetClassification': policy.datasetClassification
|
|
|
|
});
|
2017-06-05 11:22:48 -07:00
|
|
|
|
2017-08-30 10:26:44 -07:00
|
|
|
get(this, 'notifications').notify('info', {
|
|
|
|
content: successUploading
|
|
|
|
});
|
2017-06-01 13:11:26 -07:00
|
|
|
}
|
|
|
|
|
2017-08-30 10:26:44 -07:00
|
|
|
get(this, 'notifications').notify('error', {
|
|
|
|
content: invalidPolicyData
|
|
|
|
});
|
2017-06-01 13:11:26 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the compliance policy download action
|
|
|
|
*/
|
|
|
|
onComplianceDownloadJson() {
|
|
|
|
const currentPolicy = get(this, 'complianceInfo');
|
2017-08-15 23:16:38 -07:00
|
|
|
const policyProps = [datasetClassificationKey, policyComplianceEntitiesKey].map(name => name.split('.').pop());
|
2017-06-01 13:11:26 -07:00
|
|
|
const policy = Object.assign({}, getProperties(currentPolicy, policyProps));
|
|
|
|
const href = `data:text/json;charset=utf-8,${encodeURIComponent(JSON.stringify(policy))}`;
|
|
|
|
const download = `${get(this, 'datasetName')}_policy.json`;
|
|
|
|
const anchor = document.createElement('a');
|
2017-07-13 09:56:40 -07:00
|
|
|
const anchorParent = document.body;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Post download housekeeping
|
|
|
|
*/
|
|
|
|
const cleanupPostDownload = () => {
|
|
|
|
anchor.removeEventListener('click', cleanupPostDownload);
|
|
|
|
anchorParent.removeChild(anchor);
|
|
|
|
};
|
|
|
|
|
2017-06-01 13:11:26 -07:00
|
|
|
Object.assign(anchor, { download, href });
|
2017-07-13 09:56:40 -07:00
|
|
|
anchor.addEventListener('click', cleanupPostDownload);
|
|
|
|
|
|
|
|
// Element needs to be in DOM to receive event in firefox
|
|
|
|
anchorParent.appendChild(anchor);
|
|
|
|
|
2017-06-01 13:11:26 -07:00
|
|
|
anchor.click();
|
|
|
|
},
|
|
|
|
|
2017-03-27 18:26:09 -07:00
|
|
|
/**
|
2017-05-19 08:45:05 -07:00
|
|
|
* When a user updates the identifierFieldType in the DOM, update the backing store
|
2017-05-19 18:26:38 -07:00
|
|
|
* @param {String} identifierField
|
|
|
|
* @param {String} logicalType
|
|
|
|
* @param {String} identifierType
|
2017-03-27 18:26:09 -07:00
|
|
|
*/
|
2017-08-15 23:16:38 -07:00
|
|
|
onFieldIdentifierTypeChange({ identifierField }, { value: identifierType }) {
|
2017-08-07 22:21:05 -07:00
|
|
|
const currentComplianceEntities = get(this, 'mergedComplianceEntitiesAndColumnFields');
|
2017-08-15 23:16:38 -07:00
|
|
|
// A reference to the current field in the compliance list, it should exist even for empty complianceEntities
|
|
|
|
// since this is a reference created in the working copy: mergedComplianceEntitiesAndColumnFields
|
2017-08-07 22:21:05 -07:00
|
|
|
const currentFieldInComplianceList = currentComplianceEntities.findBy('identifierField', identifierField);
|
|
|
|
setProperties(currentFieldInComplianceList, {
|
2017-08-15 23:16:38 -07:00
|
|
|
identifierType,
|
2017-08-07 22:21:05 -07:00
|
|
|
logicalType: void 0
|
2017-05-19 08:45:05 -07:00
|
|
|
});
|
2017-06-06 11:34:53 -07:00
|
|
|
// Set the defaultClassification for the identifierField,
|
|
|
|
// although the classification is based on the logicalType,
|
|
|
|
// an identifierField may only have one valid logicalType for it's given identifierType
|
2017-08-15 23:16:38 -07:00
|
|
|
this.setDefaultClassification({ identifierField, identifierType });
|
2017-02-13 14:51:31 -08:00
|
|
|
},
|
|
|
|
|
2017-03-27 18:26:09 -07:00
|
|
|
/**
|
2017-05-19 08:45:05 -07:00
|
|
|
* Updates the logical type for the given identifierField
|
|
|
|
* @param {Object} field
|
|
|
|
* @prop {String} field.identifierField
|
|
|
|
* @param {Event} e the DOM change event
|
2017-03-27 18:26:09 -07:00
|
|
|
* @return {*}
|
|
|
|
*/
|
2017-08-07 22:21:05 -07:00
|
|
|
onFieldLogicalTypeChange(field, { value: logicalType } = {}) {
|
2017-05-19 08:45:05 -07:00
|
|
|
const { identifierField } = field;
|
|
|
|
|
|
|
|
// If the identifierField does not current exist, invoke onFieldIdentifierChange to add it on the compliance list
|
2017-08-07 22:21:05 -07:00
|
|
|
if (!field) {
|
2017-05-19 08:45:05 -07:00
|
|
|
this.actions.onFieldIdentifierTypeChange.call(
|
|
|
|
this,
|
2017-08-07 22:21:05 -07:00
|
|
|
{ identifierField, logicalType },
|
2017-05-19 08:45:05 -07:00
|
|
|
{ value: fieldIdentifierTypes.none.value }
|
|
|
|
);
|
2017-05-19 11:57:46 -07:00
|
|
|
} else {
|
2017-08-07 22:21:05 -07:00
|
|
|
set(field, 'logicalType', logicalType);
|
2017-05-19 08:45:05 -07:00
|
|
|
}
|
2017-02-13 14:51:31 -08:00
|
|
|
|
2017-05-19 08:45:05 -07:00
|
|
|
return this.setDefaultClassification({ identifierField }, { value: logicalType });
|
2017-02-13 14:51:31 -08:00
|
|
|
},
|
|
|
|
|
2017-03-27 00:08:08 -07:00
|
|
|
/**
|
2017-05-19 08:45:05 -07:00
|
|
|
* Updates the filed classification
|
|
|
|
* @param {String} identifierField the identifier field to update the classification for
|
|
|
|
* @param {String} classification
|
|
|
|
* @return {*}
|
2017-03-27 00:08:08 -07:00
|
|
|
*/
|
2017-05-19 08:45:05 -07:00
|
|
|
onFieldClassificationChange({ identifierField }, { value: classification = null }) {
|
2017-08-07 22:21:05 -07:00
|
|
|
const currentFieldInComplianceList = get(this, 'mergedComplianceEntitiesAndColumnFields').findBy(
|
|
|
|
'identifierField',
|
|
|
|
identifierField
|
|
|
|
);
|
2017-04-02 15:40:43 -07:00
|
|
|
// TODO:DSS-6719 refactor into mixin
|
|
|
|
this.clearMessages();
|
|
|
|
|
2017-08-07 22:21:05 -07:00
|
|
|
// Apply the updated classification value to the current instance of the field in working copy
|
|
|
|
set(currentFieldInComplianceList, 'classification', classification);
|
2017-03-27 00:08:08 -07:00
|
|
|
},
|
|
|
|
|
2017-03-27 18:30:44 -07:00
|
|
|
/**
|
2017-05-19 08:45:05 -07:00
|
|
|
* Updates the source object representing the current datasetClassification map
|
|
|
|
* @param {String} classifier the property on the datasetClassification to update
|
|
|
|
* @param {Boolean} value flag indicating if this dataset contains member data for the specified classifier
|
2017-05-19 18:26:38 -07:00
|
|
|
* @return {*}
|
2017-03-27 18:30:44 -07:00
|
|
|
*/
|
2017-05-19 08:45:05 -07:00
|
|
|
onChangeDatasetClassification(classifier, value) {
|
2017-08-20 18:12:56 -07:00
|
|
|
return set(this.getDatasetClassificationRef(), classifier, value);
|
2017-02-13 14:51:31 -08:00
|
|
|
},
|
|
|
|
|
2017-03-27 18:50:55 -07:00
|
|
|
/**
|
|
|
|
* If all validity checks are passed, invoke onSave action on controller
|
|
|
|
*/
|
2017-07-18 15:01:28 -07:00
|
|
|
async saveCompliance() {
|
|
|
|
const setSaveFlag = (flag = false) => set(this, 'isSaving', flag);
|
2017-05-19 18:26:38 -07:00
|
|
|
|
2017-08-29 16:50:44 -07:00
|
|
|
try {
|
|
|
|
const isSaving = true;
|
|
|
|
const onSave = get(this, 'onSave');
|
|
|
|
setSaveFlag(isSaving);
|
|
|
|
|
|
|
|
return await this.whenRequestCompletes(onSave(), { isSaving });
|
|
|
|
} finally {
|
|
|
|
setSaveFlag();
|
2017-03-27 18:50:55 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-02-13 14:51:31 -08:00
|
|
|
// Rolls back changes made to the compliance spec to current
|
|
|
|
// server state
|
2017-03-27 18:26:09 -07:00
|
|
|
resetCompliance() {
|
2017-04-02 15:40:43 -07:00
|
|
|
const options = {
|
|
|
|
successMessage: 'Field classification has been reset to the previously saved state.'
|
|
|
|
};
|
|
|
|
this.whenRequestCompletes(get(this, 'onReset')(), options);
|
2017-02-13 14:51:31 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|