Commit 3fd4cdca authored by Matija Obreza's avatar Matija Obreza
Browse files

Permission editor update

- Properly reload and save permissions when changing OID
parent af5f4796
......@@ -59,22 +59,16 @@ class Permissions extends React.Component<IPermissionsProps, any> {
};
private show = () => {
const {permissions, clazz, id} = this.props;
const { permissions, clazz, id } = this.props;
if (! clazz || ! id) {
console.log('Permissions: Missing clazz or id', clazz, id);
return;
if (!clazz || !id) {
console.log('Permissions: Missing clazz or id', clazz, id);
return;
}
this.setState(
(state) => ({...state, open: true}),
() => {
permissions(clazz, id)
.then((aclObjectIdentity) => {
this.setState({aclObjectIdentity});
});
},
);
permissions(clazz, id)
.then((aclObjectIdentity) => {
this.setState({ ...this.state, open: true, aclObjectIdentity });
});
}
private showParent = () => {
......@@ -85,35 +79,33 @@ class Permissions extends React.Component<IPermissionsProps, any> {
console.log(`Permissions: doesn't have a parent OID`);
return;
}
this.setState({ ...this.state, aclObjectIdentity: null });
this.setState(
(state) => ({ ...state, open: true }),
() => {
permissionsForOid(typeof aclObjectIdentity.parentObject === 'object' ? aclObjectIdentity.parentObject.id : aclObjectIdentity.parentObject)
.then((aclObjectIdentity) => {
this.setState({ aclObjectIdentity });
});
},
);
permissionsForOid(typeof aclObjectIdentity.parentObject === 'object' ? aclObjectIdentity.parentObject.id : aclObjectIdentity.parentObject)
.then((aclObjectIdentity) => {
this.setState({ ...this.state, open: true, aclObjectIdentity });
});
}
private hide = () => {
this.setState({open: false});
this.setState({ open: false });
}
protected addPermission = (sidPermissions: SidPermissions) => {
const {addPermission, clazz, id} = this.props;
addPermission(clazz, id, sidPermissions)
const { addPermission } = this.props;
const { aclObjectIdentity } = this.state;
addPermission(aclObjectIdentity.aclClass.aclClass, aclObjectIdentity.objectIdIdentity, sidPermissions)
.then((aclObjectIdentity) => {
this.setState({aclObjectIdentity});
this.setState({ ...this.state, aclObjectIdentity });
});
}
protected removePermission = (sid: string) => {
const {removePermission, clazz, id} = this.props;
removePermission(clazz, id, sid)
const { removePermission } = this.props;
const { aclObjectIdentity } = this.state;
removePermission(aclObjectIdentity.aclClass.aclClass, aclObjectIdentity.objectIdIdentity, sid)
.then((aclObjectIdentity) => {
this.setState({aclObjectIdentity});
this.setState({ ...this.state, aclObjectIdentity });
});
}
......@@ -121,15 +113,15 @@ class Permissions extends React.Component<IPermissionsProps, any> {
if (e.target && e.target.value) {
this.props.autocomplete(e.target.value)
.then((autocompleteObj) => {
this.setState({autocompleteObj});
this.setState({...this.state, autocompleteObj});
});
}
}
protected handleSwitch = (event, checked) => {
const {updateInheriting} = this.props;
const { updateInheriting } = this.props;
updateInheriting(this.state.aclObjectIdentity.id, checked).then((aclObjectIdentity) => {
this.setState({ aclObjectIdentity });
this.setState({ ...this.state, aclObjectIdentity });
});
}
......@@ -137,7 +129,7 @@ class Permissions extends React.Component<IPermissionsProps, any> {
const { updateParentObject } = this.props;
return updateParentObject(this.state.aclObjectIdentity.id, value.id)
.then((aclObjectIdentity) => {
this.setState({ aclObjectIdentity });
this.setState({ ...this.state, aclObjectIdentity });
})
.catch((error) => {
throw new SubmissionError({ ...error.errors });
......@@ -145,16 +137,16 @@ class Permissions extends React.Component<IPermissionsProps, any> {
}
protected handleCancel = () => {
const {aclObjectIdentity} = this.state;
const { aclObjectIdentity } = this.state;
const parentId = typeof aclObjectIdentity.parentObject === 'number'
? aclObjectIdentity.parentObject : (aclObjectIdentity.parentObject === null ? '' : aclObjectIdentity.parentObject.id);
this.props.change(UPDATE_PARENT_ID_FORM, 'id', parentId);
}
}
public render() {
const {autocomplete, variant = 'text', t } = this.props;
const {aclObjectIdentity, autocompleteObj} = this.state;
const { autocomplete, variant = 'text', t } = this.props;
const { aclObjectIdentity, autocompleteObj } = this.state;
return (
<span>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment