diff --git a/scm-ui/ui-webapp/public/locales/de/users.json b/scm-ui/ui-webapp/public/locales/de/users.json index 9d32fc279a..a5b2da64af 100644 --- a/scm-ui/ui-webapp/public/locales/de/users.json +++ b/scm-ui/ui-webapp/public/locales/de/users.json @@ -63,10 +63,16 @@ }, "userForm": { "subtitle": "Benutzer bearbeiten", - "button": "Speichern", + "userIsInternal": "Der Benutzer wird vom SCM-Manager verwaltet", + "userIsExternal": "Der Benutzer wird von einem externen System verwaltet", + "button": { + "submit": "Speichern", + "convertToExternal": "Zu externem Benutzer konvertieren", + "convertToInternal": "Zu internem Benutzer konvertieren" + }, "modal": { "passwordRequired": "Neues Passwort für internen Benutzer setzen", - "setPassword": "Passwort setzen" + "convertToInternal": "Zu internem Benutzer konvertieren" } }, "publicKey": { diff --git a/scm-ui/ui-webapp/public/locales/en/users.json b/scm-ui/ui-webapp/public/locales/en/users.json index d09e450d40..48281c3486 100644 --- a/scm-ui/ui-webapp/public/locales/en/users.json +++ b/scm-ui/ui-webapp/public/locales/en/users.json @@ -63,10 +63,16 @@ }, "userForm": { "subtitle": "Edit User", - "button": "Submit", + "userIsInternal": "This user is managed by SCM-Manager", + "userIsExternal": "This user is managed by an external system", + "button": { + "submit": "Submit", + "convertToExternal": "Convert to external", + "convertToInternal": "Convert to internal" + }, "modal": { - "setPassword": "Set password", - "passwordRequired": "Set new password for internal user" + "passwordRequired": "Set new password for internal user", + "convertToInternal": "Convert to internal" } }, "publicKey": { diff --git a/scm-ui/ui-webapp/src/users/components/UserConverter.tsx b/scm-ui/ui-webapp/src/users/components/UserConverter.tsx new file mode 100644 index 0000000000..b565fadcc1 --- /dev/null +++ b/scm-ui/ui-webapp/src/users/components/UserConverter.tsx @@ -0,0 +1,130 @@ +/* + * MIT License + * + * Copyright (c) 2020-present Cloudogu GmbH and Contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +import React, { FC, useState } from "react"; +import { + Button, + Modal, + PasswordConfirmation, + SubmitButton, + ErrorNotification, + Level +} from "@scm-manager/ui-components"; +import { useTranslation } from "react-i18next"; +import { Link, User } from "@scm-manager/ui-types"; +import { convertToExternal, convertToInternal } from "./convertUser"; +import styled from "styled-components"; + +const ExternalDescription = styled.div` + display: flex; + align-items: center; + font-size: 1.25rem; + font-weight: 400; +`; + +type Props = { + user: User; + fetchUser: (user: User) => void; +}; + +const UserConverter: FC = ({ user, fetchUser }) => { + const [t] = useTranslation("users"); + const [showPasswordModal, setShowPasswordModal] = useState(false); + const [password, setPassword] = useState(""); + const [passwordValid, setPasswordValid] = useState(false); + const [error, setError] = useState(); + + const toInternal = () => { + convertToInternal((user._links.convertToInternal as Link).href, password) + .then(() => fetchUser(user)) + .then(() => setShowPasswordModal(false)) + .catch(setError); + }; + + const toExternal = () => { + convertToExternal((user._links.convertToExternal as Link).href) + .then(() => fetchUser(user)) + .catch(setError); + }; + + const changePassword = (password: string, valid: boolean) => { + setPassword(password); + setPasswordValid(valid); + }; + + const getUserExternalDescription = () => { + if (user.external) { + return t("userForm.userIsExternal"); + } else { + return t("userForm.userIsInternal"); + } + }; + + const getConvertButton = () => { + if (user.external) { + return ( +