2017-12-06 10:23:33 -08:00
|
|
|
import { capitalize } from '@ember/string';
|
2018-01-18 10:16:29 -08:00
|
|
|
import { IComplianceChangeSet } from 'wherehows-web/components/dataset-compliance';
|
2017-12-14 12:57:17 -08:00
|
|
|
import { ISecurityClassificationOption } from 'wherehows-web/constants/dataset-compliance';
|
2017-12-14 16:41:21 -08:00
|
|
|
import { Classification, ComplianceFieldIdValue } from 'wherehows-web/constants/datasets/compliance';
|
2017-12-12 22:19:01 -08:00
|
|
|
import { IComplianceDataType } from 'wherehows-web/typings/api/list/compliance-datatypes';
|
2017-09-27 09:33:20 -07:00
|
|
|
|
2017-10-04 10:56:59 -07:00
|
|
|
/**
|
|
|
|
* Length of time between suggestion modification time and last modified time for the compliance policy
|
|
|
|
* If a policy has been updated within the range of this window then it is considered as stale / or
|
|
|
|
* has been seen previously
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
const lastSeenSuggestionInterval: number = 7 * 24 * 60 * 60 * 1000;
|
|
|
|
|
2017-10-03 18:07:38 -07:00
|
|
|
/**
|
|
|
|
* Percentage value for a compliance policy suggestion with a low confidence score
|
|
|
|
* @type {number}
|
|
|
|
*/
|
|
|
|
const lowQualitySuggestionConfidenceThreshold = 0.5;
|
|
|
|
|
2017-04-28 22:02:46 -07:00
|
|
|
/**
|
|
|
|
* Stores a unique list of classification values
|
2017-12-12 22:19:01 -08:00
|
|
|
* @type {Array<Classification>} the list of classification values
|
2017-04-28 22:02:46 -07:00
|
|
|
*/
|
2018-01-21 20:21:40 -08:00
|
|
|
const classifiers = [
|
|
|
|
Classification.HighlyConfidential,
|
|
|
|
Classification.Confidential,
|
|
|
|
Classification.LimitedDistribution,
|
|
|
|
Classification.Internal,
|
|
|
|
Classification.Public
|
|
|
|
];
|
2017-05-19 03:05:25 -07:00
|
|
|
|
2018-01-21 21:24:36 -08:00
|
|
|
/**
|
|
|
|
* Lists the dataset security classification options that are exluded for datasets containing PII
|
|
|
|
* @type {Classification[]}
|
|
|
|
*/
|
|
|
|
const classifiersExcludedIfPII = [Classification.Internal, Classification.Public];
|
|
|
|
|
2017-12-06 10:23:33 -08: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
|
|
|
|
*/
|
2017-12-12 22:19:01 -08:00
|
|
|
const formatAsCapitalizedStringWithSpaces = (string: string) => capitalize(string.toLowerCase().replace(/[_]/g, ' '));
|
2017-12-06 10:23:33 -08:00
|
|
|
|
|
|
|
/**
|
2018-01-21 21:24:36 -08:00
|
|
|
* Derives the list of security classification options from the list of classifiers and disables options if
|
|
|
|
* the containsPii argument is truthy. Includes a disabled placeholder option: Unspecified
|
|
|
|
* @param {boolean = false} containsPii flag indicating if the dataset contains Pii
|
|
|
|
* @return {Array<ISecurityClassificationOption>}
|
2017-12-06 10:23:33 -08:00
|
|
|
*/
|
2018-01-21 21:24:36 -08:00
|
|
|
const getSecurityClassificationDropDownOptions = (containsPii: boolean = false): Array<ISecurityClassificationOption> =>
|
|
|
|
[null, ...classifiers].map((value: ISecurityClassificationOption['value']) => ({
|
2018-01-21 20:21:40 -08:00
|
|
|
value,
|
|
|
|
label: value ? formatAsCapitalizedStringWithSpaces(value) : 'Unspecified',
|
2018-01-21 21:24:36 -08:00
|
|
|
isDisabled: !value || (containsPii && classifiersExcludedIfPII.includes(value))
|
|
|
|
}));
|
2017-12-06 10:23:33 -08:00
|
|
|
|
2017-09-18 16:13:30 -07:00
|
|
|
/**
|
|
|
|
* Checks if the identifierType is a mixed Id
|
|
|
|
* @param {string} identifierType
|
2017-10-13 23:08:39 -07:00
|
|
|
* @return {boolean}
|
2017-09-18 16:13:30 -07:00
|
|
|
*/
|
2017-12-14 16:41:21 -08:00
|
|
|
const isMixedId = (identifierType: string) => identifierType === ComplianceFieldIdValue.MixedId;
|
2017-09-18 16:13:30 -07:00
|
|
|
/**
|
|
|
|
* Checks if the identifierType is a custom Id
|
|
|
|
* @param {string} identifierType
|
2017-12-14 16:41:21 -08:00
|
|
|
* @return {boolean}
|
2017-10-13 23:08:39 -07:00
|
|
|
*/
|
2017-12-14 16:41:21 -08:00
|
|
|
const isCustomId = (identifierType: string) => identifierType === ComplianceFieldIdValue.CustomId;
|
2017-09-18 16:13:30 -07:00
|
|
|
|
2017-09-27 09:33:20 -07:00
|
|
|
/**
|
|
|
|
* Caches a list of fieldIdentifierTypes values
|
2017-12-11 18:26:26 -08:00
|
|
|
* @type {Array<ComplianceFieldIdValue>}
|
2017-09-27 09:33:20 -07:00
|
|
|
*/
|
2018-01-18 15:21:34 -08:00
|
|
|
const fieldIdentifierTypeValues: Array<ComplianceFieldIdValue> = <Array<ComplianceFieldIdValue>>Object.values(
|
|
|
|
ComplianceFieldIdValue
|
|
|
|
);
|
2017-09-27 09:33:20 -07:00
|
|
|
|
2017-12-12 22:19:01 -08:00
|
|
|
/**
|
|
|
|
* Retrieves the default security classification for an identifier type, or null if it does not exist
|
|
|
|
* @param {Array<IComplianceDataType>} [complianceDataTypes=[]] the list of compliance data types
|
|
|
|
* @param {ComplianceFieldIdValue} identifierType the compliance data type id string
|
|
|
|
* @returns {(IComplianceDataType['defaultSecurityClassification'] | null)}
|
|
|
|
*/
|
|
|
|
const getDefaultSecurityClassification = (
|
|
|
|
complianceDataTypes: Array<IComplianceDataType> = [],
|
2018-01-18 10:16:29 -08:00
|
|
|
identifierType: IComplianceChangeSet['identifierType']
|
2017-12-12 22:19:01 -08:00
|
|
|
): IComplianceDataType['defaultSecurityClassification'] | null => {
|
2017-12-14 12:57:17 -08:00
|
|
|
const complianceDataType = complianceDataTypes.findBy('id', identifierType || '');
|
2017-12-12 22:19:01 -08:00
|
|
|
|
|
|
|
return complianceDataType ? complianceDataType.defaultSecurityClassification : null;
|
|
|
|
};
|
|
|
|
|
2017-05-23 12:18:55 -07:00
|
|
|
export {
|
2018-01-21 21:24:36 -08:00
|
|
|
getSecurityClassificationDropDownOptions,
|
2017-12-06 10:23:33 -08:00
|
|
|
formatAsCapitalizedStringWithSpaces,
|
2017-09-27 09:33:20 -07:00
|
|
|
fieldIdentifierTypeValues,
|
2017-09-18 16:13:30 -07:00
|
|
|
isMixedId,
|
|
|
|
isCustomId,
|
2017-10-04 10:56:59 -07:00
|
|
|
lastSeenSuggestionInterval,
|
2017-10-16 18:11:57 -07:00
|
|
|
lowQualitySuggestionConfidenceThreshold,
|
2017-12-12 22:19:01 -08:00
|
|
|
getDefaultSecurityClassification
|
2017-05-23 12:18:55 -07:00
|
|
|
};
|