Skip to content
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

FEATURE: Make it possible to validate host, source and target path #100

Open
wants to merge 3 commits into
base: 2.0
Choose a base branch
from
Open
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
31 changes: 22 additions & 9 deletions Classes/Controller/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,17 +582,30 @@ protected function deleteRedirect(string $sourceUriPath, ?string $host = null):

protected function validateRedirectAttributes(?string $host, string $sourceUriPath, string $targetUriPath): bool
{
$valid = true;

if ($sourceUriPath === $targetUriPath) {
$this->addFlashMessage('', $this->translateById('error.sameSourceAndTarget'),
Message::SEVERITY_WARNING);
} elseif (!preg_match($this->validationOptions['sourceUriPath'], $sourceUriPath)) {
$this->addFlashMessage('',
$this->translateById('error.sourceUriPathNotValid', [$this->validationOptions['sourceUriPath']]),
Message::SEVERITY_WARNING);
} else {
return true;
$valid = false;
$errorMessages[] = $this->translateById('error.sameSourceAndTarget');
}
if (isset($this->validationOptions['host']) && !preg_match($this->validationOptions['host'], $host)) {
$valid = false;
$errorMessages[] = $this->translateById('error.hostNotValid');
}
if (isset($this->validationOptions['sourceUriPath']) && !preg_match($this->validationOptions['sourceUriPath'], $sourceUriPath)) {
$valid = false;
$errorMessages[] = $this->translateById('error.sourceUriPathNotValid', [$this->validationOptions['sourceUriPath']]);
}
return false;
if (isset($this->validationOptions['targetUriPath']) && !preg_match($this->validationOptions['targetUriPath'], $targetUriPath)) {
$valid = false;
$errorMessages[] = $this->translateById('error.targetUriPathNotValid', [$this->validationOptions['targetUriPath']]);
}

if (!$valid) {
$this->addFlashMessage('', implode('<br>', $errorMessages), Message::SEVERITY_WARNING);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to show all errors and not just the first one.
Will test it.

}

return $valid;
}

