2019-10-20 18:02:52 +02:00
|
|
|
import React from "react";
|
|
|
|
|
import { translate } from "react-i18next";
|
|
|
|
|
import { SubmitButton, Notification } from "@scm-manager/ui-components";
|
|
|
|
|
import { NamespaceStrategies, Config } from "@scm-manager/ui-types";
|
|
|
|
|
import ProxySettings from "./ProxySettings";
|
|
|
|
|
import GeneralSettings from "./GeneralSettings";
|
|
|
|
|
import BaseUrlSettings from "./BaseUrlSettings";
|
|
|
|
|
import LoginAttempt from "./LoginAttempt";
|
2018-08-13 16:33:56 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
submitForm: (p: Config) => void;
|
|
|
|
|
config?: Config;
|
|
|
|
|
loading?: boolean;
|
|
|
|
|
configReadPermission: boolean;
|
|
|
|
|
configUpdatePermission: boolean;
|
|
|
|
|
namespaceStrategies?: NamespaceStrategies;
|
2019-03-11 14:48:48 +01:00
|
|
|
// context props
|
2019-10-19 16:38:07 +02:00
|
|
|
t: (p: string) => string;
|
2018-08-13 16:33:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type State = {
|
2019-10-19 16:38:07 +02:00
|
|
|
config: Config;
|
|
|
|
|
showNotification: boolean;
|
2018-08-21 08:40:49 +02:00
|
|
|
error: {
|
2019-10-19 16:38:07 +02:00
|
|
|
loginAttemptLimitTimeout: boolean;
|
|
|
|
|
loginAttemptLimit: boolean;
|
|
|
|
|
};
|
|
|
|
|
changed: boolean;
|
2018-08-13 16:33:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ConfigForm extends React.Component<Props, State> {
|
|
|
|
|
constructor(props: Props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
|
config: {
|
|
|
|
|
proxyPassword: null,
|
|
|
|
|
proxyPort: 0,
|
2019-10-20 18:02:52 +02:00
|
|
|
proxyServer: "",
|
2018-08-13 16:33:56 +02:00
|
|
|
proxyUser: null,
|
|
|
|
|
enableProxy: false,
|
2019-10-20 18:02:52 +02:00
|
|
|
realmDescription: "",
|
2018-08-13 16:33:56 +02:00
|
|
|
disableGroupingGrid: false,
|
2019-10-20 18:02:52 +02:00
|
|
|
dateFormat: "",
|
2018-08-13 16:33:56 +02:00
|
|
|
anonymousAccessEnabled: false,
|
2019-10-20 18:02:52 +02:00
|
|
|
baseUrl: "",
|
2018-08-13 16:33:56 +02:00
|
|
|
forceBaseUrl: false,
|
|
|
|
|
loginAttemptLimit: 0,
|
|
|
|
|
proxyExcludes: [],
|
|
|
|
|
skipFailedAuthenticators: false,
|
2019-10-20 18:02:52 +02:00
|
|
|
pluginUrl: "",
|
2018-08-13 16:33:56 +02:00
|
|
|
loginAttemptLimitTimeout: 0,
|
|
|
|
|
enabledXsrfProtection: true,
|
2019-10-20 18:02:52 +02:00
|
|
|
namespaceStrategy: "",
|
|
|
|
|
loginInfoUrl: "",
|
|
|
|
|
_links: {}
|
2018-08-16 13:28:46 +02:00
|
|
|
},
|
2018-08-16 16:41:17 +02:00
|
|
|
showNotification: false,
|
2018-08-21 08:40:49 +02:00
|
|
|
error: {
|
|
|
|
|
loginAttemptLimitTimeout: false,
|
2019-10-20 18:02:52 +02:00
|
|
|
loginAttemptLimit: false
|
2019-01-02 14:37:25 +01:00
|
|
|
},
|
2019-10-20 18:02:52 +02:00
|
|
|
changed: false
|
2018-08-13 16:33:56 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
2018-08-16 13:28:46 +02:00
|
|
|
const { config, configUpdatePermission } = this.props;
|
2018-08-13 16:33:56 +02:00
|
|
|
if (config) {
|
2019-10-19 16:38:07 +02:00
|
|
|
this.setState({
|
|
|
|
|
...this.state,
|
|
|
|
|
config: {
|
2019-10-20 18:02:52 +02:00
|
|
|
...config
|
|
|
|
|
}
|
2019-10-19 16:38:07 +02:00
|
|
|
});
|
2018-08-16 13:28:46 +02:00
|
|
|
}
|
|
|
|
|
if (!configUpdatePermission) {
|
2019-10-19 16:38:07 +02:00
|
|
|
this.setState({
|
|
|
|
|
...this.state,
|
2019-10-20 18:02:52 +02:00
|
|
|
showNotification: true
|
2019-10-19 16:38:07 +02:00
|
|
|
});
|
2018-08-13 16:33:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
submit = (event: Event) => {
|
|
|
|
|
event.preventDefault();
|
2019-01-11 08:31:00 +01:00
|
|
|
this.setState({
|
2019-10-20 18:02:52 +02:00
|
|
|
changed: false
|
2019-01-11 08:31:00 +01:00
|
|
|
});
|
2018-08-13 16:33:56 +02:00
|
|
|
this.props.submitForm(this.state.config);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
2019-03-04 16:47:44 +01:00
|
|
|
const {
|
|
|
|
|
loading,
|
|
|
|
|
t,
|
2019-03-11 14:48:48 +01:00
|
|
|
namespaceStrategies,
|
2019-03-04 16:47:44 +01:00
|
|
|
configReadPermission,
|
2019-10-20 18:02:52 +02:00
|
|
|
configUpdatePermission
|
2019-03-04 16:47:44 +01:00
|
|
|
} = this.props;
|
2018-08-16 13:28:46 +02:00
|
|
|
const config = this.state.config;
|
|
|
|
|
|
|
|
|
|
let noPermissionNotification = null;
|
|
|
|
|
|
2019-03-04 16:47:44 +01:00
|
|
|
if (!configReadPermission) {
|
|
|
|
|
return (
|
|
|
|
|
<Notification
|
2019-10-20 18:02:52 +02:00
|
|
|
type={"danger"}
|
|
|
|
|
children={t("config.form.no-read-permission-notification")}
|
2019-03-04 16:47:44 +01:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 13:28:46 +02:00
|
|
|
if (this.state.showNotification) {
|
|
|
|
|
noPermissionNotification = (
|
|
|
|
|
<Notification
|
2019-10-20 18:02:52 +02:00
|
|
|
type={"info"}
|
|
|
|
|
children={t("config.form.no-write-permission-notification")}
|
2018-08-16 13:28:46 +02:00
|
|
|
onClose={() => this.onClose()}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-13 16:33:56 +02:00
|
|
|
return (
|
|
|
|
|
<form onSubmit={this.submit}>
|
2018-08-16 13:28:46 +02:00
|
|
|
{noPermissionNotification}
|
2018-08-13 16:33:56 +02:00
|
|
|
<GeneralSettings
|
2019-03-11 14:48:48 +01:00
|
|
|
namespaceStrategies={namespaceStrategies}
|
2019-08-13 09:45:37 +02:00
|
|
|
loginInfoUrl={config.loginInfoUrl}
|
2018-08-13 16:33:56 +02:00
|
|
|
realmDescription={config.realmDescription}
|
|
|
|
|
disableGroupingGrid={config.disableGroupingGrid}
|
|
|
|
|
dateFormat={config.dateFormat}
|
|
|
|
|
anonymousAccessEnabled={config.anonymousAccessEnabled}
|
|
|
|
|
skipFailedAuthenticators={config.skipFailedAuthenticators}
|
|
|
|
|
pluginUrl={config.pluginUrl}
|
|
|
|
|
enabledXsrfProtection={config.enabledXsrfProtection}
|
2019-03-12 15:54:34 +01:00
|
|
|
namespaceStrategy={config.namespaceStrategy}
|
2018-08-13 16:33:56 +02:00
|
|
|
onChange={(isValid, changedValue, name) =>
|
|
|
|
|
this.onChange(isValid, changedValue, name)
|
|
|
|
|
}
|
2018-08-16 12:12:59 +02:00
|
|
|
hasUpdatePermission={configUpdatePermission}
|
2018-08-13 16:33:56 +02:00
|
|
|
/>
|
2018-08-16 10:55:39 +02:00
|
|
|
<hr />
|
2018-08-16 16:41:17 +02:00
|
|
|
<LoginAttempt
|
|
|
|
|
loginAttemptLimit={config.loginAttemptLimit}
|
|
|
|
|
loginAttemptLimitTimeout={config.loginAttemptLimitTimeout}
|
|
|
|
|
onChange={(isValid, changedValue, name) =>
|
|
|
|
|
this.onChange(isValid, changedValue, name)
|
|
|
|
|
}
|
|
|
|
|
hasUpdatePermission={configUpdatePermission}
|
|
|
|
|
/>
|
|
|
|
|
<hr />
|
2018-08-13 16:33:56 +02:00
|
|
|
<BaseUrlSettings
|
|
|
|
|
baseUrl={config.baseUrl}
|
|
|
|
|
forceBaseUrl={config.forceBaseUrl}
|
|
|
|
|
onChange={(isValid, changedValue, name) =>
|
|
|
|
|
this.onChange(isValid, changedValue, name)
|
|
|
|
|
}
|
2018-08-16 12:12:59 +02:00
|
|
|
hasUpdatePermission={configUpdatePermission}
|
2018-08-13 16:33:56 +02:00
|
|
|
/>
|
2018-08-16 10:55:39 +02:00
|
|
|
<hr />
|
2018-08-13 16:33:56 +02:00
|
|
|
<ProxySettings
|
2019-10-20 18:02:52 +02:00
|
|
|
proxyPassword={config.proxyPassword ? config.proxyPassword : ""}
|
2018-08-13 16:33:56 +02:00
|
|
|
proxyPort={config.proxyPort}
|
2019-10-20 18:02:52 +02:00
|
|
|
proxyServer={config.proxyServer ? config.proxyServer : ""}
|
|
|
|
|
proxyUser={config.proxyUser ? config.proxyUser : ""}
|
2018-08-13 16:33:56 +02:00
|
|
|
enableProxy={config.enableProxy}
|
2018-08-16 11:18:28 +02:00
|
|
|
proxyExcludes={config.proxyExcludes}
|
2018-08-13 16:33:56 +02:00
|
|
|
onChange={(isValid, changedValue, name) =>
|
|
|
|
|
this.onChange(isValid, changedValue, name)
|
|
|
|
|
}
|
2018-08-16 12:12:59 +02:00
|
|
|
hasUpdatePermission={configUpdatePermission}
|
2018-08-13 16:33:56 +02:00
|
|
|
/>
|
2018-08-16 10:55:39 +02:00
|
|
|
<hr />
|
2018-08-13 16:33:56 +02:00
|
|
|
<SubmitButton
|
|
|
|
|
loading={loading}
|
2019-10-20 18:02:52 +02:00
|
|
|
label={t("config.form.submit")}
|
2019-01-11 08:31:00 +01:00
|
|
|
disabled={
|
|
|
|
|
!configUpdatePermission || this.hasError() || !this.state.changed
|
|
|
|
|
}
|
2018-08-13 16:33:56 +02:00
|
|
|
/>
|
|
|
|
|
</form>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onChange = (isValid: boolean, changedValue: any, name: string) => {
|
2018-08-16 16:41:17 +02:00
|
|
|
this.setState({
|
|
|
|
|
...this.state,
|
|
|
|
|
config: {
|
|
|
|
|
...this.state.config,
|
2019-10-20 18:02:52 +02:00
|
|
|
[name]: changedValue
|
2018-08-21 08:40:49 +02:00
|
|
|
},
|
|
|
|
|
error: {
|
|
|
|
|
...this.state.error,
|
2019-10-20 18:02:52 +02:00
|
|
|
[name]: !isValid
|
2019-01-02 14:37:25 +01:00
|
|
|
},
|
2019-10-20 18:02:52 +02:00
|
|
|
changed: true
|
2018-08-16 16:41:17 +02:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-21 08:40:49 +02:00
|
|
|
hasError = () => {
|
|
|
|
|
return (
|
|
|
|
|
this.state.error.loginAttemptLimit ||
|
|
|
|
|
this.state.error.loginAttemptLimitTimeout
|
|
|
|
|
);
|
2018-08-13 16:33:56 +02:00
|
|
|
};
|
2018-08-16 13:28:46 +02:00
|
|
|
|
|
|
|
|
onClose = () => {
|
|
|
|
|
this.setState({
|
|
|
|
|
...this.state,
|
2019-10-20 18:02:52 +02:00
|
|
|
showNotification: false
|
2018-08-16 13:28:46 +02:00
|
|
|
});
|
|
|
|
|
};
|
2018-08-13 16:33:56 +02:00
|
|
|
}
|
|
|
|
|
|
2019-10-20 18:02:52 +02:00
|
|
|
export default translate("config")(ConfigForm);
|