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

Closes #1407

* commit 'df487cbc07945354242827fdefdb6b90e6c92635':
  * client: fix wrong data type for client tags
  - client: fix wrong statuses for Safebrowsing, Parental control, Safe search
This commit is contained in:
Ildar Kamalov 2020-02-13 18:15:32 +03:00
commit 867bf5457f
5 changed files with 64 additions and 26 deletions

View File

@ -2,7 +2,17 @@ import React, { Fragment } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { withNamespaces } from 'react-i18next'; 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) => { const getFilterName = (id, filters, t) => {
if (id === 0) { if (id === 0) {
@ -18,7 +28,7 @@ const getFilterName = (id, filters, t) => {
return ''; return '';
}; };
const getTitle = (reason, filterName, t) => { const getTitle = (reason, filterName, t, onlyFiltered) => {
if (checkNotFilteredNotFound(reason)) { if (checkNotFilteredNotFound(reason)) {
return t('check_not_found'); 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 ( return (
<Fragment> <Fragment>
<div> <div>
@ -80,9 +100,24 @@ const Info = ({
t, t,
}) => { }) => {
const filterName = getFilterName(filter_id, filters, 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); 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 ( return (
<div className={`card mb-0 p-3 ${color}`}> <div className={`card mb-0 p-3 ${color}`}>
<div> <div>

View File

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

View File

@ -36,6 +36,8 @@ class ClientsTable extends Component {
if (values.tags) { if (values.tags) {
config.tags = values.tags.map(tag => tag.value); config.tags = values.tags.map(tag => tag.value);
} else {
config.tags = [];
} }
} }

View File

@ -241,6 +241,9 @@ export const FILTERED_STATUS = {
NOT_FILTERED_NOT_FOUND: 'NotFilteredNotFound', NOT_FILTERED_NOT_FOUND: 'NotFilteredNotFound',
FILTERED_BLOCKED_SERVICE: 'FilteredBlockedService', FILTERED_BLOCKED_SERVICE: 'FilteredBlockedService',
REWRITE: 'Rewrite', REWRITE: 'Rewrite',
FILTERED_SAFE_SEARCH: 'FilteredSafeSearch',
FILTERED_SAFE_BROWSING: 'FilteredSafeBrowsing',
FILTERED_PARENTAL: 'FilteredParental',
}; };
export const FILTERED = 'Filtered'; 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 checkBlackList = reason => reason === FILTERED_STATUS.FILTERED_BLACK_LIST;
export const checkWhiteList = reason => reason === FILTERED_STATUS.NOT_FILTERED_WHITE_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 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;