mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 06:25:45 +01:00
add role to RepositoryPermissions ui-type and local state in CreatePermissionForm
This commit is contained in:
@@ -12,6 +12,8 @@ export type ButtonProps = {
|
|||||||
fullWidth?: boolean,
|
fullWidth?: boolean,
|
||||||
className?: string,
|
className?: string,
|
||||||
children?: React.Node,
|
children?: React.Node,
|
||||||
|
|
||||||
|
// context props
|
||||||
classes: any
|
classes: any
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
//@flow
|
//@flow
|
||||||
import type {Links} from "./hal";
|
import type {Links} from "./hal";
|
||||||
|
|
||||||
|
export type PermissionCreateEntry = {
|
||||||
|
name: string,
|
||||||
|
role?: string,
|
||||||
|
verbs: string[],
|
||||||
|
groupPermission: boolean
|
||||||
|
}
|
||||||
|
|
||||||
export type Permission = PermissionCreateEntry & {
|
export type Permission = PermissionCreateEntry & {
|
||||||
_links: Links
|
_links: Links
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PermissionCreateEntry = {
|
|
||||||
name: string,
|
|
||||||
verbs: string[],
|
|
||||||
groupPermission: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export type PermissionCollection = Permission[];
|
export type PermissionCollection = Permission[];
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ type Props = {
|
|||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
name: string,
|
name: string,
|
||||||
|
role?: string,
|
||||||
verbs: string[],
|
verbs: string[],
|
||||||
groupPermission: boolean,
|
groupPermission: boolean,
|
||||||
valid: boolean,
|
valid: boolean,
|
||||||
@@ -45,6 +46,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
|||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
name: "",
|
name: "",
|
||||||
|
role: props.availableRoles[0].name,
|
||||||
verbs: props.availableRoles[0].verbs,
|
verbs: props.availableRoles[0].verbs,
|
||||||
groupPermission: false,
|
groupPermission: false,
|
||||||
valid: true,
|
valid: true,
|
||||||
@@ -137,9 +139,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
|||||||
|
|
||||||
const { verbs, showAdvancedDialog } = this.state;
|
const { verbs, showAdvancedDialog } = this.state;
|
||||||
|
|
||||||
const availableRoleNames = availableRoles.map(
|
const availableRoleNames = availableRoles.map(r => r.name);
|
||||||
r => r.name
|
|
||||||
);
|
|
||||||
const matchingRole = findMatchingRoleName(availableRoles, verbs);
|
const matchingRole = findMatchingRoleName(availableRoles, verbs);
|
||||||
|
|
||||||
const advancedDialog = showAdvancedDialog ? (
|
const advancedDialog = showAdvancedDialog ? (
|
||||||
@@ -230,6 +230,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
|||||||
submitAdvancedPermissionsDialog = (newVerbs: string[]) => {
|
submitAdvancedPermissionsDialog = (newVerbs: string[]) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
showAdvancedDialog: false,
|
showAdvancedDialog: false,
|
||||||
|
role: undefined,
|
||||||
verbs: newVerbs
|
verbs: newVerbs
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -237,6 +238,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
|||||||
submit = e => {
|
submit = e => {
|
||||||
this.props.createPermission({
|
this.props.createPermission({
|
||||||
name: this.state.name,
|
name: this.state.name,
|
||||||
|
role: this.state.role,
|
||||||
verbs: this.state.verbs,
|
verbs: this.state.verbs,
|
||||||
groupPermission: this.state.groupPermission
|
groupPermission: this.state.groupPermission
|
||||||
});
|
});
|
||||||
@@ -247,6 +249,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
|||||||
removeState = () => {
|
removeState = () => {
|
||||||
this.setState({
|
this.setState({
|
||||||
name: "",
|
name: "",
|
||||||
|
role: undefined,
|
||||||
verbs: this.props.availableRoles[0].verbs,
|
verbs: this.props.availableRoles[0].verbs,
|
||||||
valid: true,
|
valid: true,
|
||||||
value: undefined
|
value: undefined
|
||||||
@@ -259,14 +262,13 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
|
role: selectedRole.name,
|
||||||
verbs: selectedRole.verbs
|
verbs: selectedRole.verbs
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
findAvailableRole = (roleName: string) => {
|
findAvailableRole = (roleName: string) => {
|
||||||
return this.props.availableRoles.find(
|
return this.props.availableRoles.find(role => role.name === roleName);
|
||||||
role => role.name === roleName
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user