Commit a2b778cb authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch 'api-396-problem-with-ssr-accession-page' into 'master'

Permissions editor for Parent OID

See merge request genesys-pgr/genesys-ui!162
parents 21f5dd9f a62f916d
......@@ -114,7 +114,7 @@
"objectID": "Object ID",
"owner": "Owner",
"inheritsPermissions": "Inherits permissions",
"effectivePermissions": "Effective permissions",
"inheritedPermissions": "Permissions inherited from parent ACL object",
"sid": "Sid",
"objectIdentityId": "ACL OID ID",
"parentObjectIdentityId": "Parent OID ID",
......
......@@ -12,6 +12,14 @@ export const permissions = (clazz: string, id: number) => (dispatch, getState) =
});
};
export const permissionsForOid = (id: number) => (dispatch, getState) => {
return PermissionService.permissionsForOid(id)
.catch((error) => {
log('Error', error);
});
};
export const addPermission = (clazz: string, id: number, sidPermissions: SidPermissions) => (dispatch, getState) => {
return PermissionService.addPermission(clazz, id, sidPermissions)
......@@ -20,6 +28,14 @@ export const addPermission = (clazz: string, id: number, sidPermissions: SidPerm
});
};
export const removePermission = (clazz: string, id: number, sid: string) => (dispatch, getState) => {
return PermissionService.removePermission(clazz, id, sid)
.catch((error) => {
log('Error', error);
});
};
export const autocomplete = (term: string) => (dispatch, getState) => {
return PermissionService.acSid(term)
......
......@@ -7,10 +7,12 @@ import AclObjectIdentity from 'model/acl/AclObjectIdentity';
import SidPermissions from 'model/acl/SidPermissions';
const URL_ADD_PERMISSION = UrlTemplate.parse(`/api/v1/permission/permissions/{clazz}/{id}`);
const URL_REMOVE_PERMISSION = UrlTemplate.parse(`/api/v1/permission/permissions/{clazz}/{id}/{sid}`);
const URL_AC_OAUTH_CLIENT = `/api/v1/permission/autocomplete-oauth-client`;
const URL_AC_USER = `/api/v1/permission/autocompleteuser`;
const URL_AC_SID = `/api/v1/permission/autocomplete`;
const URL_AC_ROLE = `/api/v1/permission/autocompleterole`;
const URL_OID_PERMISSIONS = UrlTemplate.parse(`/api/v1/permission/permissions/{id}`);
const URL_PERMISSIONS = UrlTemplate.parse(`/api/v1/permission/permissions/{clazz}/{id}`);
const URL_UPDATE_OBJECT_IDENTITY = UrlTemplate.parse(`/api/v1/permission/update-inheriting/{inheriting}/{id}`);
const URL_UPDATE_PARENT_OBJECT = UrlTemplate.parse(`/api/v1/permission/update-parent/{id}/{parentId}`);
......@@ -40,6 +42,26 @@ class PermissionService {
}).then(({ data }) => data as AclObjectIdentity);
}
/**
* removePermission at /api/v1/permission/permissions/{clazz}/{id}/{sid}
*
* @param clazz clazz
* @param id id
* @param sidPermissions sidPermissions
*/
public static removePermission(clazz: string, id: number, sid: string): Promise<AclObjectIdentity> {
const apiUrl = URL_REMOVE_PERMISSION.expand({clazz, id, sid});
// console.log(`Fetching from ${apiUrl}`);
const content = { };
return axiosBackend.request({
url: apiUrl,
method: 'DELETE',
...content,
}).then(({ data }) => data as AclObjectIdentity);
}
/**
* acOauthClient at /api/v1/permission/autocomplete-oauth-client
*
......@@ -127,6 +149,24 @@ class PermissionService {
}).then(({ data }) => data as any);
}
/**
* permissions at /api/v1/permission/permissions/{id}
*
* @param id ACL OID id
*/
public static permissionsForOid(id: number): Promise<AclObjectIdentity> {
const apiUrl = URL_OID_PERMISSIONS.expand({ id });
// console.log(`Fetching from ${apiUrl}`);
const content = { /* No content in request body */ };
return axiosBackend.request({
url: apiUrl,
method: 'GET',
...content,
}).then(({ data }) => data as AclObjectIdentity);
}
/**
* permissions at /api/v1/permission/permissions/{clazz}/{id}
*
......
......@@ -187,7 +187,7 @@ class MaterialAutosuggest extends React.Component<IMaterialAutosuggestProps, any
classes,
...input,
...other,
autocomplete: 'off',
autoComplete: 'off',
onBlur: checkIfMatch,
} }
/>
......
......@@ -12,7 +12,7 @@ import {withStyles} from '@material-ui/core/styles';
import Switch from '@material-ui/core/Switch';
import ChangeParentForm from './ChangeParentForm';
import { permissions, addPermission, autocomplete, updateInheriting, updateParentObject } from 'actions/permission';
import { permissions, permissionsForOid, addPermission, removePermission, autocomplete, updateInheriting, updateParentObject } from 'actions/permission';
import SidPermissions from 'model/acl/SidPermissions';
import Loading from 'ui/common/Loading';
import Authorize from 'ui/common/authorized/Authorize';
......@@ -38,8 +38,10 @@ interface IPermissionsProps extends React.ClassAttributes<any> {
clazz: string;
id: number;
permissions: (clazz: string, id: number) => Promise<AclObjectIdentity>;
permissionsForOid: (id: number) => Promise<AclObjectIdentity>;
autocomplete: (term: string) => Promise<{[key: string]: number}>;
addPermission: (clazz: string, id: number, sidPermissions: SidPermissions) => Promise<AclObjectIdentity>;
removePermission: (clazz: string, id: number, sid: string) => Promise<AclObjectIdentity>;
updateInheriting: (id: number, inheriting: boolean) => Promise<AclObjectIdentity>;
updateParentObject: (id: number, parentId: number) => Promise<AclObjectIdentity>;
change: any;
......@@ -75,6 +77,26 @@ class Permissions extends React.Component<IPermissionsProps, any> {
);
}
private showParent = () => {
const { permissionsForOid } = this.props;
const { aclObjectIdentity } = this.state;
if (!aclObjectIdentity || !aclObjectIdentity.parentObject) {
console.log(`Permissions: doesn't have a parent OID`);
return;
}
this.setState(
(state) => ({ ...state, open: true }),
() => {
permissionsForOid(typeof aclObjectIdentity.parentObject === 'object' ? aclObjectIdentity.parentObject.id : aclObjectIdentity.parentObject)
.then((aclObjectIdentity) => {
this.setState({ aclObjectIdentity });
});
},
);
}
private hide = () => {
this.setState({open: false});
}
......@@ -87,6 +109,14 @@ class Permissions extends React.Component<IPermissionsProps, any> {
});
}
protected removePermission = (sid: string) => {
const {removePermission, clazz, id} = this.props;
removePermission(clazz, id, sid)
.then((aclObjectIdentity) => {
this.setState({aclObjectIdentity});
});
}
protected onInputChange = (e) => {
if (e.target && e.target.value) {
this.props.autocomplete(e.target.value)
......@@ -149,7 +179,9 @@ class Permissions extends React.Component<IPermissionsProps, any> {
{
aclObjectIdentity.parentObject &&
<PropertiesItem title={ t('common:permissions.parentObjectIdentityId') }>
{ `${ typeof aclObjectIdentity.parentObject === 'object' ? aclObjectIdentity.parentObject.id : aclObjectIdentity.parentObject }` }
<a onClick={ this.showParent }>
{ `${ typeof aclObjectIdentity.parentObject === 'object' ? aclObjectIdentity.parentObject.id : aclObjectIdentity.parentObject }` }
</a>
</PropertiesItem>
}
{
......@@ -171,6 +203,7 @@ class Permissions extends React.Component<IPermissionsProps, any> {
],
} }
addPermission={ this.addPermission }
removePermission={ this.removePermission }
onInputChange={ this.onInputChange }
autocomplete={ autocomplete }
autocompleteObj={ autocompleteObj }
......@@ -200,7 +233,9 @@ class Permissions extends React.Component<IPermissionsProps, any> {
const mapDispatchToProps = (dispatch) => bindActionCreators({
permissions,
permissionsForOid,
addPermission,
removePermission,
autocomplete,
updateInheriting,
updateParentObject,
......
......@@ -11,7 +11,6 @@ import Button from '@material-ui/core/Button';
import { PERMISSION_TABLE_FORM } from 'constants/permission';
import ReduxCheckbox from 'ui/common/checkbox';
import { Permissions } from 'model/acl/ACL';
import SidPermissions from 'model/acl/SidPermissions';
import MaterialAutosuggest from 'ui/common/material-autosuggest';
import AclObjectIdentity from 'model/acl/AclObjectIdentity';
......@@ -22,6 +21,7 @@ interface IPermissionsTableFormProps extends React.ClassAttributes<any> {
fields: any;
handleSubmit: () => void;
addPermission: (sidPermissions: SidPermissions) => Promise<AclObjectIdentity>;
removePermission: (sid: string) => Promise<AclObjectIdentity>;
autocompleteObj: {[key: string]: number};
onInputChange: (e) => void;
inherits?: boolean;
......@@ -55,12 +55,14 @@ const styles = {
class PermissionsTableForm extends React.Component<IPermissionsTableFormProps, any> {
protected remove = (fields, index) => () => {
const sidPermissions = Permissions.grantNone(fields.get(index));
this.props.addPermission(sidPermissions);
const sidPermissions = fields.get(index);
this.props.removePermission(sidPermissions.sid.sid);
}
protected save = (fields, index, isNew) => () => {
protected save = (fields, index, name, isNew) => (e: any, checked: any) => {
console.log(`Ticked`, checked, e.target.checked, fields.get(index));
const sidPermissions = fields.get(index);
sidPermissions[name] = checked;
if (!isNew) {
this.props.addPermission(sidPermissions);
}
......@@ -110,7 +112,7 @@ class PermissionsTableForm extends React.Component<IPermissionsTableFormProps, a
<Field
name={ `${entry}.create` }
component={ ReduxCheckbox }
onChange={ this.save(fields, index, isNewEntry) }
onChange={ this.save(fields, index, 'create', isNewEntry) }
disabled={ !(!owner && !inherits) }
/>
</TableCell>
......@@ -118,7 +120,7 @@ class PermissionsTableForm extends React.Component<IPermissionsTableFormProps, a
<Field
name={ `${entry}.read` }
component={ ReduxCheckbox }
onChange={ this.save(fields, index, isNewEntry) }
onChange={ this.save(fields, index, 'read', isNewEntry) }
disabled={ !(!owner && !inherits) }
/>
</TableCell>
......@@ -126,7 +128,7 @@ class PermissionsTableForm extends React.Component<IPermissionsTableFormProps, a
<Field
name={ `${entry}.write` }
component={ ReduxCheckbox }
onChange={ this.save(fields, index, isNewEntry) }
onChange={ this.save(fields, index, 'write', isNewEntry) }
disabled={ !(!owner && !inherits) }
/>
</TableCell>
......@@ -134,7 +136,7 @@ class PermissionsTableForm extends React.Component<IPermissionsTableFormProps, a
<Field
name={ `${entry}.delete` }
component={ ReduxCheckbox }
onChange={ this.save(fields, index, isNewEntry) }
onChange={ this.save(fields, index, 'delete', isNewEntry) }
disabled={ !(!owner && !inherits) }
/>
</TableCell>
......@@ -142,7 +144,7 @@ class PermissionsTableForm extends React.Component<IPermissionsTableFormProps, a
<Field
name={ `${entry}.manage` }
component={ ReduxCheckbox }
onChange={ this.save(fields, index, isNewEntry) }
onChange={ this.save(fields, index, 'manage', isNewEntry) }
disabled={ !(!owner && !inherits) }
/>
</TableCell>
......@@ -187,7 +189,7 @@ class PermissionsTableForm extends React.Component<IPermissionsTableFormProps, a
{ inherits &&
<div>
<div className={ classes.inheritedTitle }>{ t('common:permissions.effectivePermissions') }</div>
<div className={ classes.inheritedTitle }>{ t('common:permissions.inheritedPermissions') }</div>
<Table className={ classes.table }>
<TableHead>
<TableRow>
......
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