mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 16:05:44 +01:00
Merged in feature/custom_roles_overview (pull request #250)
custom roles overview
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import type {
|
||||
RepositoryRole,
|
||||
PermissionCollection,
|
||||
PermissionCreateEntry,
|
||||
SelectValue
|
||||
} from "@scm-manager/ui-types";
|
||||
import {
|
||||
Subtitle,
|
||||
Autocomplete,
|
||||
@@ -9,30 +15,28 @@ import {
|
||||
LabelWithHelpIcon,
|
||||
Radio
|
||||
} from "@scm-manager/ui-components";
|
||||
import RoleSelector from "../components/RoleSelector";
|
||||
import type {
|
||||
AvailableRepositoryPermissions,
|
||||
PermissionCollection,
|
||||
PermissionCreateEntry,
|
||||
SelectValue
|
||||
} from "@scm-manager/ui-types";
|
||||
import * as validator from "../components/permissionValidation";
|
||||
import { findMatchingRoleName } from "../modules/permissions";
|
||||
import RoleSelector from "../components/RoleSelector";
|
||||
import AdvancedPermissionsDialog from "./AdvancedPermissionsDialog";
|
||||
import { findVerbsForRole } from "../modules/permissions";
|
||||
|
||||
type Props = {
|
||||
t: string => string,
|
||||
availablePermissions: AvailableRepositoryPermissions,
|
||||
availableRoles: RepositoryRole[],
|
||||
availableVerbs: string[],
|
||||
createPermission: (permission: PermissionCreateEntry) => void,
|
||||
loading: boolean,
|
||||
currentPermissions: PermissionCollection,
|
||||
groupAutoCompleteLink: string,
|
||||
userAutoCompleteLink: string
|
||||
userAutoCompleteLink: string,
|
||||
|
||||
// Context props
|
||||
t: string => string
|
||||
};
|
||||
|
||||
type State = {
|
||||
name: string,
|
||||
verbs: string[],
|
||||
role?: string,
|
||||
verbs?: string[],
|
||||
groupPermission: boolean,
|
||||
valid: boolean,
|
||||
value?: SelectValue,
|
||||
@@ -45,7 +49,8 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
|
||||
this.state = {
|
||||
name: "",
|
||||
verbs: props.availablePermissions.availableRoles[0].verbs,
|
||||
role: props.availableRoles[0].name,
|
||||
verbs: undefined,
|
||||
groupPermission: false,
|
||||
valid: true,
|
||||
value: undefined,
|
||||
@@ -90,6 +95,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
renderAutocompletionField = () => {
|
||||
const { t } = this.props;
|
||||
if (this.state.groupPermission) {
|
||||
@@ -133,19 +139,17 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
};
|
||||
|
||||
render() {
|
||||
const { t, availablePermissions, loading } = this.props;
|
||||
const { t, availableRoles, availableVerbs, loading } = this.props;
|
||||
const { role, verbs, showAdvancedDialog } = this.state;
|
||||
|
||||
const { verbs, showAdvancedDialog } = this.state;
|
||||
const availableRoleNames = availableRoles.map(r => r.name);
|
||||
|
||||
const availableRoleNames = availablePermissions.availableRoles.map(
|
||||
r => r.name
|
||||
);
|
||||
const matchingRole = findMatchingRoleName(availablePermissions, verbs);
|
||||
const selectedVerbs = role ? findVerbsForRole(availableRoles, role) : verbs;
|
||||
|
||||
const advancedDialog = showAdvancedDialog ? (
|
||||
<AdvancedPermissionsDialog
|
||||
availableVerbs={availablePermissions.availableVerbs}
|
||||
selectedVerbs={verbs}
|
||||
availableVerbs={availableVerbs}
|
||||
selectedVerbs={selectedVerbs}
|
||||
onClose={this.closeAdvancedPermissionsDialog}
|
||||
onSubmit={this.submitAdvancedPermissionsDialog}
|
||||
/>
|
||||
@@ -187,7 +191,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
label={t("permission.role")}
|
||||
helpText={t("permission.help.roleHelpText")}
|
||||
handleRoleChange={this.handleRoleChange}
|
||||
role={matchingRole}
|
||||
role={role}
|
||||
/>
|
||||
</div>
|
||||
<div className="column">
|
||||
@@ -228,6 +232,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
submitAdvancedPermissionsDialog = (newVerbs: string[]) => {
|
||||
this.setState({
|
||||
showAdvancedDialog: false,
|
||||
role: undefined,
|
||||
verbs: newVerbs
|
||||
});
|
||||
};
|
||||
@@ -235,6 +240,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
submit = e => {
|
||||
this.props.createPermission({
|
||||
name: this.state.name,
|
||||
role: this.state.role,
|
||||
verbs: this.state.verbs,
|
||||
groupPermission: this.state.groupPermission
|
||||
});
|
||||
@@ -245,7 +251,8 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
removeState = () => {
|
||||
this.setState({
|
||||
name: "",
|
||||
verbs: this.props.availablePermissions.availableRoles[0].verbs,
|
||||
role: this.props.availableRoles[0].name,
|
||||
verbs: undefined,
|
||||
valid: true,
|
||||
value: undefined
|
||||
});
|
||||
@@ -257,14 +264,13 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
||||
return;
|
||||
}
|
||||
this.setState({
|
||||
verbs: selectedRole.verbs
|
||||
role: selectedRole.name,
|
||||
verbs: []
|
||||
});
|
||||
};
|
||||
|
||||
findAvailableRole = (roleName: string) => {
|
||||
return this.props.availablePermissions.availableRoles.find(
|
||||
role => role.name === roleName
|
||||
);
|
||||
return this.props.availableRoles.find(role => role.name === roleName);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user