8000 Add user role and server match by johngodley · Pull Request #1005 · johngodley/redirection · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add user role and server match #1005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: yarn install
- run: yarn install --ignore-engines

- save_cache:
paths:
Expand Down
7 changes: 6 additions & 1 deletion client/component/home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ class Home extends React.Component {
);
}

=> {
ev.preventDefault();
this.props.onAdd();
}

render() {
const title = TITLES[ this.state.page ];

Expand All @@ -167,7 +172,7 @@ class Home extends React.Component {
return (
<div className="wrap redirection">
<h1 className="wp-heading-inline">{ title }</h1>
{ this.state.page === 'redirect' && <a href="#" this.props.onAdd } className="page-title-action">Add New</a> }
{ this.state.page === 'redirect' && <a href="#" this.onAdd } className="page-title-action">{ __( 'Add New' ) }</a> }

<Menu this.handlePageChange } />
<Error />
Expand Down
14 changes: 13 additions & 1 deletion client/component/options/options-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class OptionsForm extends React.Component {
} );
}

componentWillUpdate( nextProps ) {
UNSAFE_componentWillUpdate( nextProps ) {
if ( nextProps.values.token !== this.props.values.token ) {
this.setState( { token: nextProps.values.token } );
}
Expand Down Expand Up @@ -158,6 +158,8 @@ class OptionsForm extends React.Component {

<TableRow title={ __( 'IP Logging' ) + ':' } url={ this.supportLink( 'options', 'iplogging' ) }>
<Select items={ ipLogging } name="ip_logging" value={ parseInt( this.state.ip_logging, 10 ) } this.onChange } /> { __( '(select IP logging level)' ) }

&nbsp;- <a target="_blank" rel="noopener noreferrer" href={ this.supportLink( 'privacy-gdpr' ) }>{ __( 'GDPR / Privacy information' ) }</a>
</TableRow>

<TableRow title={ __( 'URL Monitor' ) + ':' } url={ this.supportLink( 'options', 'monitor' ) }>
Expand Down Expand Up @@ -196,6 +198,16 @@ class OptionsForm extends React.Component {
</label>
</TableRow>

<TableRow title={ __( 'Force HTTPS' ) } url={ this.supportLink( 'options', 'force-https' ) }>
<label>
<p>
<input type="checkbox" name="https" this.onChange } checked={ this.state.https } />
{ __( 'Force a redirect from HTTP to HTTPS. Please ensure your HTTPS is working before enabling' ) }
&nbsp; { __( '(beta)' ) }
</p>
</label>
</TableRow>

<TableRow title={ __( 'Redirect Cache' ) } url={ this.supportLink( 'options', 'cache' ) }>
<Select items={ expireTimes } name="redirect_cache" value={ parseInt( this.state.redirect_cache, 10 ) } this.onChange } /> &nbsp;
<span className="sub">{ __( 'How long to cache redirected 301 URLs (via "Expires" HTTP header)' ) }</span>
Expand Down
2 changes: 1 addition & 1 deletion client/component/redirects/action/url.js
AE20
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const ActionUrl = props => {
<tr>
<th>{ __( 'Target URL' ) }</th>
<td>
<input type="text" name="url" value={ props.target.url } changer } />
<input type="text" name="url" value={ props.target.url } changer } placeholder={ __( 'The target URL you want to redirect to if matched' ) } />
</td>
</tr>
);
Expand Down
106 changes: 83 additions & 23 deletions client/component/redirects/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import MatchReferrer from './match/referrer';
import MatchHeader from './match/header';
import MatchCustom from './match/custom';
import MatchCookie from './match/cookie';
import MatchRole from './match/role';
import MatchServer from './match/server';
import ActionLogin from './action/login';
import ActionUrl from './action/url';
import ActionUrlFrom from './action/url-from';
Expand All @@ -37,6 +39,8 @@ import {
MATCH_COOKIE,
MATCH_HEADER,
MATCH_CUSTOM,
MATCH_ROLE,
MATCH_SERVER,

getActionData,
hasUrlTarget,
Expand All @@ -51,6 +55,10 @@ const MATCHES = [
value: MATCH_LOGIN,
name: __( 'URL and login status' ),
},
{
value: MATCH_ROLE,
name: __( 'URL and role/capability filter' ),
},
{
value: MATCH_REFERRER,
name: __( 'URL and referrer' ),
Expand All @@ -63,6 +71,10 @@ const MATCHES = [
value: MATCH_COOKIE,
name: __( 'URL and cookie' ),
},
{
value: MATCH_SERVER,
name: __( 'URL and server' ),
},
{
value: MATCH_HEADER,
name: __( 'URL and HTTP header' ),
Expand Down Expand Up @@ -158,6 +170,8 @@ class EditRedirect extends React.Component {
cookie: this.getHeaderState( action_data ),
header: this.getHeaderState( action_data ),
custom: this.getCustomState( action_data ),
role: this.getRoleState( action_data ),
server: this.getServerState( action_data ),
};

this.state.advanced = ! this.canShowAdvanced();
Expand Down Expand Up @@ -242,6 +256,16 @@ class EditRedirect extends React.Component {
url_from: '',
url_notfrom: '',
},
role: {
role: '',
url_from: '',
url_notfrom: '',
},
server: {
server: '',
url_from: '',
url_notfrom: '',
},
};
}

Expand Down Expand Up @@ -273,6 +297,26 @@ class EditRedirect extends React.Component {
};
}

