From 5e9c21b0a7917d0b89fe25cbf8b5790029ea2ac6 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Wed, 29 Jan 2020 15:00:37 +0300 Subject: [PATCH] Merge: + client: show filter name for blocked items in the query log Closes #993 Squashed commit of the following: commit 4c5e17226c6efa8a7847a8c565c491a7bae2db59 Author: Ildar Kamalov Date: Wed Jan 29 12:21:40 2020 +0300 - client: use constant commit 818c07d1cfb210965a6413dc8370fc8867979c7b Author: Ildar Kamalov Date: Wed Jan 29 12:18:31 2020 +0300 - client: fix filter find commit 1f9132151c843dacbf26f814faeeea3cfdff9b73 Author: Ildar Kamalov Date: Tue Jan 28 15:52:29 2020 +0300 + client: show filter name for blocked items in the query log --- client/src/components/Logs/index.js | 80 +++++++++++++++++++---------- client/src/helpers/constants.js | 2 + 2 files changed, 55 insertions(+), 27 deletions(-) diff --git a/client/src/components/Logs/index.js b/client/src/components/Logs/index.js index c511edc7..1281db28 100644 --- a/client/src/components/Logs/index.js +++ b/client/src/components/Logs/index.js @@ -11,7 +11,7 @@ import { formatDateTime, isToday, } from '../../helpers/helpers'; -import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE } from '../../helpers/constants'; +import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE, CUSTOM_FILTERING_RULES_ID } from '../../helpers/constants'; import { getTrackerData } from '../../helpers/trackers/trackers'; import { formatClientCell } from '../../helpers/formatClientCell'; @@ -116,6 +116,9 @@ class Logs extends Component { checkWhiteList = reason => reason === FILTERED_STATUS.NOT_FILTERED_WHITE_LIST; + checkBlackList = reason => reason === FILTERED_STATUS.FILTERED_BLACK_LIST; + + checkBlockedService = reason => reason === FILTERED_STATUS.FILTERED_BLOCKED_SERVICE; getDateCell = row => CellWrap( row, @@ -142,6 +145,25 @@ class Logs extends Component { }) ); + getFilterName = (filters, filterId, t) => { + if (filterId === CUSTOM_FILTERING_RULES_ID) { + return t('custom_filter_rules'); + } + + const filter = filters.find(filter => filter.id === filterId); + let filterName = ''; + + if (filter) { + filterName = filter.name; + } + + if (!filterName) { + filterName = t('unknown_filter', { filterId }); + } + + return filterName; + } + getResponseCell = ({ value: responses, original }) => { const { reason, filterId, rule, status, originalAnswer, @@ -150,43 +172,50 @@ class Logs extends Component { const { filters } = filtering; const isFiltered = this.checkFiltered(reason); - const filterKey = reason.replace(FILTERED_REASON, ''); - const parsedFilteredReason = t('query_log_filtered', { filter: filterKey }); + const isBlackList = this.checkBlackList(reason); const isRewrite = this.checkRewrite(reason); const isWhiteList = this.checkWhiteList(reason); - const isBlockedService = reason === FILTERED_STATUS.FILTERED_BLOCKED_SERVICE; + const isBlockedService = this.checkBlockedService(reason); + const isBlockedCnameIp = originalAnswer; + + const filterKey = reason.replace(FILTERED_REASON, ''); + const parsedFilteredReason = t('query_log_filtered', { filter: filterKey }); const currentService = SERVICES.find(service => service.id === original.serviceName); const serviceName = currentService && currentService.name; - const normalizedAnswer = originalAnswer && this.normalizeResponse(originalAnswer); - let filterName = ''; + const filterName = this.getFilterName(filters, filterId, t); - if (filterId === 0) { - filterName = t('custom_filter_rules'); - } else { - const filterItem = Object.keys(filters).filter(key => filters[key].id === filterId)[0]; + if (isBlockedCnameIp) { + const normalizedAnswer = this.normalizeResponse(originalAnswer); - if (typeof filterItem !== 'undefined' && typeof filters[filterItem] !== 'undefined') { - filterName = filters[filterItem].name; - } - - if (!filterName) { - filterName = t('unknown_filter', { filterId }); - } + return ( +
+
+ + blocked_by_response + +
+
+ {this.renderResponseList(normalizedAnswer, status)} +
+
+ ); } return (
- {originalAnswer && ( - - blocked_by_response - - )} - {!originalAnswer && (isFiltered || isBlockedService) && ( + {(isFiltered || isBlockedService) && !isBlackList && ( {parsedFilteredReason} )} + {isBlackList && ( + + + query_log_filtered + + + )} {isBlockedService ? this.renderTooltip(isFiltered, '', '', serviceName) : this.renderTooltip(isFiltered, rule, filterName)} @@ -197,10 +226,7 @@ class Logs extends Component { )}
- {originalAnswer - ? this.renderResponseList(normalizedAnswer, status) - : this.renderResponseList(responses, status) - } + {this.renderResponseList(responses, status)} {isWhiteList && this.renderTooltip(isWhiteList, rule, filterName)}
diff --git a/client/src/helpers/constants.js b/client/src/helpers/constants.js index 218d8e43..65f8cc5d 100644 --- a/client/src/helpers/constants.js +++ b/client/src/helpers/constants.js @@ -450,3 +450,5 @@ export const DETAILED_DATE_FORMAT_OPTIONS = { ...DEFAULT_DATE_FORMAT_OPTIONS, month: 'long', }; + +export const CUSTOM_FILTERING_RULES_ID = 0;