2018-08-13 16:33:56 +02:00
|
|
|
// @flow
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { translate } from "react-i18next";
|
2018-09-05 14:32:49 +02:00
|
|
|
import { SubmitButton, Notification } from "@scm-manager/ui-components";
|
|
|
|
|
import type { Config } from "@scm-manager/ui-types";
|
2018-08-13 16:33:56 +02:00
|
|
|
import ProxySettings from "./ProxySettings";
|
|
|
|
|
import GeneralSettings from "./GeneralSettings";
|
|
|
|
|
import BaseUrlSettings from "./BaseUrlSettings";
|
2018-08-16 10:55:39 +02:00
|
|
|
import AdminSettings from "./AdminSettings";
|
2018-08-16 16:41:17 +02:00
|
|
|
import LoginAttempt from "./LoginAttempt";
|
2018-08-13 16:33:56 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
submitForm: Config => void,
|
|
|
|
|
config?: Config,
|
|
|
|
|
loading?: boolean,
|
2018-08-16 10:55:39 +02:00
|
|
|
t: string => string,
|
2019-03-04 16:47:44 +01:00
|
|
|
configReadPermission: boolean,
|
2018-08-16 10:55:39 +02:00
|
|
|
configUpdatePermission: boolean
|
2018-08-13 16:33:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type State = {
|
2018-08-16 13:28:46 +02:00
|
|
|
config: Config,
|
2018-08-16 16:41:17 +02:00
|
|
|
showNotification: boolean,
|
2018-08-21 08:40:49 +02:00
|
|
|
error: {
|
|
|
|
|
loginAttemptLimitTimeout: boolean,
|
|
|
|
|
loginAttemptLimit: boolean
|
2019-01-02 14:37:25 +01:00
|
|
|
},
|
2019-01-11 08:31:00 +01:00
|
|
|
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,
|
|
|
|
|
proxyServer: "",
|
|
|
|
|
proxyUser: null,
|
|
|
|
|
enableProxy: false,
|
|
|
|
|
realmDescription: "",
|
|
|
|
|
enableRepositoryArchive: false,
|
|
|
|
|
disableGroupingGrid: false,
|
|
|
|
|
dateFormat: "",
|
|
|
|
|
anonymousAccessEnabled: false,
|
|
|
|
|
adminGroups: [],
|
|
|
|
|
adminUsers: [],
|
|
|
|
|
baseUrl: "",
|
|
|
|
|
forceBaseUrl: false,
|
|
|
|
|
loginAttemptLimit: 0,
|
|
|
|
|
proxyExcludes: [],
|
|
|
|
|
skipFailedAuthenticators: false,
|
|
|
|
|
pluginUrl: "",
|
|
|
|
|
loginAttemptLimitTimeout: 0,
|
|
|
|
|
enabledXsrfProtection: true,
|
|
|
|
|
defaultNamespaceStrategy: "",
|
|
|
|
|
_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,
|
|
|
|
|
loginAttemptLimit: false
|
2019-01-02 14:37:25 +01:00
|
|
|
},
|
2019-01-11 08:31:00 +01: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) {
|
2018-08-16 13:28:46 +02:00
|
|
|
this.setState({ ...this.state, config: { ...config } });
|
|
|
|
|
}
|
|
|
|
|
if (!configUpdatePermission) {
|
|
|
|
|
this.setState({ ...this.state, showNotification: true });
|
2018-08-13 16:33:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
submit = (event: Event) => {
|
|
|
|
|
event.preventDefault();
|
2019-01-11 08:31:00 +01:00
|
|
|
this.setState({
|
|
|
|
|
changed: false
|
|
|
|
|
});
|
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,
|
|
|
|
|
configReadPermission,
|
|
|
|
|
configUpdatePermission
|
|
|
|
|
} = 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
|
|
|
|
|
type={"danger"}
|
|
|
|
|
children={t("config-form.no-read-permission-notification")}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 13:28:46 +02:00
|
|
|
if (this.state.showNotification) {
|
|
|
|
|
noPermissionNotification = (
|
|
|
|
|
<Notification
|
|
|
|
|
type={"info"}
|
2019-03-04 16:47:44 +01:00
|
|
|
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
|
|
|
|
|
realmDescription={config.realmDescription}
|
|
|
|
|
enableRepositoryArchive={config.enableRepositoryArchive}
|
|
|
|
|
disableGroupingGrid={config.disableGroupingGrid}
|
|
|
|
|
dateFormat={config.dateFormat}
|
|
|
|
|
anonymousAccessEnabled={config.anonymousAccessEnabled}
|
|
|
|
|
skipFailedAuthenticators={config.skipFailedAuthenticators}
|
|
|
|
|
pluginUrl={config.pluginUrl}
|
|
|
|
|
enabledXsrfProtection={config.enabledXsrfProtection}
|
|
|
|
|
defaultNamespaceStrategy={config.defaultNamespaceStrategy}
|
|
|
|
|
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 />
|
|
|
|
|
<AdminSettings
|
|
|
|
|
adminGroups={config.adminGroups}
|
|
|
|
|
adminUsers={config.adminUsers}
|
|
|
|
|
onChange={(isValid, changedValue, name) =>
|
|
|
|
|
this.onChange(isValid, changedValue, name)
|
|
|
|
|
}
|
2018-08-16 12:12:59 +02:00
|
|
|
hasUpdatePermission={configUpdatePermission}
|
2018-08-16 10:55:39 +02:00
|
|
|
/>
|
|
|
|
|
<hr />
|
2018-08-13 16:33:56 +02:00
|
|
|
<ProxySettings
|
|
|
|
|
proxyPassword={config.proxyPassword ? config.proxyPassword : ""}
|
|
|
|
|
proxyPort={config.proxyPort}
|
|
|
|
|
proxyServer={config.proxyServer ? config.proxyServer : ""}
|
|
|
|
|
proxyUser={config.proxyUser ? config.proxyUser : ""}
|
|
|
|
|
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}
|
|
|
|
|
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,
|
|
|
|
|
[name]: changedValue
|
2018-08-21 08:40:49 +02:00
|
|
|
},
|
|
|
|
|
error: {
|
|
|
|
|
...this.state.error,
|
|
|
|
|
[name]: !isValid
|
2019-01-02 14:37:25 +01:00
|
|
|
},
|
2019-01-11 08:31:00 +01: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,
|
|
|
|
|
showNotification: false
|
|
|
|
|
});
|
|
|
|
|
};
|
2018-08-13 16:33:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default translate("config")(ConfigForm);
|