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";
|
2019-10-23 15:47:08 +02:00
|
|
|
import { WithTranslation, withTranslation } from "react-i18next";
|
2019-01-24 08:05:28 +01:00
|
|
|
import {
|
2019-08-15 10:51:36 +02:00
|
|
|
createPermission,
|
|
|
|
|
createPermissionReset,
|
|
|
|
|
deletePermissionReset,
|
2019-01-24 08:05:28 +01:00
|
|
|
fetchAvailablePermissionsIfNeeded,
|
|
|
|
|
fetchPermissions,
|
2019-01-24 09:53:26 +01:00
|
|
|
getAvailablePermissions,
|
2019-08-15 10:51:36 +02:00
|
|
|
getAvailableRepositoryRoles,
|
|
|
|
|
getAvailableRepositoryVerbs,
|
|
|
|
|
getCreatePermissionFailure,
|
|
|
|
|
getDeletePermissionsFailure,
|
|
|
|
|
getFetchAvailablePermissionsFailure,
|
2019-01-24 08:05:28 +01:00
|
|
|
getFetchPermissionsFailure,
|
2019-08-15 10:51:36 +02:00
|
|
|
getModifyPermissionsFailure,
|
2019-01-24 08:05:28 +01:00
|
|
|
getPermissionsOfRepo,
|
|
|
|
|
hasCreatePermission,
|
|
|
|
|
isCreatePermissionPending,
|
2019-08-15 10:51:36 +02:00
|
|
|
isFetchAvailablePermissionsPending,
|
|
|
|
|
isFetchPermissionsPending,
|
2019-10-20 18:02:52 +02:00
|
|
|
modifyPermissionReset
|
|
|
|
|
} from "../modules/permissions";
|
2019-10-21 10:57:56 +02:00
|
|
|
import { ErrorPage, LabelWithHelpIcon, Loading, Subtitle } from "@scm-manager/ui-components";
|
|
|
|
|
import { Permission, PermissionCollection, PermissionCreateEntry, RepositoryRole } from "@scm-manager/ui-types";
|
2019-10-20 18:02:52 +02:00
|
|
|
import SinglePermission from "./SinglePermission";
|
|
|
|
|
import CreatePermissionForm from "./CreatePermissionForm";
|
|
|
|
|
import { History } from "history";
|
|
|
|
|
import { getPermissionsLink } from "../../modules/repos";
|
2019-01-24 08:05:28 +01:00
|
|
|
import {
|
2019-05-15 15:52:16 +02:00
|
|
|
getGroupAutoCompleteLink,
|
|
|
|
|
getRepositoryRolesLink,
|
|
|
|
|
getRepositoryVerbsLink,
|
2019-10-20 18:02:52 +02:00
|
|
|
getUserAutoCompleteLink
|
|
|
|
|
} from "../../../modules/indexResource";
|
2019-10-23 15:47:08 +02:00
|
|
|
type Props = WithTranslation & {
|
2019-10-19 16:38:07 +02:00
|
|
|
availablePermissions: boolean;
|
|
|
|
|
availableRepositoryRoles: RepositoryRole[];
|
|
|
|
|
availableVerbs: string[];
|
|
|
|
|
namespace: string;
|
2020-09-17 07:49:37 +02:00
|
|
|
repoName?: string;
|
2019-10-19 16:38:07 +02:00
|
|
|
loading: boolean;
|
|
|
|
|
error: Error;
|
|
|
|
|
permissions: PermissionCollection;
|
|
|
|
|
hasPermissionToCreate: boolean;
|
|
|
|
|
loadingCreatePermission: boolean;
|
|
|
|
|
repositoryRolesLink: string;
|
|
|
|
|
repositoryVerbsLink: string;
|
|
|
|
|
permissionsLink: string;
|
|
|
|
|
groupAutocompleteLink: string;
|
|
|
|
|
userAutocompleteLink: string;
|
2019-01-24 08:05:28 +01:00
|
|
|
|
2019-10-23 15:47:08 +02:00
|
|
|
// dispatch functions
|
2019-10-21 10:57:56 +02:00
|
|
|
fetchAvailablePermissionsIfNeeded: (repositoryRolesLink: string, repositoryVerbsLink: string) => void;
|
2020-09-17 07:49:37 +02:00
|
|
|
fetchPermissions: (link: string, namespace: string, repoName?: string) => void;
|
2019-01-24 08:05:28 +01:00
|
|
|
createPermission: (
|
|
|
|
|
link: string,
|
|
|
|
|
permission: PermissionCreateEntry,
|
|
|
|
|
namespace: string,
|
2020-09-17 07:49:37 +02:00
|
|
|
repoName?: string,
|
2019-10-20 18:02:52 +02:00
|
|
|
callback?: () => void
|
2019-10-19 16:38:07 +02:00
|
|
|
) => void;
|
2020-09-17 07:49:37 +02:00
|
|
|
createPermissionReset: (namespace: string, repoName?: string) => void;
|
|
|
|
|
modifyPermissionReset: (namespace: string, repoName?: string) => void;
|
|
|
|
|
deletePermissionReset: (namespace: string, repoName?: string) => void;
|
2019-10-23 15:47:08 +02:00
|
|
|
|
2019-01-24 08:05:28 +01:00
|
|
|
// context props
|
2019-10-19 16:38:07 +02:00
|
|
|
match: any;
|
|
|
|
|
history: History;
|
2019-01-24 08:05:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Permissions extends React.Component<Props> {
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
const {
|
|
|
|
|
fetchAvailablePermissionsIfNeeded,
|
|
|
|
|
fetchPermissions,
|
|
|
|
|
namespace,
|
|
|
|
|
repoName,
|
|
|
|
|
modifyPermissionReset,
|
|
|
|
|
createPermissionReset,
|
|
|
|
|
deletePermissionReset,
|
2019-05-13 15:44:43 +02:00
|
|
|
permissionsLink,
|
|
|
|
|
repositoryRolesLink,
|
2019-10-20 18:02:52 +02:00
|
|
|
repositoryVerbsLink
|
2019-01-24 08:05:28 +01:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
createPermissionReset(namespace, repoName);
|
|
|
|
|
modifyPermissionReset(namespace, repoName);
|
|
|
|
|
deletePermissionReset(namespace, repoName);
|
2019-05-13 15:44:43 +02:00
|
|
|
fetchAvailablePermissionsIfNeeded(repositoryRolesLink, repositoryVerbsLink);
|
2019-01-24 08:05:28 +01:00
|
|
|
fetchPermissions(permissionsLink, namespace, repoName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createPermission = (permission: Permission) => {
|
2019-10-21 10:57:56 +02:00
|
|
|
this.props.createPermission(this.props.permissionsLink, permission, this.props.namespace, this.props.repoName);
|
2019-01-24 08:05:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const {
|
2019-01-24 09:53:26 +01:00
|
|
|
availablePermissions,
|
2019-05-13 15:44:43 +02:00
|
|
|
availableRepositoryRoles,
|
|
|
|
|
availableVerbs,
|
2019-01-24 08:05:28 +01:00
|
|
|
loading,
|
|
|
|
|
error,
|
|
|
|
|
permissions,
|
|
|
|
|
t,
|
|
|
|
|
namespace,
|
|
|
|
|
repoName,
|
|
|
|
|
loadingCreatePermission,
|
|
|
|
|
hasPermissionToCreate,
|
2019-06-12 09:47:13 +02:00
|
|
|
userAutocompleteLink,
|
2019-10-20 18:02:52 +02:00
|
|
|
groupAutocompleteLink
|
2019-01-24 08:05:28 +01:00
|
|
|
} = this.props;
|
|
|
|
|
if (error) {
|
2019-10-21 10:57:56 +02:00
|
|
|
return <ErrorPage title={t("permission.error-title")} subtitle={t("permission.error-subtitle")} error={error} />;
|
2019-01-24 08:05:28 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-24 09:53:26 +01:00
|
|
|
if (loading || !permissions || !availablePermissions) {
|
2019-01-24 08:05:28 +01:00
|
|
|
return <Loading />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const createPermissionForm = hasPermissionToCreate ? (
|
|
|
|
|
<CreatePermissionForm
|
2019-05-13 15:44:43 +02:00
|
|
|
availableRoles={availableRepositoryRoles}
|
|
|
|
|
availableVerbs={availableVerbs}
|
2019-01-24 08:05:28 +01:00
|
|
|
createPermission={permission => this.createPermission(permission)}
|
|
|
|
|
loading={loadingCreatePermission}
|
|
|
|
|
currentPermissions={permissions}
|
2019-06-12 09:47:13 +02:00
|
|
|
userAutocompleteLink={userAutocompleteLink}
|
|
|
|
|
groupAutocompleteLink={groupAutocompleteLink}
|
2019-01-24 08:05:28 +01:00
|
|
|
/>
|
|
|
|
|
) : null;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
2019-10-20 18:02:52 +02:00
|
|
|
<Subtitle subtitle={t("permission.title")} />
|
2019-05-24 09:26:27 +02:00
|
|
|
<table className="card-table table is-hoverable is-fullwidth">
|
2019-01-24 08:05:28 +01:00
|
|
|
<thead>
|
|
|
|
|
<tr>
|
2019-01-25 12:32:19 +01:00
|
|
|
<th>
|
2019-10-21 10:57:56 +02:00
|
|
|
<LabelWithHelpIcon label={t("permission.name")} helpText={t("permission.help.nameHelpText")} />
|
2019-01-25 12:32:19 +01:00
|
|
|
</th>
|
|
|
|
|
<th>
|
2019-10-21 10:57:56 +02:00
|
|
|
<LabelWithHelpIcon label={t("permission.role")} helpText={t("permission.help.roleHelpText")} />
|
2019-01-25 12:32:19 +01:00
|
|
|
</th>
|
|
|
|
|
<th>
|
|
|
|
|
<LabelWithHelpIcon
|
2019-10-20 18:02:52 +02:00
|
|
|
label={t("permission.permissions")}
|
|
|
|
|
helpText={t("permission.help.permissionsHelpText")}
|
2019-01-25 12:32:19 +01:00
|
|
|
/>
|
2019-01-24 08:05:28 +01:00
|
|
|
</th>
|
2019-01-24 13:34:05 +01:00
|
|
|
<th />
|
2019-01-24 08:05:28 +01:00
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
{permissions.map(permission => {
|
|
|
|
|
return (
|
|
|
|
|
<SinglePermission
|
2019-05-13 15:44:43 +02:00
|
|
|
availableRepositoryRoles={availableRepositoryRoles}
|
|
|
|
|
availableRepositoryVerbs={availableVerbs}
|
2019-01-24 08:05:28 +01:00
|
|
|
key={permission.name + permission.groupPermission.toString()}
|
|
|
|
|
namespace={namespace}
|
|
|
|
|
repoName={repoName}
|
|
|
|
|
permission={permission}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
{createPermissionForm}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-08 13:40:07 +01:00
|
|
|
const mapStateToProps = (state: any, ownProps: Props) => {
|
2019-01-24 08:05:28 +01:00
|
|
|
const namespace = ownProps.namespace;
|
|
|
|
|
const repoName = ownProps.repoName;
|
|
|
|
|
const error =
|
|
|
|
|
getFetchPermissionsFailure(state, namespace, repoName) ||
|
|
|
|
|
getCreatePermissionFailure(state, namespace, repoName) ||
|
|
|
|
|
getDeletePermissionsFailure(state, namespace, repoName) ||
|
|
|
|
|
getModifyPermissionsFailure(state, namespace, repoName) ||
|
|
|
|
|
getFetchAvailablePermissionsFailure(state);
|
2019-10-21 10:57:56 +02:00
|
|
|
const loading = isFetchPermissionsPending(state, namespace, repoName) || isFetchAvailablePermissionsPending(state);
|
2019-01-24 08:05:28 +01:00
|
|
|
const permissions = getPermissionsOfRepo(state, namespace, repoName);
|
2019-10-21 10:57:56 +02:00
|
|
|
const loadingCreatePermission = isCreatePermissionPending(state, namespace, repoName);
|
2019-01-24 08:05:28 +01:00
|
|
|
const hasPermissionToCreate = hasCreatePermission(state, namespace, repoName);
|
2019-05-13 15:44:43 +02:00
|
|
|
const repositoryRolesLink = getRepositoryRolesLink(state);
|
|
|
|
|
const repositoryVerbsLink = getRepositoryVerbsLink(state);
|
2019-01-24 08:05:28 +01:00
|
|
|
const permissionsLink = getPermissionsLink(state, namespace, repoName);
|
2019-06-12 09:47:13 +02:00
|
|
|
const groupAutocompleteLink = getGroupAutoCompleteLink(state);
|
|
|
|
|
const userAutocompleteLink = getUserAutoCompleteLink(state);
|
2019-01-24 09:53:26 +01:00
|
|
|
const availablePermissions = getAvailablePermissions(state);
|
2019-05-13 15:44:43 +02:00
|
|
|
const availableRepositoryRoles = getAvailableRepositoryRoles(state);
|
|
|
|
|
const availableVerbs = getAvailableRepositoryVerbs(state);
|
|
|
|
|
|
2019-01-24 08:05:28 +01:00
|
|
|
return {
|
2019-01-24 09:53:26 +01:00
|
|
|
availablePermissions,
|
2019-05-13 15:44:43 +02:00
|
|
|
availableRepositoryRoles,
|
|
|
|
|
availableVerbs,
|
2019-01-24 08:05:28 +01:00
|
|
|
namespace,
|
|
|
|
|
repoName,
|
2019-05-13 15:44:43 +02:00
|
|
|
repositoryRolesLink,
|
|
|
|
|
repositoryVerbsLink,
|
2019-01-24 08:05:28 +01:00
|
|
|
error,
|
|
|
|
|
loading,
|
|
|
|
|
permissions,
|
|
|
|
|
hasPermissionToCreate,
|
|
|
|
|
loadingCreatePermission,
|
|
|
|
|
permissionsLink,
|
2019-06-12 09:47:13 +02:00
|
|
|
groupAutocompleteLink,
|
2019-10-20 18:02:52 +02:00
|
|
|
userAutocompleteLink
|
2019-01-24 08:05:28 +01:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-08 13:40:07 +01:00
|
|
|
const mapDispatchToProps = (dispatch: any) => {
|
2019-01-24 08:05:28 +01:00
|
|
|
return {
|
2020-09-17 07:49:37 +02:00
|
|
|
fetchPermissions: (link: string, namespace: string, repoName?: string) => {
|
2019-01-24 08:05:28 +01:00
|
|
|
dispatch(fetchPermissions(link, namespace, repoName));
|
|
|
|
|
},
|
2019-10-21 10:57:56 +02:00
|
|
|
fetchAvailablePermissionsIfNeeded: (repositoryRolesLink: string, repositoryVerbsLink: string) => {
|
|
|
|
|
dispatch(fetchAvailablePermissionsIfNeeded(repositoryRolesLink, repositoryVerbsLink));
|
2019-01-24 08:05:28 +01:00
|
|
|
},
|
|
|
|
|
createPermission: (
|
|
|
|
|
link: string,
|
|
|
|
|
permission: PermissionCreateEntry,
|
|
|
|
|
namespace: string,
|
|
|
|
|
repoName: string,
|
2019-10-20 18:02:52 +02:00
|
|
|
callback?: () => void
|
2019-01-24 08:05:28 +01:00
|
|
|
) => {
|
2019-10-21 10:57:56 +02:00
|
|
|
dispatch(createPermission(link, permission, namespace, repoName, callback));
|
2019-01-24 08:05:28 +01:00
|
|
|
},
|
2020-09-17 07:49:37 +02:00
|
|
|
createPermissionReset: (namespace: string, repoName?: string) => {
|
2019-01-24 08:05:28 +01:00
|
|
|
dispatch(createPermissionReset(namespace, repoName));
|
|
|
|
|
},
|
2020-09-17 07:49:37 +02:00
|
|
|
modifyPermissionReset: (namespace: string, repoName?: string) => {
|
2019-01-24 08:05:28 +01:00
|
|
|
dispatch(modifyPermissionReset(namespace, repoName));
|
|
|
|
|
},
|
2020-09-17 07:49:37 +02:00
|
|
|
deletePermissionReset: (namespace: string, repoName?: string) => {
|
2019-01-24 08:05:28 +01:00
|
|
|
dispatch(deletePermissionReset(namespace, repoName));
|
2019-10-20 18:02:52 +02:00
|
|
|
}
|
2019-01-24 08:05:28 +01:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2020-01-08 13:40:07 +01:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(withTranslation("repos")(Permissions));
|