NIFI-6769:

- Ensuring the users policy listing can handle when the specified policy is unknown.

This closes #3807.
This commit is contained in:
Matt Gilman 2019-10-10 11:06:10 -04:00 committed by Rob Fellows
parent d64f4fa942
commit ed1e843609
No known key found for this signature in database
GPG Key ID: DC06CD21901CA426
2 changed files with 41 additions and 13 deletions

View File

@ -1709,13 +1709,25 @@
return formattedGarbageCollections;
},
/**
* Returns whether the specified resource is for a global policy.
*
* @param resource
*/
isGlobalPolicy: function (value) {
return nfCommon.getPolicyTypeListing(value) !== null;
},
/**
* Gets the policy type for the specified resource.
*
* @param value
* @returns {*}
*/
getPolicyTypeListing: function (value) {
var nest = d3.nest()
.key(function (d) {
return d.value;
})
.map(policyTypeListing, d3.map);
return nest.get(value)[0];
return policyTypeListing.find(function (policy) {
return value === policy.value;
});
},
/**

View File

@ -534,12 +534,21 @@
/**
* Generates a human readable global policy string.
*
* @param policy
* @returns {string}
*/
var globalResourceParser = function (policy) {
return 'Global policy to ' + policy.text;
};
/**
* Generates a human readable policy string for an unknown resource.
*
* @param dataContext
* @returns {string}
*/
var globalResourceParser = function (dataContext) {
return 'Global policy to ' +
nfCommon.getPolicyTypeListing(nfCommon.substringAfterFirst(dataContext.component.resource, '/')).text;
var unknownResourceParser = function (dataContext) {
return '<span class="unset">Unknown resource ' + nfCommon.escapeHtml(dataContext.component.resource) + '</span>';
};
/**
@ -991,12 +1000,19 @@
if (dataContext.component.resource.startsWith('/restricted-components')) {
// restricted components policy
return restrictedComponentResourceParser(dataContext);
} else if (nfCommon.isUndefinedOrNull(dataContext.component.componentReference)) {
// global policy
return globalResourceParser(dataContext);
} else {
} else if (nfCommon.isDefinedAndNotNull(dataContext.component.componentReference)) {
// not restricted/global policy... check if user has access to the component reference
return componentResourceParser(dataContext);
} else {
// may be a global policy
var policy = nfCommon.getPolicyTypeListing(nfCommon.substringAfterFirst(dataContext.component.resource, '/'));
// if known global policy, format it otherwise format as unknown
if (nfCommon.isDefinedAndNotNull(policy)) {
return globalResourceParser(policy);
} else {
return unknownResourceParser(dataContext);
}
}
};