2020-03-23 15:35:58 +01:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2019-10-20 18:02:52 +02:00
|
|
|
import React from "react";
|
|
|
|
|
import { connect } from "react-redux";
|
2020-02-26 15:45:24 +01:00
|
|
|
import { Route, RouteComponentProps } from "react-router-dom";
|
2019-10-23 15:47:08 +02:00
|
|
|
import { ExtensionPoint } from "@scm-manager/ui-extensions";
|
|
|
|
|
import { User } from "@scm-manager/ui-types";
|
2020-02-26 15:45:24 +01:00
|
|
|
import {
|
|
|
|
|
ErrorPage,
|
|
|
|
|
Loading,
|
|
|
|
|
NavLink,
|
|
|
|
|
Page,
|
2020-03-25 15:35:46 +01:00
|
|
|
CustomQueryFlexWrappedColumns,
|
|
|
|
|
PrimaryContentColumn,
|
|
|
|
|
SecondaryNavigationColumn,
|
2020-03-11 15:47:40 +01:00
|
|
|
SecondaryNavigation,
|
2020-03-25 15:35:46 +01:00
|
|
|
SubNavigation,
|
2020-03-31 11:00:07 +02:00
|
|
|
StateMenuContextProvider
|
2020-02-26 15:45:24 +01:00
|
|
|
} from "@scm-manager/ui-components";
|
2019-10-20 18:02:52 +02:00
|
|
|
import { Details } from "./../components/table";
|
|
|
|
|
import EditUser from "./EditUser";
|
2020-01-08 15:57:13 +01:00
|
|
|
import { fetchUserByName, getFetchUserFailure, getUserByName, isFetchUserPending } from "../modules/users";
|
2020-07-24 14:59:28 +02:00
|
|
|
import { EditUserNavLink, SetPasswordNavLink, SetPermissionsNavLink, SetPublicKeysNavLink } from "./../components/navLinks";
|
2019-10-23 15:47:08 +02:00
|
|
|
import { WithTranslation, withTranslation } from "react-i18next";
|
2020-08-27 13:20:43 +02:00
|
|
|
import { mustGetUsersLink } from "../../modules/indexResource";
|
2019-10-20 18:02:52 +02:00
|
|
|
import SetUserPassword from "../components/SetUserPassword";
|
|
|
|
|
import SetPermissions from "../../permissions/components/SetPermissions";
|
2020-07-24 14:59:28 +02:00
|
|
|
import SetPublicKeys from "../components/publicKeys/SetPublicKeys";
|
2020-09-18 17:20:54 +02:00
|
|
|
import { urls } from "@scm-manager/ui-components";
|
2018-07-26 10:19:26 +02:00
|
|
|
|
2020-02-26 15:45:24 +01:00
|
|
|
type Props = RouteComponentProps &
|
|
|
|
|
WithTranslation & {
|
|
|
|
|
name: string;
|
|
|
|
|
user: User;
|
|
|
|
|
loading: boolean;
|
|
|
|
|
error: Error;
|
|
|
|
|
usersLink: string;
|
2018-07-30 13:38:15 +02:00
|
|
|
|
2020-02-26 15:45:24 +01:00
|
|
|
// dispatcher function
|
|
|
|
|
fetchUserByName: (p1: string, p2: string) => void;
|
|
|
|
|
};
|
2018-07-30 13:38:15 +02:00
|
|
|
|
2020-03-31 11:00:07 +02:00
|
|
|
class SingleUser extends React.Component<Props> {
|
2018-07-25 13:21:49 +02:00
|
|
|
componentDidMount() {
|
2018-11-05 13:14:52 +01:00
|
|
|
this.props.fetchUserByName(this.props.usersLink, this.props.name);
|
2018-07-25 13:21:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2018-07-30 13:38:15 +02:00
|
|
|
const { t, loading, error, user } = this.props;
|
2018-07-25 13:21:49 +02:00
|
|
|
|
2018-07-30 13:38:15 +02:00
|
|
|
if (error) {
|
2019-10-21 10:57:56 +02:00
|
|
|
return <ErrorPage title={t("singleUser.errorTitle")} subtitle={t("singleUser.errorSubtitle")} error={error} />;
|
2018-07-25 13:21:49 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-30 13:38:15 +02:00
|
|
|
if (!user || loading) {
|
|
|
|
|
return <Loading />;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-18 17:38:10 +02:00
|
|
|
const url = urls.matchedUrl(this.props);
|
2018-07-25 13:21:49 +02:00
|
|
|
|
2019-01-23 15:42:15 +01:00
|
|
|
const extensionProps = {
|
|
|
|
|
user,
|
2019-10-20 18:02:52 +02:00
|
|
|
url
|
2019-01-23 15:42:15 +01:00
|
|
|
};
|
|
|
|
|
|
2018-07-25 13:21:49 +02:00
|
|
|
return (
|
2020-03-31 11:00:07 +02:00
|
|
|
<StateMenuContextProvider>
|
2020-02-26 15:45:24 +01:00
|
|
|
<Page title={user.displayName}>
|
2020-03-25 15:35:46 +01:00
|
|
|
<CustomQueryFlexWrappedColumns>
|
2020-03-31 11:00:07 +02:00
|
|
|
<PrimaryContentColumn>
|
2020-02-26 15:45:24 +01:00
|
|
|
<Route path={url} exact component={() => <Details user={user} />} />
|
|
|
|
|
<Route path={`${url}/settings/general`} component={() => <EditUser user={user} />} />
|
|
|
|
|
<Route path={`${url}/settings/password`} component={() => <SetUserPassword user={user} />} />
|
|
|
|
|
<Route
|
|
|
|
|
path={`${url}/settings/permissions`}
|
|
|
|
|
component={() => <SetPermissions selectedPermissionsLink={user._links.permissions} />}
|
|
|
|
|
/>
|
2020-07-24 14:59:28 +02:00
|
|
|
<Route
|
|
|
|
|
path={`${url}/settings/publickeys`}
|
|
|
|
|
component={() => <SetPublicKeys user={user} />}
|
|
|
|
|
/>
|
2020-02-26 15:45:24 +01:00
|
|
|
<ExtensionPoint name="user.route" props={extensionProps} renderAll={true} />
|
2020-03-25 15:35:46 +01:00
|
|
|
</PrimaryContentColumn>
|
2020-03-31 11:00:07 +02:00
|
|
|
<SecondaryNavigationColumn>
|
|
|
|
|
<SecondaryNavigation label={t("singleUser.menu.navigationLabel")}>
|
2020-03-10 10:45:37 +01:00
|
|
|
<NavLink
|
|
|
|
|
to={`${url}`}
|
|
|
|
|
icon="fas fa-info-circle"
|
|
|
|
|
label={t("singleUser.menu.informationNavLink")}
|
|
|
|
|
title={t("singleUser.menu.informationNavLink")}
|
2020-08-11 10:34:29 +02:00
|
|
|
testId="user-information-link"
|
2020-03-10 10:45:37 +01:00
|
|
|
/>
|
|
|
|
|
<SubNavigation
|
|
|
|
|
to={`${url}/settings/general`}
|
|
|
|
|
label={t("singleUser.menu.settingsNavLink")}
|
|
|
|
|
title={t("singleUser.menu.settingsNavLink")}
|
2020-08-11 10:34:29 +02:00
|
|
|
testId="user-settings-link"
|
2020-02-26 15:45:24 +01:00
|
|
|
>
|
2020-03-10 10:45:37 +01:00
|
|
|
<EditUserNavLink user={user} editUrl={`${url}/settings/general`} />
|
|
|
|
|
<SetPasswordNavLink user={user} passwordUrl={`${url}/settings/password`} />
|
|
|
|
|
<SetPermissionsNavLink user={user} permissionsUrl={`${url}/settings/permissions`} />
|
2020-07-24 14:59:28 +02:00
|
|
|
<SetPublicKeysNavLink user={user} publicKeyUrl={`${url}/settings/publickeys`} />
|
2020-03-10 10:45:37 +01:00
|
|
|
<ExtensionPoint name="user.setting" props={extensionProps} renderAll={true} />
|
|
|
|
|
</SubNavigation>
|
2020-03-11 15:47:40 +01:00
|
|
|
</SecondaryNavigation>
|
2020-03-25 15:35:46 +01:00
|
|
|
</SecondaryNavigationColumn>
|
|
|
|
|
</CustomQueryFlexWrappedColumns>
|
2020-02-26 15:45:24 +01:00
|
|
|
</Page>
|
2020-03-31 11:00:07 +02:00
|
|
|
</StateMenuContextProvider>
|
2018-07-25 13:21:49 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-08 13:40:07 +01:00
|
|
|
const mapStateToProps = (state: any, ownProps: Props) => {
|
2018-07-25 13:21:49 +02:00
|
|
|
const name = ownProps.match.params.name;
|
2018-07-30 13:38:15 +02:00
|
|
|
const user = getUserByName(state, name);
|
2019-01-18 15:26:55 +01:00
|
|
|
const loading = isFetchUserPending(state, name);
|
|
|
|
|
const error = getFetchUserFailure(state, name);
|
2020-08-27 13:20:43 +02:00
|
|
|
const usersLink = mustGetUsersLink(state);
|
2018-07-25 13:21:49 +02:00
|
|
|
return {
|
2018-10-09 16:40:44 +02:00
|
|
|
usersLink,
|
2018-07-25 13:21:49 +02:00
|
|
|
name,
|
2018-07-30 13:38:15 +02:00
|
|
|
user,
|
|
|
|
|
loading,
|
2019-10-20 18:02:52 +02:00
|
|
|
error
|
2018-07-25 13:21:49 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-08 13:40:07 +01:00
|
|
|
const mapDispatchToProps = (dispatch: any) => {
|
2018-07-25 13:21:49 +02:00
|
|
|
return {
|
2018-11-05 13:14:52 +01:00
|
|
|
fetchUserByName: (link: string, name: string) => {
|
|
|
|
|
dispatch(fetchUserByName(link, name));
|
2019-10-20 18:02:52 +02:00
|
|
|
}
|
2018-07-25 13:21:49 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-08 13:40:07 +01:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(withTranslation("users")(SingleUser));
|