2017-02-13 14:51:31 -08:00
|
|
|
import Ember from 'ember';
|
|
|
|
|
2017-03-24 20:27:43 -07:00
|
|
|
const {
|
|
|
|
Component,
|
|
|
|
computed,
|
|
|
|
set,
|
|
|
|
get,
|
|
|
|
getWithDefault
|
|
|
|
} = Ember;
|
|
|
|
|
|
|
|
const complianceListKey = 'privacyCompliancePolicy.compliancePurgeEntities';
|
|
|
|
// List of field formats for security compliance
|
|
|
|
const fieldFormats = [
|
|
|
|
'MEMBER_ID', 'SUBJECT_MEMBER_ID', 'URN', 'SUBJECT_URN', 'COMPANY_ID', 'GROUP_ID', 'CUSTOMER_ID'
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Computed macro tha checks if a dependentList has a specified privacy type
|
|
|
|
* @param {String} dependentListKey
|
|
|
|
* @param {String} type
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
const datasetHasPrivacyIdentifierType = (dependentListKey, type) => {
|
|
|
|
const prop = 'identifierType';
|
|
|
|
|
|
|
|
return computed(`${dependentListKey}.@each.${prop}`, {
|
|
|
|
get() {
|
|
|
|
const list = get(this, dependentListKey) || [];
|
|
|
|
return list.filterBy(prop, type).length > 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
sortColumnWithName: 'name',
|
|
|
|
filterBy: 'name',
|
|
|
|
sortDirection: 'asc',
|
2017-02-13 14:51:31 -08:00
|
|
|
searchTerm: '',
|
2017-03-24 20:27:43 -07:00
|
|
|
|
|
|
|
radioSelection: {
|
|
|
|
memberId: null,
|
|
|
|
subjectMemberId: null,
|
|
|
|
urnId: null,
|
|
|
|
orgId: null
|
2017-02-13 14:51:31 -08:00
|
|
|
},
|
|
|
|
|
2017-03-24 20:27:43 -07:00
|
|
|
hasMemberId: datasetHasPrivacyIdentifierType(complianceListKey, 'MEMBER_ID'),
|
|
|
|
hasSubjectMemberId: datasetHasPrivacyIdentifierType(complianceListKey, 'SUBJECT_MEMBER_ID'),
|
|
|
|
hasUrnId: datasetHasPrivacyIdentifierType(complianceListKey, 'URN'),
|
|
|
|
hasOrgId: datasetHasPrivacyIdentifierType(complianceListKey, 'COMPANY_ID'),
|
2017-02-13 14:51:31 -08:00
|
|
|
|
2017-03-24 20:27:43 -07:00
|
|
|
isMemberIdSelected: computed.notEmpty('radioSelection.memberId'),
|
|
|
|
isMemberIdSelectedTrue: computed.equal('radioSelection.memberId', true),
|
|
|
|
isSubjectMemberIdSelected: computed.notEmpty('radioSelection.subjectMemberId'),
|
|
|
|
isUrnIdSelected: computed.notEmpty('radioSelection.urnId'),
|
|
|
|
|
|
|
|
showSubjectMemberIdPrompt: computed.equal('radioSelection.memberId', false),
|
|
|
|
showUrnIdPrompt: computed.or('isSubjectMemberIdSelected', 'isMemberIdSelectedTrue'),
|
|
|
|
showOrgIdPrompt: computed.bool('isUrnIdSelected'),
|
2017-02-13 14:51:31 -08:00
|
|
|
|
2017-03-24 20:27:43 -07:00
|
|
|
identifierTypes: ['', ...fieldFormats].map(type => ({
|
|
|
|
value: type,
|
|
|
|
label: type ? type.replace(/_/g, ' ').toLowerCase().capitalize() : 'Please select'
|
|
|
|
})),
|
|
|
|
|
|
|
|
complianceEntities: computed(`${complianceListKey}.[]`, function () {
|
|
|
|
return getWithDefault(this, complianceListKey, []);
|
2017-02-13 14:51:31 -08:00
|
|
|
}),
|
|
|
|
|
2017-03-24 20:27:43 -07:00
|
|
|
ownerFieldIdType(field) {
|
|
|
|
const ownerField = getWithDefault(this, complianceListKey, []).filterBy('identifierField', field).shift();
|
|
|
|
return ownerField && ownerField.identifierType;
|
2017-02-13 14:51:31 -08:00
|
|
|
},
|
|
|
|
|
2017-03-24 20:27:43 -07:00
|
|
|
complianceFields: computed('complianceEntities', 'datasetSchemaFieldsAndTypes', function () {
|
|
|
|
const complianceFieldNames = get(this, 'complianceEntities').mapBy('identifierField');
|
2017-02-13 14:51:31 -08:00
|
|
|
|
2017-03-24 20:27:43 -07:00
|
|
|
return get(this, 'datasetSchemaFieldsAndTypes').map(({name, type}) => ({
|
|
|
|
name,
|
|
|
|
type,
|
|
|
|
hasPrivacyData: complianceFieldNames.includes(name),
|
|
|
|
format: get(this, 'ownerFieldIdType').call(this, name)
|
|
|
|
}));
|
|
|
|
}),
|
2017-02-13 14:51:31 -08:00
|
|
|
|
2017-03-24 20:27:43 -07:00
|
|
|
changeFieldFormat(fieldName, format) {
|
|
|
|
let field = get(this, 'complianceEntities').findBy('identifierField', fieldName);
|
2017-02-13 14:51:31 -08:00
|
|
|
|
2017-03-24 20:27:43 -07:00
|
|
|
if (field && fieldFormats.includes(format)) {
|
|
|
|
return set(field, 'identifierType', format);
|
2017-02-13 14:51:31 -08:00
|
|
|
}
|
2017-03-24 20:27:43 -07:00
|
|
|
},
|
2017-02-13 14:51:31 -08:00
|
|
|
|
2017-03-24 20:27:43 -07:00
|
|
|
toggleFieldOnComplianceList(identifierField, toggle) {
|
|
|
|
const complianceList = get(this, 'complianceEntities');
|
2017-02-13 14:51:31 -08:00
|
|
|
const op = {
|
2017-03-24 20:27:43 -07:00
|
|
|
add() {
|
|
|
|
if (!complianceList.findBy('identifierField', identifierField)) {
|
|
|
|
return complianceList.setObjects([...complianceList, {identifierField}]);
|
2017-02-13 14:51:31 -08:00
|
|
|
}
|
2017-03-24 20:27:43 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
remove: () => complianceList.setObjects(complianceList.filter(item => item.identifierField !== identifierField)),
|
|
|
|
}[toggle];
|
2017-02-13 14:51:31 -08:00
|
|
|
|
2017-03-24 20:27:43 -07:00
|
|
|
return typeof op === 'function' && op();
|
2017-02-13 14:51:31 -08:00
|
|
|
},
|
|
|
|
|
2017-03-24 20:27:43 -07:00
|
|
|
ensureTypeContainsFormat: (updatedCompliance) =>
|
|
|
|
updatedCompliance.every(entity => fieldFormats.includes(get(entity, 'identifierType'))),
|
|
|
|
|
2017-02-13 14:51:31 -08:00
|
|
|
actions: {
|
2017-03-24 20:27:43 -07:00
|
|
|
onFieldFormatChange({name: fieldName}, {value: format}) {
|
|
|
|
return this.changeFieldFormat(fieldName, format);
|
2017-02-13 14:51:31 -08:00
|
|
|
},
|
|
|
|
|
2017-03-24 20:27:43 -07:00
|
|
|
onFieldPrivacyChange({name: fieldName, hasPrivacyData}) {
|
|
|
|
const toggle = !hasPrivacyData ? 'add' : 'remove';
|
2017-02-13 14:51:31 -08:00
|
|
|
|
2017-03-24 20:27:43 -07:00
|
|
|
return this.toggleFieldOnComplianceList(fieldName, toggle);
|
2017-02-13 14:51:31 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
saveCompliance () {
|
2017-03-24 20:27:43 -07:00
|
|
|
const allEntitiesHaveValidFormat = this.ensureTypeContainsFormat(get(this, 'complianceEntities'));
|
|
|
|
|
|
|
|
if (allEntitiesHaveValidFormat) {
|
|
|
|
return this.get('onSave')();
|
|
|
|
}
|
2017-02-13 14:51:31 -08:00
|
|
|
},
|
|
|
|
|
|
|
|
// Rolls back changes made to the compliance spec to current
|
|
|
|
// server state
|
|
|
|
resetCompliance () {
|
|
|
|
this.get('onReset')();
|
2017-03-24 20:27:43 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
didChangePrivacyIdentifiable (sectionName, isPrivacyIdentifiable) {
|
|
|
|
const section = {
|
|
|
|
'has-subject-member': 'subjectMemberId',
|
|
|
|
'has-urn': 'urnId',
|
|
|
|
'has-organization': 'orgId',
|
|
|
|
'has-member': 'memberId'
|
|
|
|
}[sectionName];
|
|
|
|
|
|
|
|
return set(this, `radioSelection.${section}`, isPrivacyIdentifiable);
|
2017-02-13 14:51:31 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|