protected function isSame(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ prototype(Neos.RedirectHandler.Ui:Component.Redirect.List) < prototype(Neos.Fusi
initialStatusCodeFilter = ${Configuration.setting('Neos.RedirectHandler.Ui.initialStatusCodeFilter')}
initialTypeFilter = ${Configuration.setting('Neos.RedirectHandler.Ui.initialTypeFilter')}
validSourceUriPathPattern = ${Configuration.setting('Neos.RedirectHandler.Ui.validation.sourceUriPath')}
validTargetUriPathPattern = ${Configuration.setting('Neos.RedirectHandler.Ui.validation.targetUriPath')}
// Don't render disabled status codes
statusCodes = ${Array.filter(Configuration.setting('Neos.RedirectHandler.Ui.statusCodes'), x => !!x)}
hostOptions = ${hostOptions}
Expand Down Expand Up @@ -34,6 +35,7 @@ prototype(Neos.RedirectHandler.Ui:Component.Redirect.List) < prototype(Neos.Fusi
data-default-status-code={props.defaultStatusCode}
data-actions={Json.stringify(props.actions)}
data-valid-source-uri-path-pattern={props.validSourceUriPathPattern}
data-valid-target-uri-path-pattern={props.validTargetUriPathPattern}
data-status-codes={Json.stringify(props.statusCodes)}
data-host-options={Json.stringify(props.hostOptions)}>
<p>{I18n.translate('Neos.RedirectHandler.Ui:Modules:list.loading')}</p>
Expand Down
5 changes: 4 additions & 1 deletion Resources/Private/JavaScript/components/RedirectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type RedirectFormProps = {
redirect: Redirect;
idPrefix: string;
validSourceUriPathPattern: string;
validTargetUriPathPattern: string;
handleNewRedirect: (changedRedirects: Redirect[]) => void;
handleUpdatedRedirect: (changedRedirects: Redirect[], oldRedirect: Redirect) => void;
handleCancelAction: () => void;
Expand Down Expand Up @@ -268,7 +269,8 @@ export class RedirectForm extends PureComponent<RedirectFormProps, RedirectFormS
};

public render(): React.ReactElement {
const { translate, redirect, idPrefix, validSourceUriPathPattern, handleCancelAction } = this.props;
const { translate, redirect, idPrefix, validSourceUriPathPattern, validTargetUriPathPattern, handleCancelAction } = this.props;
console.log({validTargetUriPathPattern});

const { statusCodes, hostOptions } = this.context;

Expand Down Expand Up @@ -391,6 +393,7 @@ export class RedirectForm extends PureComponent<RedirectFormProps, RedirectFormS
autoCapitalize="off"
spellCheck={false}
value={targetUriPath || ''}
pattern={validTargetUriPathPattern}
onChange={this.handleInputChange}
/>
</div>
Expand Down
5 changes: 4 additions & 1 deletion Resources/Private/JavaScript/components/RedirectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type RedirectListProps = {
initialTypeFilter: string;
initialStatusCodeFilter: number;
validSourceUriPathPattern: string;
validTargetUriPathPattern: string;
showHitCount: boolean;
actions: {
delete: string;
Expand Down Expand Up @@ -389,7 +390,7 @@ export class RedirectList extends React.Component<RedirectListProps, RedirectLis
}

public render(): JSX.Element {
const { showHitCount, translate, actions, validSourceUriPathPattern, notificationHelper } = this.props;
const { showHitCount, translate, actions, validSourceUriPathPattern, validTargetUriPathPattern, notificationHelper } = this.props;

const {
redirects,
Expand Down Expand Up @@ -447,6 +448,7 @@ export class RedirectList extends React.Component<RedirectListProps, RedirectLis
handleCancelAction={this.handleToggleForm}
idPrefix=""
validSourceUriPathPattern={validSourceUriPathPattern}
validTargetUriPathPattern={validTargetUriPathPattern}
/>
</>
)}
Expand Down Expand Up @@ -521,6 +523,7 @@ export class RedirectList extends React.Component<RedirectListProps, RedirectLis
handleCancelAction={this.handleCancelAction}
idPrefix={'redirect-' + index + '-'}
validSourceUriPathPattern={validSourceUriPathPattern}
validTargetUriPathPattern={validTargetUriPathPattern}
/>
</td>
</tr>
Expand Down
3 changes: 2 additions & 1 deletion Resources/Private/JavaScript/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ window.addEventListener(
const statusCodes: { [index: string]: string } = JSON.parse(redirectsList.dataset.statusCodes);
const hostOptions: string[] = JSON.parse(redirectsList.dataset.hostOptions);

const { csrfToken, validSourceUriPathPattern } = redirectsList.dataset;
const { csrfToken, validSourceUriPathPattern, validTargetUriPathPattern } = redirectsList.dataset;

const initialTypeFilter = redirectsList.dataset.initialTypeFilter || '';
const defaultStatusCode = parseInt(redirectsList.dataset.defaultStatusCode, 10);
Expand Down Expand Up @@ -61,6 +61,7 @@ window.addEventListener(
translate={translate}
showHitCount={showHitCount}
validSourceUriPathPattern={validSourceUriPathPattern}
validTargetUriPathPattern={validTargetUriPathPattern}
notificationHelper={Notification}
initialTypeFilter={initialTypeFilter}
initialStatusCodeFilter={initialStatusCodeFilter}
Expand Down
12 changes: 10 additions & 2 deletions Resources/Private/Translations/de/Modules.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,16 @@
<target>In der CSV Datei konnten keine Einträge gefunden werden</target>
</trans-unit>
<trans-unit id="error.sourceUriPathNotValid" xml:space="preserve">
<source>The source path doesn't match the expression {0}</source>
<target>Der Quellpfad entspricht nicht dem Muster {0}</target>
<source>The source path doesn't match the expression "{0}"</source>
<target>Der Quellpfad entspricht nicht dem Muster "{0}"</target>
</trans-unit>
<trans-unit id="error.targetUriPathNotValid" xml:space="preserve">
<source>The target path doesn't match the expression "{0}"</source>
<target>Der Zielpfad entspricht nicht dem Muster "{0}"</target>
</trans-unit>
<trans-unit id="error.hostNotValid" xml:space="preserve">
<source>The host doesn't match the expression "{0}"</source>
<target>Der Host entspricht nicht dem Muster "{0}"</target>
</trans-unit>
<trans-unit id="host" xml:space="preserve">
<source>Origin domain</source>
Expand Down
8 changes: 7 additions & 1 deletion Resources/Private/Translations/en/Modules.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@
<source>No entries were found in the CSV file</source>
</trans-unit>
<trans-unit id="error.sourceUriPathNotValid" xml:space="preserve">
<source>The source path doesn't match the expression {0}</source>
<source>The source path doesn't match the expression "{0}"</source>
</trans-unit>
<trans-unit id="error.targetUriPathNotValid" xml:space="preserve">
<source>The target path doesn't match the expression "{0}"</source>
</trans-unit>
<trans-unit id="error.hostNotValid" xml:space="preserve">
<source>The host doesn't match the expression "{0}"</source>
</trans-unit>

<trans-unit id="host" xml:space="preserve">
Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/Assets/main.bundle.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/Public/Assets/main.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Resources/Public/Assets/main.bundle.js.map

Large diffs are not rendered by default.