From c9a08e68325a94ea34325b88e7f45290f0ee8bda Mon Sep 17 00:00:00 2001 From: Brijesh Bhalala Date: Thu, 5 Oct 2023 19:21:33 +0530 Subject: [PATCH] RANGER-4424: UI updates to support security zones without any resource Signed-off-by: Madhan Neethiraj --- .../resources/META-INF/jpa_named_queries.xml | 2 +- .../react-webapp/src/images/no-service.svg | 4 + .../AuditEvent/AdminLogs/SecurityZonelogs.jsx | 530 ++++++++++-------- .../views/AuditEvent/OperationAdminModal.jsx | 11 +- .../views/SecurityZone/SecurityZoneForm.jsx | 126 ++--- .../src/views/SecurityZone/ZoneDisplay.jsx | 158 +++--- .../src/views/SecurityZone/ZoneListing.jsx | 2 +- .../ServiceManager/ServiceDefinitions.jsx | 60 +- 8 files changed, 495 insertions(+), 398 deletions(-) create mode 100644 security-admin/src/main/webapp/react-webapp/src/images/no-service.svg diff --git a/security-admin/src/main/resources/META-INF/jpa_named_queries.xml b/security-admin/src/main/resources/META-INF/jpa_named_queries.xml index d3246c60cd..33172ce858 100755 --- a/security-admin/src/main/resources/META-INF/jpa_named_queries.xml +++ b/security-admin/src/main/resources/META-INF/jpa_named_queries.xml @@ -324,7 +324,7 @@ - SELECT obj FROM XXTrxLog obj WHERE obj.transactionId = :transactionId + SELECT obj FROM XXTrxLog obj WHERE obj.transactionId = :transactionId order by obj.id diff --git a/security-admin/src/main/webapp/react-webapp/src/images/no-service.svg b/security-admin/src/main/webapp/react-webapp/src/images/no-service.svg new file mode 100644 index 0000000000..a72198016b --- /dev/null +++ b/security-admin/src/main/webapp/react-webapp/src/images/no-service.svg @@ -0,0 +1,4 @@ + + + + diff --git a/security-admin/src/main/webapp/react-webapp/src/views/AuditEvent/AdminLogs/SecurityZonelogs.jsx b/security-admin/src/main/webapp/react-webapp/src/views/AuditEvent/AdminLogs/SecurityZonelogs.jsx index c6ab380b74..a582cbb8b3 100644 --- a/security-admin/src/main/webapp/react-webapp/src/views/AuditEvent/AdminLogs/SecurityZonelogs.jsx +++ b/security-admin/src/main/webapp/react-webapp/src/views/AuditEvent/AdminLogs/SecurityZonelogs.jsx @@ -25,21 +25,57 @@ import { isEmpty } from "lodash"; export const SecurityZonelogs = ({ data, reportdata }) => { const { objectName, objectClassType, createDate, owner, action } = data; - - const updateZoneDetails = reportdata.filter( - (zone) => zone.action == "update" && zone.attributeName !== "Zone Services" - ); - - const updateZoneServices = reportdata.filter( - (zone) => zone.action == "update" && zone.attributeName == "Zone Services" - ); - const createZoneDetails = (newvalue) => { return !isEmpty(newvalue.replace(/[[\]]/g, "")) ? newvalue.replace(/[[\]]/g, "") : "--"; }; + const zoneServiceData = (reportdata, action, attributeName) => { + return reportdata.filter( + (zone) => zone.action == action && zone.attributeName == attributeName + ); + }; + const createZoneServices = zoneServiceData( + reportdata, + "create", + "Zone Services" + ); + + const deleteZoneServices = zoneServiceData( + reportdata, + "delete", + "Zone Services" + ); + const parseAndFilterData = (zones, zoneValues) => { + return zones.map( + (zone) => !isEmpty(zone[zoneValues]) && JSON.parse(zone[zoneValues]) + ); + }; + + const newZoneServiceData = parseAndFilterData(createZoneServices, "newValue"); + const oldZoneServiceData = parseAndFilterData( + deleteZoneServices, + "previousValue" + ); + const updateZoneDetails = reportdata.filter( + (zone) => zone.action == "update" && zone.attributeName != "Zone Services" + ); + + const updateZoneServices = zoneServiceData( + reportdata, + "update", + "Zone Services" + ); + + const updateZoneOldServices = parseAndFilterData( + updateZoneServices, + "previousValue" + ); + const updateZoneNewServices = parseAndFilterData( + updateZoneServices, + "newValue" + ); return (
{/* CREATE */} @@ -83,31 +119,31 @@ export const SecurityZonelogs = ({ data, reportdata }) => { })}
-
Zone Service Details:
- - - - + {!isEmpty(Object.keys(newZoneServiceData[0] || {})) && ( + <> +
+ Zone Service Details: +
+
Service Name
+ + + - - - + + + - {reportdata - .filter((obj) => obj.attributeName == "Zone Services") - .map((key) => { - return ( - !isEmpty(key.newValue) && - Object.keys(JSON.parse(key.newValue)).map((c) => { - return ( - - - - + + + {!isEmpty(newZoneServiceData[0][key].resources) ? ( + - - - ); - }) - ); - })} -
Service NameZone Service Resources
Zone Service Resources
- {c} - + {Object.entries(newZoneServiceData[0])?.map(([key]) => { + return ( +
+ {key} + {Object.values( - JSON.parse(key.newValue)[c].resources + newZoneServiceData[0][key].resources ).map((resource) => (
{Object.keys(resource).map((policy) => { @@ -122,13 +158,16 @@ export const SecurityZonelogs = ({ data, reportdata }) => {
))}
+ ) : ( + -- + )} + + + ); + })} + + + )}
)} @@ -136,188 +175,220 @@ export const SecurityZonelogs = ({ data, reportdata }) => { {action == "update" && objectClassType == ClassTypes.CLASS_TYPE_RANGER_SECURITY_ZONE.value && ( -
-
-
-
Name: {objectName}
-
- Date: {dateFormat(createDate, "mm/dd/yyyy hh:MM:ss TT ")} - India Standard Time + <> +
+
+
+
Name: {objectName}
+
+ Date: {dateFormat(createDate, "mm/dd/yyyy hh:MM:ss TT ")} + India Standard Time +
+
Updated By: {owner}
+
+
+
{" Added "} +
{" Deleted "}
-
Updated By: {owner}
-
-
-
{" Added "} -
{" Deleted "}
-
-
- {action == "update" && !isEmpty(updateZoneDetails) && ( - <> -
Zone Details:
+
+ {action == "update" && !isEmpty(updateZoneDetails) && ( + <> +
Zone Details:
- - - - - - - - - {updateZoneDetails.map((obj) => ( - - - +
FieldsOld ValueNew Value
- {obj.attributeName} -
+ + + + + + + + {updateZoneDetails.map((obj) => ( + + + - - - - - ))} -
FieldsOld ValueNew Value
+ {!isEmpty(obj.attributeName) + ? obj.attributeName + : "--"} + - {!isEmpty(obj.previousValue.replace(/[[\]]/g, "")) ? ( - isEmpty(obj.newValue.replace(/[[\]]/g, "")) ? ( -
- - {obj.previousValue.replace(/[[\]]/g, "")} - -
- ) : ( +
+ {!isEmpty( obj.previousValue.replace(/[[\]]/g, "") - ) - ) : ( - "--" - )} - - {!isEmpty(obj.newValue.replace(/[[\]]/g, "")) ? ( - isEmpty(obj.previousValue.replace(/[[\]]/g, "")) ? ( -
- - {obj.newValue.replace(/[[\]]/g, "")} - -
+ ) ? ( + isEmpty(obj.newValue.replace(/[[\]]/g, "")) ? ( +
+ + {obj.previousValue.replace(/[[\]]/g, "")} + +
+ ) : ( + obj.previousValue.replace(/[[\]]/g, "") + ) ) : ( - obj.newValue.replace(/[[\]]/g, "") - ) - ) : ( - "--" - )} -
-
- - )} -
- )} - - {action == "update" && !isEmpty(updateZoneServices) && ( -
-
-
- Old Zone Service Details: -
+ "--" + )} + + + {!isEmpty(obj.newValue.replace(/[[\]]/g, "")) ? ( + isEmpty( + obj.previousValue.replace(/[[\]]/g, "") + ) ? ( +
+ + {obj.newValue.replace(/[[\]]/g, "")} + +
+ ) : ( + obj.newValue.replace(/[[\]]/g, "") + ) + ) : ( + "--" + )} + + + + ))} + +
+ + )} +
+ {(!isEmpty(Object.keys(updateZoneOldServices[0] || {})) || + !isEmpty(Object.keys(updateZoneNewServices[0] || {}))) && ( +
+
+
+ Old Zone Service Details: +
- - - - +
Service Name
+ + + - - - - {updateZoneServices.map((key) => { - return ( - !isEmpty(key.previousValue) && - Object.keys(JSON.parse(key.previousValue)).map((c) => { - return ( + + + + {!isEmpty(Object.keys(updateZoneOldServices[0] || {})) ? ( + Object.entries(updateZoneOldServices[0]).map(([key]) => { + return ( + + + + {!isEmpty( + updateZoneOldServices[0][key].resources + ) ? ( + + ) : ( + + )} + + + ); + }) + ) : ( - - - ); - }) - ); - })} -
Service Name Zone Service Resources
Zone Service Resources
+ {key} + + {Object.values( + updateZoneOldServices[0][key].resources + ).map((resource) => ( +
+ {Object.keys(resource).map((policy) => { + return ( + <> + {`${policy} : `} + {resource[policy].join(", ")} +
+ + ); + })} +
+ ))} +
--
- {c} - - {Object.values( - JSON.parse(key.previousValue)[c].resources - ).map((resource) => ( -
- {Object.keys(resource).map((policy) => { - return ( - <> - {`${policy} : `} - {resource[policy].join(", ")} -
- - ); - })} -
- ))} +
+ --
-
-
-
- New Zone Service Details: -
+ )} + +
+
+
+ New Zone Service Details: +
- - - - +
Service Name
+ + + - - - - {updateZoneServices.map((key) => { - return ( - !isEmpty(key.newValue) && - Object.keys(JSON.parse(key.newValue)).map((c) => { - return ( + + + + {!isEmpty(Object.keys(updateZoneNewServices[0] || {})) ? ( + Object.entries(updateZoneNewServices[0]).map(([key]) => { + return ( + + + + {!isEmpty( + updateZoneNewServices[0][key].resources + ) ? ( + + ) : ( + + )} + + + ); + }) + ) : ( - - - ); - }) - ); - })} -
Service Name Zone Service Resources
Zone Service Resources
+ {key} + + {Object.values( + updateZoneNewServices[0][key].resources + ).map((resource) => ( +
+ {Object.keys(resource).map((policy) => { + return ( + <> + {`${policy} : `} + {resource[policy].join(", ")} +
+ + ); + })} +
+ ))} +
+ -- +
- {c} - - {Object.values( - JSON.parse(key.newValue)[c].resources - ).map((resource) => ( -
- {Object.keys(resource).map((policy) => { - return ( - <> - {`${policy} : `} - {resource[policy].join(", ")} -
- - ); - })} -
- ))} +
+ --
-
-
-
- )} + )} + +
+
+
+ )} + + )} {/* DELETE */} @@ -360,31 +431,31 @@ export const SecurityZonelogs = ({ data, reportdata }) => { })}
-
Zone Service Details:
- - - - + {!isEmpty(Object.keys(oldZoneServiceData[0] || {})) && ( + <> +
+ Zone Service Details: +
+
Service Name
+ + + - - - + + + - {reportdata - .filter((obj) => obj.attributeName == "Zone Services") - .map((key) => { - return ( - !isEmpty(key.previousValue) && - Object.keys(JSON.parse(key.previousValue)).map((c) => { - return ( - - - + {Object.entries(oldZoneServiceData[0]).map(([key]) => { + return ( + + + + {!isEmpty(oldZoneServiceData[0][key].resources) ? ( - - - ); - }) - ); - })} -
Service NameZone Service Resources
Zone Service Resources
- {c} -
+ {key} + {Object.values( - JSON.parse(key.previousValue)[c].resources + oldZoneServiceData[0][key].resources ).map((resource) => (
{Object.keys(resource).map((policy) => { @@ -399,13 +470,16 @@ export const SecurityZonelogs = ({ data, reportdata }) => {
))}
+ ) : ( + -- + )} + + + ); + })} + + + )}
)}
diff --git a/security-admin/src/main/webapp/react-webapp/src/views/AuditEvent/OperationAdminModal.jsx b/security-admin/src/main/webapp/react-webapp/src/views/AuditEvent/OperationAdminModal.jsx index 8e17b4301f..0d30e32247 100644 --- a/security-admin/src/main/webapp/react-webapp/src/views/AuditEvent/OperationAdminModal.jsx +++ b/security-admin/src/main/webapp/react-webapp/src/views/AuditEvent/OperationAdminModal.jsx @@ -43,17 +43,20 @@ export const OperationAdminModal = ({ onHide, show, data = {} }) => { const rowModal = async () => { setLoader(true); + let authlogs = []; + try { const authResp = await fetchApi({ url: `assets/report/${transactionId}` }); - let authlogs = authResp.data.vXTrxLogs; - setShowview(objectId); - setReportData(authlogs); - setLoader(false); + authlogs = authResp?.data?.vXTrxLogs || []; } catch (error) { console.error(`Error occurred while fetching Admin logs! ${error}`); } + + setShowview(objectId); + setReportData(authlogs); + setLoader(false); }; return ( diff --git a/security-admin/src/main/webapp/react-webapp/src/views/SecurityZone/SecurityZoneForm.jsx b/security-admin/src/main/webapp/react-webapp/src/views/SecurityZone/SecurityZoneForm.jsx index fc56b661c3..3bf0df71cc 100644 --- a/security-admin/src/main/webapp/react-webapp/src/views/SecurityZone/SecurityZoneForm.jsx +++ b/security-admin/src/main/webapp/react-webapp/src/views/SecurityZone/SecurityZoneForm.jsx @@ -124,14 +124,6 @@ const SecurityZoneForm = () => { text: "" }; } - - if (isEmpty(values.resourceServices)) { - errors.resourceServices = { - required: true, - text: "Required" - }; - } - return errors; }; @@ -325,33 +317,29 @@ const SecurityZoneForm = () => { } zoneData.services = {}; - - for (let key of Object.keys(values.tableList)) { - let serviceName = values.tableList[key].serviceName; - let resourcesName = values.tableList[key].resources; - zoneData.services[serviceName] = {}; - zoneData.services[serviceName].resources = []; - resourcesName.map((obj) => { - let serviceResourceData = {}; - pickBy(obj, (key, val) => { - if ( - obj[`value-${key.level}`] && - obj[`value-${key.level}`].length > 0 - ) { - if (val.includes("resourceName")) { - serviceResourceData[key.name] = obj[`value-${key.level}`].map( - (value) => value.value - ); + if (!isEmpty(Object.keys(values.tableList || {}))) { + for (let key of Object.keys(values.tableList)) { + let serviceName = values.tableList[key].serviceName; + let resourcesName = values.tableList[key].resources; + zoneData.services[serviceName] = {}; + zoneData.services[serviceName].resources = []; + resourcesName.map((obj) => { + let serviceResourceData = {}; + pickBy(obj, (key, val) => { + if ( + obj[`value-${key.level}`] && + obj[`value-${key.level}`].length > 0 + ) { + if (val.includes("resourceName")) { + serviceResourceData[key.name] = obj[`value-${key.level}`].map( + (value) => value.value + ); + } } - } - }); - return zoneData.services[serviceName].resources.push( - serviceResourceData - ); - }); - if (zoneData.services[serviceName].resources.length === 0) { - toast.error("Please add at least one resource for service", { - toastId: "error1" + }); + return zoneData.services[serviceName].resources.push( + serviceResourceData + ); }); } } @@ -431,7 +419,7 @@ const SecurityZoneForm = () => { } zoneData.tableList = []; - for (let name of Object.keys(zone.services)) { + for (let name of Object.keys(zone.services || {})) { let tableValues = {}; tableValues["serviceName"] = name; @@ -450,33 +438,36 @@ const SecurityZoneForm = () => { } tableValues["resources"] = []; - zone.services[name].resources.map((obj) => { - let serviceResource = {}; - let lastResourceLevel = []; - Object.entries(obj).map(([key, value]) => { - let setResources = find(filterServiceDef.resources, ["name", key]); - serviceResource[`resourceName-${setResources.level}`] = setResources; - serviceResource[`value-${setResources.level}`] = value.map((m) => { - return { label: m, value: m }; - }); - lastResourceLevel.push({ - level: setResources.level, - name: setResources.name + if (!isEmpty(zone.services[name].resources)) { + zone.services[name].resources?.map((obj) => { + let serviceResource = {}; + let lastResourceLevel = []; + Object.entries(obj).map(([key, value]) => { + let setResources = find(filterServiceDef.resources, ["name", key]); + serviceResource[`resourceName-${setResources.level}`] = + setResources; + serviceResource[`value-${setResources.level}`] = value.map((m) => { + return { label: m, value: m }; + }); + lastResourceLevel.push({ + level: setResources.level, + name: setResources.name + }); }); + lastResourceLevel = maxBy(lastResourceLevel, "level"); + let setLastResources = find( + sortBy(filterServiceDef.resources, "itemId"), + ["parent", lastResourceLevel.name] + ); + if (setLastResources && setLastResources?.isValidLeaf) { + serviceResource[`resourceName-${setLastResources.level}`] = { + label: "None", + value: "none" + }; + } + tableValues["resources"].push(serviceResource); }); - lastResourceLevel = maxBy(lastResourceLevel, "level"); - let setLastResources = find( - sortBy(filterServiceDef.resources, "itemId"), - ["parent", lastResourceLevel.name] - ); - if (setLastResources && setLastResources?.isValidLeaf) { - serviceResource[`resourceName-${setLastResources.level}`] = { - label: "None", - value: "none" - }; - } - tableValues["resources"].push(serviceResource); - }); + } zoneData.tableList.push(tableValues); } @@ -930,22 +921,16 @@ const SecurityZoneForm = () => { /> ( + render={({ input }) => (