getRoleState( action_data ) {
const { role = '', url_from = '', url_notfrom = '' } = action_data ? action_data : {};

return {
role,
url_from,
url_notfrom,
};
}

getServerState( action_data ) {
const { server = '', url_from = '', url_notfrom = '' } = action_data ? action_data : {};

return {
server,
url_from,
url_notfrom,
};
}

getHeaderState( action_data ) {
const { name = '', value = '', regex = false, url_from = '', url_notfrom = '' } = action_data ? action_data : {};

Expand Down Expand Up @@ -421,42 +465,51 @@ class EditRedirect extends React.Component {

case MATCH_CUSTOM:
return <MatchCustom filter={ this.state.custom.filter } this.onSetData } />;

case MATCH_ROLE:
return <MatchRole role={ this.state.role.role } this.onSetData } />;

case MATCH_SERVER:
return <MatchServer server={ this.state.server.server } this.onSetData } />;
}

return null;
}

getTarget() {
const { match_type, action_type, agent, referrer, login, cookie, target, header, custom } = this.state;
const { match_type, action_type, agent, referrer, login, cookie, target, header, custom, role, server } = this.state;

if ( hasUrlTarget( action_type ) ) {
if ( match_type === MATCH_AGENT ) {
if ( ! hasUrlTarget( action_type ) ) {
return null;
}

switch ( match_type ) {
case MATCH_AGENT:
return <ActionUrlFrom url_from={ agent.url_from } url_notfrom={ agent.url_notfrom } target="agent" this.onSetData } />;
}

if ( match_type === MATCH_REFERRER ) {
case MATCH_REFERRER:
return <ActionUrlFrom url_from={ referrer.url_from } url_notfrom={ referrer.url_notfrom } target="referrer" this.onSetData } />;
}

if ( match_type === MATCH_LOGIN ) {
case MATCH_LOGIN:
return <ActionLogin logged_in={ login.logged_in } logged_out={ login.logged_out } this.onSetData } />;
}

if ( match_type === MATCH_URL ) {
case MATCH_URL:
return <ActionUrl target={ target } this.onSetData } />;
}

if ( match_type === MATCH_COOKIE ) {
return <ActionUrlFrom url_from={ cookie.url_from } url_notfrom={ cookie.url_notfrom } target="cookie" this.onSetData } />
}
case MATCH_COOKIE:
return <ActionUrlFrom url_from={ cookie.url_from } url_notfrom={ cookie.url_notfrom } target="cookie" this.onSetData } />;

if ( match_type === MATCH_HEADER ) {
return <ActionUrlFrom url_from={ header.url_from } url_notfrom={ header.url_notfrom } target="header" this.onSetData } />
}
case MATCH_HEADER:
return <ActionUrlFrom url_from={ header.url_from } url_notfrom={ header.url_notfrom } target="header" this.onSetData } />;

if ( match_type === MATCH_CUSTOM ) {
return <ActionUrlFrom url_from={ custom.url_from } url_notfrom={ custom.url_notfrom } target="custom" this.onSetData } />
}
case MATCH_CUSTOM:
return <ActionUrlFrom url_from={ custom.url_from } url_notfrom={ custom.url_notfrom } target="custom" this.onSetData } />;

case MATCH_ROLE:
return <ActionUrlFrom url_from={ role.url_from } url_notfrom={ role.url_notfrom } target="role" this.onSetData } />;

case MATCH_SERVER:
return <ActionUrlFrom url_from={ server.url_from } url_notfrom={ server.url_notfrom } target="server" this.onSetData } />;
}

return null;
Expand All @@ -469,7 +522,7 @@ class EditRedirect extends React.Component {
<tr>
<th>{ __( 'Title' ) }</th>
<td>
<input type="text" name="title" value={ title } this.onChange } placeholder={ __( 'Optional description' ) } />
<input type="text" name="title" value={ title } this.onChange } placeholder={ __( 'Optional description - describe the purpose of this redirect' ) } />
</td>
</tr>
);
Expand Down Expand Up @@ -540,7 +593,7 @@ class EditRedirect extends React.Component {
}

