Skip to content

Commit

Permalink
Merge branch 'master' into 951-blocked-services-client-schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
schzhn committed Jun 27, 2023
2 parents cfa24ff + e7e6384 commit b4022c3
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 30 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Expand Up @@ -31,7 +31,7 @@ NOTE: Add new changes BELOW THIS COMMENT.
globally and per client, in the configuration file ([#951]). The UI changes
are coming in the upcoming releases.
- The ability to edit rewrite rules via `PUT /control/rewrite/update` HTTP API
([#1577]).
and the Web UI ([#1577]).

### Changed

Expand Down Expand Up @@ -90,7 +90,7 @@ In this release, the schema version has changed from 20 to 21.

### Fixed

- Cannot set `bind_host` in AdGuardHome.yaml (docker version) ([#4231]).
- Cannot set `bind_host` in AdGuardHome.yaml (docker version)([#4231], [#4235]).
- The blocklists can now be deleted properly ([#5700]).
- Queries with the question-section target `.`, for example `NS .`, are now
counted in the statistics and correctly shown in the query log ([#5910]).
Expand All @@ -100,6 +100,7 @@ In this release, the schema version has changed from 20 to 21.
[#951]: https://github.com/AdguardTeam/AdGuardHome/issues/951
[#1577]: https://github.com/AdguardTeam/AdGuardHome/issues/1577
[#4231]: https://github.com/AdguardTeam/AdGuardHome/issues/4231
[#4235]: https://github.com/AdguardTeam/AdGuardHome/pull/4235
[#5700]: https://github.com/AdguardTeam/AdGuardHome/issues/5700
[#5910]: https://github.com/AdguardTeam/AdGuardHome/issues/5910
[#5913]: https://github.com/AdguardTeam/AdGuardHome/issues/5913
Expand Down
2 changes: 2 additions & 0 deletions client/src/__locales/en.json
Expand Up @@ -478,7 +478,9 @@
"setup_dns_notice": "In order to use <1>DNS-over-HTTPS</1> or <1>DNS-over-TLS</1>, you need to <0>configure Encryption</0> in AdGuard Home settings.",
"rewrite_added": "DNS rewrite for \"{{key}}\" successfully added",
"rewrite_deleted": "DNS rewrite for \"{{key}}\" successfully deleted",
"rewrite_updated": "DNS rewrite successfully updated",
"rewrite_add": "Add DNS rewrite",
"rewrite_edit": "Edit DNS rewrite",
"rewrite_not_found": "No DNS rewrites found",
"rewrite_confirm_delete": "Are you sure you want to delete DNS rewrite for \"{{key}}\"?",
"rewrite_desc": "Allows to easily configure custom DNS response for a specific domain name.",
Expand Down
23 changes: 23 additions & 0 deletions client/src/actions/rewrites.js
Expand Up @@ -38,6 +38,29 @@ export const addRewrite = (config) => async (dispatch) => {
}
};

export const updateRewriteRequest = createAction('UPDATE_REWRITE_REQUEST');
export const updateRewriteFailure = createAction('UPDATE_REWRITE_FAILURE');
export const updateRewriteSuccess = createAction('UPDATE_REWRITE_SUCCESS');

/**
* @param {Object} config
* @param {string} config.target - current DNS rewrite value
* @param {string} config.update - updated DNS rewrite value
*/
export const updateRewrite = (config) => async (dispatch) => {
dispatch(updateRewriteRequest());
try {
await apiClient.updateRewrite(config);
dispatch(updateRewriteSuccess());
dispatch(toggleRewritesModal());
dispatch(getRewritesList());
dispatch(addSuccessToast(i18next.t('rewrite_updated', { key: config.domain })));
} catch (error) {
dispatch(addErrorToast({ error }));
dispatch(updateRewriteFailure());
}
};

export const deleteRewriteRequest = createAction('DELETE_REWRITE_REQUEST');
export const deleteRewriteFailure = createAction('DELETE_REWRITE_FAILURE');
export const deleteRewriteSuccess = createAction('DELETE_REWRITE_SUCCESS');
Expand Down
10 changes: 10 additions & 0 deletions client/src/api/Api.js
Expand Up @@ -455,6 +455,8 @@ class Api {

REWRITE_ADD = { path: 'rewrite/add', method: 'POST' };

REWRITE_UPDATE = { path: 'rewrite/update', method: 'PUT' };

REWRITE_DELETE = { path: 'rewrite/delete', method: 'POST' };

getRewritesList() {
Expand All @@ -470,6 +472,14 @@ class Api {
return this.makeRequest(path, method, parameters);
}

updateRewrite(config) {
const { path, method } = this.REWRITE_UPDATE;
const parameters = {
data: config,
};
return this.makeRequest(path, method, parameters);
}

deleteRewrite(config) {
const { path, method } = this.REWRITE_DELETE;
const parameters = {
Expand Down
1 change: 1 addition & 0 deletions client/src/components/Filters/Rewrites/Form.js
Expand Up @@ -105,6 +105,7 @@ Form.propTypes = {
submitting: PropTypes.bool.isRequired,
processingAdd: PropTypes.bool.isRequired,
t: PropTypes.func.isRequired,
initialValues: PropTypes.object,
};

export default flow([
Expand Down
12 changes: 11 additions & 1 deletion client/src/components/Filters/Rewrites/Modal.js
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import { Trans, withTranslation } from 'react-i18next';
import ReactModal from 'react-modal';

import { MODAL_TYPE } from '../../../helpers/constants';
import Form from './Form';

const Modal = (props) => {
Expand All @@ -12,6 +13,8 @@ const Modal = (props) => {
toggleRewritesModal,
processingAdd,
processingDelete,
modalType,
currentRewrite,
} = props;

return (
Expand All @@ -24,13 +27,18 @@ const Modal = (props) => {
<div className="modal-content">
<div className="modal-header">
<h4 className="modal-title">
<Trans>rewrite_add</Trans>
{modalType === MODAL_TYPE.EDIT_REWRITE ? (
<Trans>rewrite_edit</Trans>
) : (
<Trans>rewrite_add</Trans>
)}
</h4>
<button type="button" className="close" onClick={() => toggleRewritesModal()}>
<span className="sr-only">Close</span>
</button>
</div>
<Form
initialValues={{ ...currentRewrite }}
onSubmit={handleSubmit}
toggleRewritesModal={toggleRewritesModal}
processingAdd={processingAdd}
Expand All @@ -47,6 +55,8 @@ Modal.propTypes = {
toggleRewritesModal: PropTypes.func.isRequired,
processingAdd: PropTypes.bool.isRequired,
processingDelete: PropTypes.bool.isRequired,
modalType: PropTypes.string.isRequired,
currentRewrite: PropTypes.object,
};

export default withTranslation()(Modal);
59 changes: 41 additions & 18 deletions client/src/components/Filters/Rewrites/Table.js
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import ReactTable from 'react-table';
import { withTranslation } from 'react-i18next';
import { sortIp } from '../../../helpers/helpers';
import { MODAL_TYPE } from '../../../helpers/constants';

class Table extends Component {
cellWrap = ({ value }) => (
Expand Down Expand Up @@ -31,24 +32,44 @@ class Table extends Component {
maxWidth: 100,
sortable: false,
resizable: false,
Cell: (value) => (
<div className="logs__row logs__row--center">
<button
type="button"
className="btn btn-icon btn-icon--green btn-outline-secondary btn-sm"
onClick={() => this.props.handleDelete({
answer: value.row.answer,
domain: value.row.domain,
})
}
title={this.props.t('delete_table_action')}
>
<svg className="icons">
<use xlinkHref="#delete" />
</svg>
</button>
</div>
),
Cell: (value) => {
const currentRewrite = {
answer: value.row.answer,
domain: value.row.domain,
};

return (
<div className="logs__row logs__row--center">
<button
type="button"
className="btn btn-icon btn-outline-primary btn-sm mr-2"
onClick={() => {
this.props.toggleRewritesModal({
type: MODAL_TYPE.EDIT_REWRITE,
currentRewrite,
});
}}
disabled={this.props.processingUpdate}
title={this.props.t('edit_table_action')}
>
<svg className="icons icon12">
<use xlinkHref="#edit" />
</svg>
</button>

<button
type="button"
className="btn btn-icon btn-outline-secondary btn-sm"
onClick={() => this.props.handleDelete(currentRewrite)}
title={this.props.t('delete_table_action')}
>
<svg className="icons">
<use xlinkHref="#delete" />
</svg>
</button>
</div>
);
},
},
];

Expand Down Expand Up @@ -84,7 +105,9 @@ Table.propTypes = {
processing: PropTypes.bool.isRequired,
processingAdd: PropTypes.bool.isRequired,
processingDelete: PropTypes.bool.isRequired,
processingUpdate: PropTypes.bool.isRequired,
handleDelete: PropTypes.func.isRequired,
toggleRewritesModal: PropTypes.func.isRequired,
};

export default withTranslation()(Table);
29 changes: 24 additions & 5 deletions client/src/components/Filters/Rewrites/index.js
Expand Up @@ -6,23 +6,33 @@ import Table from './Table';
import Modal from './Modal';
import Card from '../../ui/Card';
import PageTitle from '../../ui/PageTitle';
import { MODAL_TYPE } from '../../../helpers/constants';

class Rewrites extends Component {
componentDidMount() {
this.props.getRewritesList();
}

handleSubmit = (values) => {
this.props.addRewrite(values);
};

handleDelete = (values) => {
// eslint-disable-next-line no-alert
if (window.confirm(this.props.t('rewrite_confirm_delete', { key: values.domain }))) {
this.props.deleteRewrite(values);
}
};

handleSubmit = (values) => {
const { modalType, currentRewrite } = this.props.rewrites;

if (modalType === MODAL_TYPE.EDIT_REWRITE && currentRewrite) {
this.props.updateRewrite({
target: currentRewrite,
update: values,
});
} else {
this.props.addRewrite(values);
}
};

render() {
const {
t,
Expand All @@ -36,6 +46,9 @@ class Rewrites extends Component {
processing,
processingAdd,
processingDelete,
processingUpdate,
modalType,
currentRewrite,
} = rewrites;

return (
Expand All @@ -54,24 +67,29 @@ class Rewrites extends Component {
processing={processing}
processingAdd={processingAdd}
processingDelete={processingDelete}
processingUpdate={processingUpdate}
handleDelete={this.handleDelete}
toggleRewritesModal={toggleRewritesModal}
/>

<button
type="button"
className="btn btn-success btn-standard mt-3"
onClick={() => toggleRewritesModal()}
onClick={() => toggleRewritesModal({ type: MODAL_TYPE.ADD_REWRITE })}
disabled={processingAdd}
>
<Trans>rewrite_add</Trans>
</button>

<Modal
isModalOpen={isModalOpen}
modalType={modalType}
toggleRewritesModal={toggleRewritesModal}
handleSubmit={this.handleSubmit}
processingAdd={processingAdd}
processingDelete={processingDelete}
processingUpdate={processingUpdate}
currentRewrite={currentRewrite}
/>
</Fragment>
</Card>
Expand All @@ -86,6 +104,7 @@ Rewrites.propTypes = {
toggleRewritesModal: PropTypes.func.isRequired,
addRewrite: PropTypes.func.isRequired,
deleteRewrite: PropTypes.func.isRequired,
updateRewrite: PropTypes.func.isRequired,
rewrites: PropTypes.object.isRequired,
};

Expand Down
1 change: 1 addition & 0 deletions client/src/components/Filters/Table.js
Expand Up @@ -48,6 +48,7 @@ class Table extends Component {
Header: <Trans>list_url_table_header</Trans>,
accessor: 'url',
minWidth: 180,
// eslint-disable-next-line react/prop-types
Cell: ({ value }) => (
<div className="logs__row">
{isValidAbsolutePath(value) ? value
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/ProtectionTimer/index.js
Expand Up @@ -32,6 +32,8 @@ const ProtectionTimer = ({
};

ProtectionTimer.propTypes = {
protectionDisabledDuration: PropTypes.number,
toggleProtectionSuccess: PropTypes.func.isRequired,
setProtectionTimerTime: PropTypes.func.isRequired,
};

Expand Down
1 change: 0 additions & 1 deletion client/src/components/Settings/LogsConfig/Form.js
Expand Up @@ -27,7 +27,6 @@ import {
} from '../../../helpers/constants';
import '../FormButton.css';


const getIntervalTitle = (interval, t) => {
switch (interval) {
case RETENTION_CUSTOM:
Expand Down
1 change: 0 additions & 1 deletion client/src/components/Settings/StatsConfig/Form.js
Expand Up @@ -7,7 +7,6 @@ import { Trans, withTranslation } from 'react-i18next';
import flow from 'lodash/flow';
import { connect } from 'react-redux';


import {
renderRadioField,
toNumber,
Expand Down
1 change: 1 addition & 0 deletions client/src/components/ui/Icons.js
@@ -1,3 +1,4 @@
/* eslint-disable react/no-unknown-property */
import React from 'react';

import './Icons.css';
Expand Down
2 changes: 2 additions & 0 deletions client/src/containers/DnsRewrites.js
Expand Up @@ -3,6 +3,7 @@ import {
getRewritesList,
addRewrite,
deleteRewrite,
updateRewrite,
toggleRewritesModal,
} from '../actions/rewrites';
import Rewrites from '../components/Filters/Rewrites';
Expand All @@ -17,6 +18,7 @@ const mapDispatchToProps = {
getRewritesList,
addRewrite,
deleteRewrite,
updateRewrite,
toggleRewritesModal,
};

Expand Down
2 changes: 2 additions & 0 deletions client/src/helpers/constants.js
Expand Up @@ -173,6 +173,8 @@ export const MODAL_TYPE = {
ADD_FILTERS: 'ADD_FILTERS',
EDIT_FILTERS: 'EDIT_FILTERS',
CHOOSE_FILTERING_LIST: 'CHOOSE_FILTERING_LIST',
ADD_REWRITE: 'ADD_REWRITE',
EDIT_REWRITE: 'EDIT_REWRITE',
};

export const CLIENT_ID = {
Expand Down
1 change: 0 additions & 1 deletion client/src/helpers/helpers.js
Expand Up @@ -845,7 +845,6 @@ export const sortIp = (a, b) => {
}
};


/**
* @param {number} filterId
* @returns {string}
Expand Down

0 comments on commit b4022c3

Please sign in to comment.