2020-03-23 15:35:58 +01:00
|
|
|
/*
|
2024-09-24 09:42:07 +02:00
|
|
|
* Copyright (c) 2020 - present Cloudogu GmbH
|
2020-03-23 15:35:58 +01:00
|
|
|
*
|
2024-09-24 09:42:07 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify it under
|
|
|
|
|
* the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
|
* Software Foundation, version 3.
|
2020-03-23 15:35:58 +01:00
|
|
|
*
|
2024-09-24 09:42:07 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
|
* details.
|
2020-03-23 15:35:58 +01:00
|
|
|
*
|
2024-09-24 09:42:07 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
2020-03-23 15:35:58 +01:00
|
|
|
*/
|
2024-09-24 09:42:07 +02:00
|
|
|
|
2023-06-19 13:04:26 +02:00
|
|
|
import React, { FC, useState } from "react";
|
2021-05-20 08:30:20 +02:00
|
|
|
import { useTranslation } from "react-i18next";
|
2023-06-19 13:04:26 +02:00
|
|
|
import { useUserOptions, Option } from "@scm-manager/ui-api";
|
|
|
|
|
import { AnonymousMode, AutocompleteObject, ConfigChangeHandler, NamespaceStrategies } from "@scm-manager/ui-types";
|
|
|
|
|
import { Checkbox, InputField, Select } from "@scm-manager/ui-components";
|
2019-10-20 18:02:52 +02:00
|
|
|
import NamespaceStrategySelect from "./NamespaceStrategySelect";
|
2023-06-19 13:04:26 +02:00
|
|
|
import { ChipInputField, Combobox } from "@scm-manager/ui-forms";
|
|
|
|
|
import classNames from "classnames";
|
2018-12-20 10:21:18 +01:00
|
|
|
|
2021-05-20 08:30:20 +02:00
|
|
|
type Props = {
|
2019-10-19 16:38:07 +02:00
|
|
|
realmDescription: string;
|
|
|
|
|
loginInfoUrl: string;
|
|
|
|
|
disableGroupingGrid: boolean;
|
|
|
|
|
dateFormat: string;
|
2020-08-03 14:40:39 +02:00
|
|
|
anonymousMode: AnonymousMode;
|
2019-10-19 16:38:07 +02:00
|
|
|
skipFailedAuthenticators: boolean;
|
2022-01-19 11:58:55 +01:00
|
|
|
alertsUrl: string;
|
2020-09-21 15:26:51 +02:00
|
|
|
releaseFeedUrl: string;
|
2020-10-14 08:17:33 +02:00
|
|
|
mailDomainName: string;
|
2019-10-19 16:38:07 +02:00
|
|
|
enabledXsrfProtection: boolean;
|
2021-05-20 08:30:20 +02:00
|
|
|
emergencyContacts: string[];
|
2019-10-19 16:38:07 +02:00
|
|
|
namespaceStrategy: string;
|
|
|
|
|
namespaceStrategies?: NamespaceStrategies;
|
2021-12-09 09:12:02 +01:00
|
|
|
onChange: ConfigChangeHandler;
|
2019-10-19 16:38:07 +02:00
|
|
|
hasUpdatePermission: boolean;
|
2018-12-20 10:21:18 +01:00
|
|
|
};
|
|
|
|
|
|
2021-05-20 08:30:20 +02:00
|
|
|
const GeneralSettings: FC<Props> = ({
|
|
|
|
|
realmDescription,
|
|
|
|
|
loginInfoUrl,
|
|
|
|
|
anonymousMode,
|
2022-01-19 11:58:55 +01:00
|
|
|
alertsUrl,
|
2021-05-20 08:30:20 +02:00
|
|
|
releaseFeedUrl,
|
|
|
|
|
mailDomainName,
|
|
|
|
|
enabledXsrfProtection,
|
|
|
|
|
emergencyContacts,
|
|
|
|
|
namespaceStrategy,
|
|
|
|
|
namespaceStrategies,
|
|
|
|
|
onChange,
|
2023-06-19 13:04:26 +02:00
|
|
|
hasUpdatePermission,
|
2021-05-20 08:30:20 +02:00
|
|
|
}) => {
|
|
|
|
|
const { t } = useTranslation("config");
|
2023-06-19 13:04:26 +02:00
|
|
|
const [query, setQuery] = useState("");
|
|
|
|
|
const { data: userOptions, isLoading: userOptionsLoading } = useUserOptions(query);
|
2018-12-20 10:21:18 +01:00
|
|
|
|
2021-05-20 08:30:20 +02:00
|
|
|
const handleLoginInfoUrlChange = (value: string) => {
|
|
|
|
|
onChange(true, value, "loginInfoUrl");
|
|
|
|
|
};
|
|
|
|
|
const handleRealmDescriptionChange = (value: string) => {
|
|
|
|
|
onChange(true, value, "realmDescription");
|
2019-08-13 09:45:37 +02:00
|
|
|
};
|
2021-05-20 08:30:20 +02:00
|
|
|
const handleEnabledXsrfProtectionChange = (value: boolean) => {
|
|
|
|
|
onChange(true, value, "enabledXsrfProtection");
|
2018-12-20 10:21:18 +01:00
|
|
|
};
|
2021-05-20 08:30:20 +02:00
|
|
|
const handleAnonymousMode = (value: string) => {
|
2021-12-09 09:12:02 +01:00
|
|
|
onChange(true, value as AnonymousMode, "anonymousMode");
|
2020-10-13 16:19:00 +02:00
|
|
|
};
|
2021-05-20 08:30:20 +02:00
|
|
|
const handleNamespaceStrategyChange = (value: string) => {
|
|
|
|
|
onChange(true, value, "namespaceStrategy");
|
2019-10-09 11:38:30 +02:00
|
|
|
};
|
2022-01-19 11:58:55 +01:00
|
|
|
const handleAlertsUrlChange = (value: string) => {
|
|
|
|
|
onChange(true, value, "alertsUrl");
|
|
|
|
|
};
|
2021-05-20 08:30:20 +02:00
|
|
|
const handleReleaseFeedUrlChange = (value: string) => {
|
|
|
|
|
onChange(true, value, "releaseFeedUrl");
|
2019-08-19 12:56:27 +02:00
|
|
|
};
|
2021-05-20 08:30:20 +02:00
|
|
|
const handleMailDomainNameChange = (value: string) => {
|
|
|
|
|
onChange(true, value, "mailDomainName");
|
2020-09-21 15:26:51 +02:00
|
|
|
};
|
2023-06-19 13:04:26 +02:00
|
|
|
const handleEmergencyContactsChange = (p: Option<AutocompleteObject>[]) => {
|
|
|
|
|
onChange(
|
|
|
|
|
true,
|
|
|
|
|
p.map((c) => c.value.id),
|
|
|
|
|
"emergencyContacts"
|
|
|
|
|
);
|
2021-05-20 08:30:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<div className="columns">
|
2023-07-06 08:47:51 +02:00
|
|
|
<div className="column">
|
2021-05-20 08:30:20 +02:00
|
|
|
<InputField
|
|
|
|
|
label={t("general-settings.realm-description")}
|
|
|
|
|
onChange={handleRealmDescriptionChange}
|
|
|
|
|
value={realmDescription}
|
|
|
|
|
disabled={!hasUpdatePermission}
|
|
|
|
|
helpText={t("help.realmDescriptionHelpText")}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2023-07-06 08:47:51 +02:00
|
|
|
</div>
|
|
|
|
|
<div className="columns">
|
|
|
|
|
<div className="column">
|
2021-05-20 08:30:20 +02:00
|
|
|
<NamespaceStrategySelect
|
|
|
|
|
label={t("general-settings.namespace-strategy")}
|
|
|
|
|
onChange={handleNamespaceStrategyChange}
|
|
|
|
|
value={namespaceStrategy}
|
|
|
|
|
disabled={!hasUpdatePermission}
|
|
|
|
|
namespaceStrategies={namespaceStrategies}
|
|
|
|
|
helpText={t("help.nameSpaceStrategyHelpText")}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="columns">
|
2023-07-06 08:47:51 +02:00
|
|
|
<div className="column">
|
2021-05-20 08:30:20 +02:00
|
|
|
<InputField
|
|
|
|
|
label={t("general-settings.login-info-url")}
|
|
|
|
|
onChange={handleLoginInfoUrlChange}
|
|
|
|
|
value={loginInfoUrl}
|
|
|
|
|
disabled={!hasUpdatePermission}
|
|
|
|
|
helpText={t("help.loginInfoUrlHelpText")}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2023-07-06 08:47:51 +02:00
|
|
|
</div>
|
|
|
|
|
<div className="columns">
|
|
|
|
|
<div className="column">
|
2021-05-20 08:30:20 +02:00
|
|
|
<Checkbox
|
|
|
|
|
label={t("general-settings.enabled-xsrf-protection")}
|
|
|
|
|
onChange={handleEnabledXsrfProtectionChange}
|
|
|
|
|
checked={enabledXsrfProtection}
|
|
|
|
|
title={t("general-settings.enabled-xsrf-protection")}
|
|
|
|
|
disabled={!hasUpdatePermission}
|
|
|
|
|
helpText={t("help.enableXsrfProtectionHelpText")}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="columns">
|
2023-07-06 08:47:51 +02:00
|
|
|
<div className="column">
|
2021-05-20 08:30:20 +02:00
|
|
|
<Select
|
|
|
|
|
label={t("general-settings.anonymousMode.title")}
|
|
|
|
|
onChange={handleAnonymousMode}
|
|
|
|
|
value={anonymousMode}
|
|
|
|
|
disabled={!hasUpdatePermission}
|
2021-12-13 15:15:57 +01:00
|
|
|
className="is-fullwidth"
|
2021-05-20 08:30:20 +02:00
|
|
|
options={[
|
2025-06-06 11:27:16 +02:00
|
|
|
{ label: t("general-settings.anonymousMode.full"), value: "FULL" },
|
|
|
|
|
{ label: t("general-settings.anonymousMode.protocolOnly"), value: "PROTOCOL_ONLY" },
|
|
|
|
|
{ label: t("general-settings.anonymousMode.off"), value: "OFF" },
|
2021-05-20 08:30:20 +02:00
|
|
|
]}
|
|
|
|
|
helpText={t("help.allowAnonymousAccessHelpText")}
|
|
|
|
|
testId={"anonymous-mode-select"}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="columns">
|
2023-07-06 08:47:51 +02:00
|
|
|
<div className="column">
|
2021-05-20 08:30:20 +02:00
|
|
|
<InputField
|
|
|
|
|
label={t("general-settings.mail-domain-name")}
|
|
|
|
|
onChange={handleMailDomainNameChange}
|
|
|
|
|
value={mailDomainName}
|
|
|
|
|
disabled={!hasUpdatePermission}
|
|
|
|
|
helpText={t("help.mailDomainNameHelpText")}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-12-13 15:15:57 +01:00
|
|
|
<div className="columns">
|
2023-07-06 08:47:51 +02:00
|
|
|
<div className="column">
|
2022-01-19 11:58:55 +01:00
|
|
|
<InputField
|
|
|
|
|
label={t("general-settings.alerts-url")}
|
|
|
|
|
onChange={handleAlertsUrlChange}
|
|
|
|
|
value={alertsUrl}
|
|
|
|
|
disabled={!hasUpdatePermission}
|
|
|
|
|
helpText={t("help.alertsUrlHelpText")}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2023-07-06 08:47:51 +02:00
|
|
|
</div>
|
|
|
|
|
<div className="columns">
|
|
|
|
|
<div className="column">
|
2021-12-13 15:15:57 +01:00
|
|
|
<InputField
|
|
|
|
|
label={t("general-settings.release-feed-url")}
|
|
|
|
|
onChange={handleReleaseFeedUrlChange}
|
|
|
|
|
value={releaseFeedUrl}
|
|
|
|
|
disabled={!hasUpdatePermission}
|
|
|
|
|
helpText={t("help.releaseFeedUrlHelpText")}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-05-20 08:30:20 +02:00
|
|
|
<div className="columns">
|
|
|
|
|
<div className="column is-full">
|
2023-06-19 13:04:26 +02:00
|
|
|
<ChipInputField<AutocompleteObject>
|
2021-05-20 08:30:20 +02:00
|
|
|
label={t("general-settings.emergencyContacts.label")}
|
|
|
|
|
helpText={t("general-settings.emergencyContacts.helpText")}
|
|
|
|
|
placeholder={t("general-settings.emergencyContacts.autocompletePlaceholder")}
|
2023-06-19 13:04:26 +02:00
|
|
|
aria-label="general-settings.emergencyContacts.ariaLabel"
|
2025-06-06 11:27:16 +02:00
|
|
|
value={emergencyContacts.map((m) => ({ label: m, value: { id: m, displayName: m } }))}
|
2023-06-19 13:04:26 +02:00
|
|
|
onChange={handleEmergencyContactsChange}
|
|
|
|
|
>
|
|
|
|
|
<Combobox<AutocompleteObject>
|
|
|
|
|
options={userOptions || []}
|
2025-06-06 11:27:16 +02:00
|
|
|
className={classNames({ "is-loading": userOptionsLoading })}
|
2023-06-19 13:04:26 +02:00
|
|
|
onQueryChange={setQuery}
|
|
|
|
|
/>
|
|
|
|
|
</ChipInputField>
|
2021-05-20 08:30:20 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default GeneralSettings;
|