- client: fix wrong statuses for Safebrowsing, Parental control, Safe search

This commit is contained in:
Ildar Kamalov 2020-02-13 11:57:49 +03:00
parent c5ca2a779c
commit 61d8ec8dae
4 changed files with 62 additions and 26 deletions

View File

@ -2,7 +2,17 @@ import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import { withNamespaces } from 'react-i18next';
import { checkFiltered, checkRewrite, checkBlackList, checkNotFilteredNotFound, checkWhiteList } from '../../../helpers/helpers';
import {
checkFiltered,
checkRewrite,
checkBlackList,
checkNotFilteredNotFound,
checkWhiteList,
checkSafeSearch,
checkSafeBrowsing,
checkParental,
} from '../../../helpers/helpers';
import { FILTERED } from '../../../helpers/constants';
const getFilterName = (id, filters, t) => {
if (id === 0) {
@ -18,7 +28,7 @@ const getFilterName = (id, filters, t) => {
return '';
};
const getTitle = (reason, filterName, t) => {
const getTitle = (reason, filterName, t, onlyFiltered) => {
if (checkNotFilteredNotFound(reason)) {
return t('check_not_found');
}
@ -44,6 +54,16 @@ const getTitle = (reason, filterName, t) => {
);
}
if (onlyFiltered) {
const filterKey = reason.replace(FILTERED, '');
return (
<div>
{t('query_log_filtered', { filter: filterKey })}
</div>
);
}
return (
<Fragment>
<div>
@ -80,9 +100,24 @@ const Info = ({
t,
}) => {
const filterName = getFilterName(filter_id, filters, t);
const title = getTitle(reason, filterName, t);
const onlyFiltered = checkSafeSearch(reason)
|| checkSafeBrowsing(reason)
|| checkParental(reason);
const title = getTitle(reason, filterName, t, onlyFiltered);
const color = getColor(reason);
if (onlyFiltered) {
return (
<div className={`card mb-0 p-3 ${color}`}>
<div>
<strong>{hostname}</strong>
</div>
<div>{title}</div>
</div>
);
}
return (
<div className={`card mb-0 p-3 ${color}`}>
<div>

View File

@ -10,8 +10,13 @@ import {
formatTime,
formatDateTime,
isToday,
checkFiltered,
checkRewrite,
checkWhiteList,
checkBlackList,
checkBlockedService,
} from '../../helpers/helpers';
import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE, CUSTOM_FILTERING_RULES_ID } from '../../helpers/constants';
import { SERVICES, TABLE_DEFAULT_PAGE_SIZE, CUSTOM_FILTERING_RULES_ID, FILTERED } from '../../helpers/constants';
import { getTrackerData } from '../../helpers/trackers/trackers';
import { formatClientCell } from '../../helpers/formatClientCell';
@ -27,7 +32,6 @@ import CellWrap from '../ui/CellWrap';
const TABLE_FIRST_PAGE = 0;
const INITIAL_REQUEST = true;
const INITIAL_REQUEST_DATA = ['', TABLE_FIRST_PAGE, INITIAL_REQUEST];
const FILTERED_REASON = 'Filtered';
class Logs extends Component {
componentDidMount() {
@ -111,16 +115,6 @@ class Logs extends Component {
);
}
checkFiltered = reason => reason.indexOf(FILTERED_REASON) === 0;
checkRewrite = reason => reason === FILTERED_STATUS.REWRITE;
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,
(isToday(row.value) ? formatTime : formatDateTime),
@ -172,14 +166,14 @@ class Logs extends Component {
const { t, filtering } = this.props;
const { filters } = filtering;
const isFiltered = this.checkFiltered(reason);
const isBlackList = this.checkBlackList(reason);
const isRewrite = this.checkRewrite(reason);
const isWhiteList = this.checkWhiteList(reason);
const isBlockedService = this.checkBlockedService(reason);
const isFiltered = checkFiltered(reason);
const isBlackList = checkBlackList(reason);
const isRewrite = checkRewrite(reason);
const isWhiteList = checkWhiteList(reason);
const isBlockedService = checkBlockedService(reason);
const isBlockedCnameIp = originalAnswer;
const filterKey = reason.replace(FILTERED_REASON, '');
const filterKey = reason.replace(FILTERED, '');
const parsedFilteredReason = t('query_log_filtered', { filter: filterKey });
const currentService = SERVICES.find(service => service.id === original.serviceName);
const serviceName = currentService && currentService.name;
@ -238,8 +232,8 @@ class Logs extends Component {
const { original } = row;
const { t } = this.props;
const { reason, domain } = original;
const isFiltered = this.checkFiltered(reason);
const isRewrite = this.checkRewrite(reason);
const isFiltered = checkFiltered(reason);
const isRewrite = checkRewrite(reason);
return (
<Fragment>
@ -360,15 +354,15 @@ class Logs extends Component {
const { reason } = rowInfo.original;
if (this.checkFiltered(reason)) {
if (checkFiltered(reason)) {
return {
className: 'red',
};
} else if (this.checkWhiteList(reason)) {
} else if (checkWhiteList(reason)) {
return {
className: 'green',
};
} else if (this.checkRewrite(reason)) {
} else if (checkRewrite(reason)) {
return {
className: 'blue',
};

View File

@ -241,6 +241,9 @@ export const FILTERED_STATUS = {
NOT_FILTERED_NOT_FOUND: 'NotFilteredNotFound',
FILTERED_BLOCKED_SERVICE: 'FilteredBlockedService',
REWRITE: 'Rewrite',
FILTERED_SAFE_SEARCH: 'FilteredSafeSearch',
FILTERED_SAFE_BROWSING: 'FilteredSafeBrowsing',
FILTERED_PARENTAL: 'FilteredParental',
};
export const FILTERED = 'Filtered';

View File

@ -432,3 +432,7 @@ export const checkRewrite = reason => reason === FILTERED_STATUS.REWRITE;
export const checkBlackList = reason => reason === FILTERED_STATUS.FILTERED_BLACK_LIST;
export const checkWhiteList = reason => reason === FILTERED_STATUS.NOT_FILTERED_WHITE_LIST;
export const checkNotFilteredNotFound = reason => reason === FILTERED_STATUS.NOT_FILTERED_NOT_FOUND;
export const checkSafeSearch = reason => reason === FILTERED_STATUS.FILTERED_SAFE_SEARCH;
export const checkSafeBrowsing = reason => reason === FILTERED_STATUS.FILTERED_SAFE_BROWSING;
export const checkParental = reason => reason === FILTERED_STATUS.FILTERED_PARENTAL;
export const checkBlockedService = reason => reason === FILTERED_STATUS.FILTERED_BLOCKED_SERVICE;