From 3ecbde1390aa7784e0aa60dbaa3c66b744bfa7f1 Mon Sep 17 00:00:00 2001 From: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com> Date: Tue, 23 Aug 2022 14:02:55 -0400 Subject: [PATCH] Feature/cldn 1541 (#200) * [CLDN-1541] Added the ability to filter on multiple user ID's and IP's at the same time in the Application Links custom viz * Temp update to image for deploying to PB-stg * Reverting change to image * [CLDN-1541] Added a tooltip to the Alfred icon * Temp update to base image * Reverting temporary change to image tag * Update superset-frontend/src/cccs-viz/plugins/plugin-chart-application-links/src/ApplicationLinks.tsx Co-authored-by: cccs-rc <62034438+cccs-rc@users.noreply.github.com> * Update superset-frontend/src/cccs-viz/plugins/plugin-chart-application-links/src/ApplicationLinks.tsx Co-authored-by: cccs-rc <62034438+cccs-rc@users.noreply.github.com> * [CLDN-1541] Changed the logic around creating the proper links/URL * Temp update to img * Undo temp img change Co-authored-by: cccs-rc <62034438+cccs-rc@users.noreply.github.com> --- .../src/ApplicationLinks.tsx | 33 +++++++++++++++---- .../src/plugin/transformProps.ts | 4 +-- .../src/types.ts | 2 +- superset/proxy/api.py | 24 +++++++++++--- 4 files changed, 50 insertions(+), 13 deletions(-) diff --git a/superset-frontend/src/cccs-viz/plugins/plugin-chart-application-links/src/ApplicationLinks.tsx b/superset-frontend/src/cccs-viz/plugins/plugin-chart-application-links/src/ApplicationLinks.tsx index d68f7999ef8ae..9c22627aeeb08 100644 --- a/superset-frontend/src/cccs-viz/plugins/plugin-chart-application-links/src/ApplicationLinks.tsx +++ b/superset-frontend/src/cccs-viz/plugins/plugin-chart-application-links/src/ApplicationLinks.tsx @@ -20,6 +20,17 @@ export default function ApplicationLinks(props: ApplicationsProps) { } } + const link_formatter = () => { + let tempString = ''; + if (appVal.length > 0) { + tempString = appVal[0]; + for (let i = 1; i < appVal.length; i += 1) { + tempString += `%22%2C%20%22${appVal[i]}`; + } + } + return tempString; + }; + useEffect(() => { fetch( // eslint-disable-next-line no-restricted-globals @@ -36,11 +47,15 @@ export default function ApplicationLinks(props: ApplicationsProps) { if (appType === 'USER_ID') { setAlfredURL( - `${response.payload?.url}/?expression=MATCH%20(email%3AEMAIL_ADDRESS)%20WHERE%20email.value%20IN%20%5B%22${appVal}%22%5D%20RETURN%20email.value%2C%20email.maliciousness%2C%20email.uri`, + `${ + response.payload?.url + }/?expression=MATCH%20(email%3AEMAIL_ADDRESS)%20WHERE%20email.value%20IN%20%5B%22${link_formatter()}%22%5D%20RETURN%20email.value%2C%20email.maliciousness%2C%20email.uri`, ); } else if (appType === 'IP') { setAlfredURL( - `${response.payload?.url}/?expression=MATCH%20(ip%3AIP_ADDRESS)%20WHERE%20ip.value%20IN%20%5B%22${appVal}%22%5D%20RETURN%20ip.value%2C%20ip.maliciousness%2C%20ip.creation_date%2C%20ip.created_by%2C%20ip.uri%2C%20ip.report_uri`, + `${ + response.payload?.url + }/?expression=MATCH%20(ip%3AIP_ADDRESS)%20WHERE%20ip.value%20IN%20%5B%22${link_formatter()}%22%5D%20RETURN%20ip.value%2C%20ip.maliciousness%2C%20ip.creation_date%2C%20ip.created_by%2C%20ip.uri%2C%20ip.report_uri`, ); } else { setAlfredURL(`${response.payload?.url}`); @@ -59,13 +74,14 @@ export default function ApplicationLinks(props: ApplicationsProps) { return (
@@ -84,13 +100,16 @@ export default function ApplicationLinks(props: ApplicationsProps) { height="17" width="30" alt="Alfred" + title="Alfred" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADMAAAAjCAYAAAA5dzKxAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAhdEVYdENyZWF0aW9uIFRpbWUAMjAyMToxMDoyMCAxMDo1NjoxODj1iuIAAAdVSURBVFhH7Vh7TJRXFv/Ni5nhVRRQTHShBevSkq6P1FK3dtWiQHazW7O+TRDsuq6Jf7T9Q7ubzSZtdvuHpmnTFbWgriuJumtX3EajbVFKpUCk1NRHqFbkFVTkrcMM8/z2nMPc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g0ulGLTso97cqVKyIPR/e4CgCXUFpUkpZLK7eJqL83fJDBsFgsKCgoEJ1cVPbs2SN9/B4ymFEoUB5qa2uThGcPUknV+vr6RP4gULr5Pzj04Sa6+X9td+7cEXmoCDky7D1GWVkZBukzgOZi+fLl8kWp+sYLFeW0tDS5RXD71q1bKC8vl/5Q9Yd8N/t/wLhy5vsJ4H+26s1scE22tgAAAABJRU5ErkJggg==" /> {alfredCount > 0 ? (
- Alfred has seen this {infoType} {alfredCount} time(s). Search - the{' '} + Alfred has seen {appVal.length > 1 ? 'these' : 'this'}{' '} + {infoType} + {appVal.length > 1 ? "s" : ''} {alfredCount} time + {alfredCount > 1 ? 's' : ''}. Search the{' '} Alfred {' '} @@ -98,7 +117,9 @@ export default function ApplicationLinks(props: ApplicationsProps) {
) : (- Alfred has not seen this {infoType}. Search the{' '} + Alfred has not seen {appVal.length > 1 ? 'these' : 'this'}{' '} + {infoType} + {appVal.length > 1 ? "s" : ''}. Search the{' '} Alfred {' '} diff --git a/superset-frontend/src/cccs-viz/plugins/plugin-chart-application-links/src/plugin/transformProps.ts b/superset-frontend/src/cccs-viz/plugins/plugin-chart-application-links/src/plugin/transformProps.ts index a7945ec2c2729..3c5a002bca65c 100644 --- a/superset-frontend/src/cccs-viz/plugins/plugin-chart-application-links/src/plugin/transformProps.ts +++ b/superset-frontend/src/cccs-viz/plugins/plugin-chart-application-links/src/plugin/transformProps.ts @@ -60,11 +60,11 @@ export default function transformProps(chartProps: ChartProps) { const filter = formData.extraFormData.filters[0]; if (filter.col === 'ip_string') { appType = 'IP'; - appVal = filter.val[0]; + appVal = filter.val; break; } else if (filter.col === 'user_id') { appType = 'USER_ID'; - appVal = filter.val[0]; + appVal = filter.val; break; } } diff --git a/superset-frontend/src/cccs-viz/plugins/plugin-chart-application-links/src/types.ts b/superset-frontend/src/cccs-viz/plugins/plugin-chart-application-links/src/types.ts index 95b8bd3704bae..62373de9d55e6 100644 --- a/superset-frontend/src/cccs-viz/plugins/plugin-chart-application-links/src/types.ts +++ b/superset-frontend/src/cccs-viz/plugins/plugin-chart-application-links/src/types.ts @@ -3,6 +3,6 @@ import { QueryFormData, TimeseriesDataRecord } from '@superset-ui/core'; export type ApplicationsProps = QueryFormData & { data: TimeseriesDataRecord[]; application: string; - appVal: string; + appVal: string[]; appType: string; }; diff --git a/superset/proxy/api.py b/superset/proxy/api.py index a1d1314a124c4..c64b29f4a95e0 100644 --- a/superset/proxy/api.py +++ b/superset/proxy/api.py @@ -158,14 +158,22 @@ def get_userid(self, user_id: str, **_kwargs: Any) -> Response: current logged in user, and will then send a request to Alfred to see if the passed in user_id is in any reports/incidents - :param user_id: String value representing the user id passed in from the front-end + :param user_id: String value representing the user id(s) passed in from the front-end :param _kwargs: Array representing any other arguments passed to the function :returns: Response generated from passing values to the make_alfred_connection function """ + user_emails = user_id.split(",") + user_email_string = '' + + if len(user_emails) > 0: + user_email_string = user_emails[0] + for index in range(1, len(user_emails)): + user_email_string += "%22%2C%20%22" + user_emails[index] + url = ( self.ALFRED_URL + "/rest/search/cypher?expression=MATCH%20(email%3AEMAIL_ADDRESS)%20WHERE%20email.value%20IN%20%5B%22" - + user_id + + user_email_string + "%22%5D%20RETURN%20email.value%2C%20email.maliciousness%2C%20email.uri" ) @@ -182,14 +190,22 @@ def get_ipstring(self, ip_string: str, **_kwargs: Any) -> Response: current logged in user, and will then send a request to Alfred to see if the passed in ip_string is in any reports/incidents - :param ip_string: String value representing the ip passed in from the front-end + :param ip_string: String value representing the ip(s) passed in from the front-end :param _kwargs: Array representing any other arguments passed to the function :returns: Response generated from passing values to the make_alfred_connection function """ + user_ips = ip_string.split(",") + user_ip_string = '' + + if len(user_ips) > 0: + user_ip_string = user_ips[0] + for index in range(1, len(user_ips)): + user_ip_string += "%22%2C%20%22" + user_ips[index] + url = ( self.ALFRED_URL + "/rest/search/cypher?expression=MATCH%20(ip%3AIP_ADDRESS)%20WHERE%20ip.value%20IN%20%5B%22" - + ip_string + + user_ip_string + "%22%5D%20RETURN%20ip.value%2C%20ip.maliciousness%2C%20ip.creation_date%2C%20ip.created_by%2C%20ip.uri%2C%20ip.report_uri" )