canSave() {
const { url, match_type, target, action_type, referrer, login, agent, header, custom, cookie } = this.state;
const { url, match_type, target, action_type, referrer, login, agent, header, cookie, role, server } = this.state;

if ( Redirectioni10n.autoGenerate === '' && url === '' ) {
return false;
Expand Down Expand Up @@ -570,6 +623,14 @@ class EditRedirect extends React.Component {
if ( match_type === MATCH_HEADER && header.url_from === '' && header.url_notfrom === '' ) {
return false;
}

if ( match_type === MATCH_ROLE && role.url_from === '' && role.url_notfrom === '' ) {
return false;
}

if ( match_type === MATCH_SERVER && server.url_from === '' && server.url_notfrom === '' ) {
return false;
}
}

return true;
Expand All @@ -586,7 +647,7 @@ class EditRedirect extends React.Component {
<tr>
<th>{ __( 'Source URL' ) }</th>
<td>
<input type="text" name="url" value={ url } this.onChange } autoFocus={ autoFocus } />
<input type="text" name="url" value={ url } this.onChange } autoFocus={ autoFocus } placeholder={ __( 'The relative URL you want to redirect from' ) } />
<label className="edit-redirection-regex">
{ __( 'Regex' ) } <sup><a tabIndex="-1" target="_blank" rel="noopener noreferrer" href="https://redirection.me/support/redirect-regular-expressions/">?</a></sup>
&nbsp;
Expand Down Expand Up @@ -625,7 +686,6 @@ class EditRedirect extends React.Component {
}
}

// XXX
EditRedirect.propTypes = {
item: PropTypes.object.isRequired,
onCancel: PropTypes.func,
Expand Down
2 changes: 1 addition & 1 deletion client/component/redirects/match/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class MatchAgent extends React.Component {
<tr>
<th>{ __( 'User Agent' ) }</th>
<td className="useragent-match">
<input type="text" name="agent" value={ this.props.agent } this.handleChangeAgent } className="medium" />
<input type="text" name="agent" value={ this.props.agent } this.handleChangeAgent } className="medium" placeholder={ __( 'Match against this browser user agent' ) } />

<select name="agent_dropdown" this.onDropdown } value={ this.state.dropdown } className="medium">
<option value="">{ __( 'Custom' ) }</option>
Expand Down
2 changes: 1 addition & 1 deletion client/component/redirects/match/referrer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MatchReferrer extends React.Component {
<tr>
<th>{ __( 'Referrer' ) }</th>
<td>
<input type="text" name="referrer" value={ this.props.referrer } this.handleChangeReferrer } />
<input type="text" name="referrer" value={ this.props.referrer } this.handleChangeReferrer } placeholder={ __( 'Match against this browser referrer text' ) } />
<label className="edit-redirection-regex">
{ __( 'Regex' ) } <sup><a tabIndex="-1" target="_blank" rel="noopener noreferrer" href="https://redirection.me/support/redirect-regular-expressions/">?</a></sup>
&nbsp;
Expand Down
36 changes: 36 additions & 0 deletions client/component/redirects/match/role.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* External dependencies
*/

import React from 'react';
import { translate as __ } from 'lib/locale';
import PropTypes from 'prop-types';

/**
* Internal dependencies
*/

class MatchRole extends React.Component {
=> {
if ( ev.target.value !== '' ) {
this.props.onChange( 'role', 'role', ev.target.value );
}
}

render() {
return (
<tr>
<th>{ __( 'Role' ) }</th>
<td>
<input type="text" value={ this.props.role } placeholder={ __( 'Enter role or capability value' ) } this.onChange } />
</td>
</tr>
);
}
}

MatchRole.propTypes = {
role: PropTypes.string.isRequired,
};

export default MatchRole;
36 changes: 36 additions & 0 deletions client/component/redirects/match/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* External dependencies
*/

import React from 'react';
import { translate as __ } from 'lib/locale';
import PropTypes from 'prop-types';

/**
* Internal dependencies
*/

class MatchServer extends React.Component {
=> {
if ( ev.target.value !== '' ) {
this.props.onChange( 'server', 'server', ev.target.value );
}
}

render() {
return (
<tr>
<th>{ __( 'Server' ) }</th>
<td>
<input type="text" value={ this.props.server } placeholder={ __( 'Enter server URL to match against' ) } this.onChange } />
</td>
</tr>
);
}
}

MatchServer.propTypes = {
server: PropTypes.string.isRequired,
};

export default MatchServer;
1 change: 1 addition & 0 deletions client/lib/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ const getAction = request =>
request.url.replace( Redirectioni10n.WP_API_root, '' ).replace( /[\?&]_wpnonce=[a-f0-9]*/, '' ) +
' ' +
request.method.toUpperCase();

const getErrorMessage = json => {
if ( json === 0 ) {
return 'Admin AJAX returned 0';
Expand Down
Empty file removed client/lib/api/settings.js
Empty file.
Loading
0