Various fixes in the UI.
Check permissions mechanism reworked to allow specifying permission checks already in menu structure.
This commit is contained in:
parent
a46c8fa9c3
commit
a258479621
37 changed files with 485 additions and 399 deletions
|
@ -24,6 +24,7 @@ import mailtrainConfig from 'mailtrainConfig';
|
|||
import {getGlobalNamespaceId} from "../../../shared/namespaces";
|
||||
import {getUrl} from "../lib/urls";
|
||||
import {withComponentMixins} from "../lib/decorator-helpers";
|
||||
import {getDefaultNamespace} from "../lib/namespace";
|
||||
|
||||
@withComponentMixins([
|
||||
withTranslation,
|
||||
|
@ -43,7 +44,8 @@ export default class CUD extends Component {
|
|||
|
||||
static propTypes = {
|
||||
action: PropTypes.string.isRequired,
|
||||
entity: PropTypes.object
|
||||
entity: PropTypes.object,
|
||||
permissions: PropTypes.object
|
||||
}
|
||||
|
||||
submitFormValuesMutator(data) {
|
||||
|
@ -97,7 +99,7 @@ export default class CUD extends Component {
|
|||
this.populateFormValues({
|
||||
name: '',
|
||||
description: '',
|
||||
namespace: mailtrainConfig.user.namespace
|
||||
namespace: getDefaultNamespace(this.props.permissions)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -4,13 +4,13 @@ import React, {Component} from 'react';
|
|||
import {withTranslation} from '../lib/i18n';
|
||||
import {LinkButton, requiresAuthenticatedUser, Title, Toolbar, withPageHelpers} from '../lib/page';
|
||||
import {TreeTable} from '../lib/tree';
|
||||
import {withAsyncErrorHandler, withErrorHandling} from '../lib/error-handling';
|
||||
import {withErrorHandling} from '../lib/error-handling';
|
||||
import {Icon} from "../lib/bootstrap-components";
|
||||
import {checkPermissions} from "../lib/permissions";
|
||||
import {tableAddDeleteButton, tableRestActionDialogInit, tableRestActionDialogRender} from "../lib/modals";
|
||||
import {getGlobalNamespaceId} from "../../../shared/namespaces";
|
||||
import {withComponentMixins} from "../lib/decorator-helpers";
|
||||
import mailtrainConfig from 'mailtrainConfig';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
@withComponentMixins([
|
||||
withTranslation,
|
||||
|
@ -26,28 +26,16 @@ export default class List extends Component {
|
|||
tableRestActionDialogInit(this);
|
||||
}
|
||||
|
||||
@withAsyncErrorHandler
|
||||
async fetchPermissions() {
|
||||
const result = await checkPermissions({
|
||||
createNamespace: {
|
||||
entityTypeId: 'namespace',
|
||||
requiredOperations: ['createNamespace']
|
||||
}
|
||||
});
|
||||
|
||||
this.setState({
|
||||
createPermitted: result.data.createNamespace
|
||||
});
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
// noinspection JSIgnoredPromiseFromCall
|
||||
this.fetchPermissions();
|
||||
static propTypes = {
|
||||
permissions: PropTypes.object
|
||||
}
|
||||
|
||||
render() {
|
||||
const t = this.props.t;
|
||||
|
||||
const permissions = this.props.permissions;
|
||||
const createPermitted = permissions.createNamespace;
|
||||
|
||||
const actions = node => {
|
||||
const actions = [];
|
||||
|
||||
|
@ -76,7 +64,7 @@ export default class List extends Component {
|
|||
return (
|
||||
<div>
|
||||
{tableRestActionDialogRender(this)}
|
||||
{this.state.createPermitted &&
|
||||
{createPermitted &&
|
||||
<Toolbar>
|
||||
<LinkButton to="/namespaces/create" className="btn-primary" icon="plus" label={t('createNamespace')}/>
|
||||
</Toolbar>
|
||||
|
|
|
@ -5,13 +5,21 @@ import CUD from './CUD';
|
|||
import List from './List';
|
||||
import Share from '../shares/Share';
|
||||
import {ellipsizeBreadcrumbLabel} from "../lib/helpers";
|
||||
import {namespaceCheckPermissions} from "../lib/namespace";
|
||||
|
||||
function getMenus(t) {
|
||||
return {
|
||||
namespaces: {
|
||||
title: t('namespaces'),
|
||||
link: '/namespaces',
|
||||
panelComponent: List,
|
||||
checkPermissions: {
|
||||
createNamespace: {
|
||||
entityTypeId: 'namespace',
|
||||
requiredOperations: ['createNamespace']
|
||||
},
|
||||
...namespaceCheckPermissions('createNamespace')
|
||||
},
|
||||
panelRender: props => <List permissions={props.permissions}/>,
|
||||
children: {
|
||||
':namespaceId([0-9]+)': {
|
||||
title: resolved => t('namespaceName', {name: ellipsizeBreadcrumbLabel(resolved.namespace.name)}),
|
||||
|
@ -24,7 +32,7 @@ function getMenus(t) {
|
|||
title: t('edit'),
|
||||
link: params => `/namespaces/${params.namespaceId}/edit`,
|
||||
visible: resolved => resolved.namespace.permissions.includes('edit'),
|
||||
panelRender: props => <CUD action={props.match.params.action} entity={props.resolved.namespace} />
|
||||
panelRender: props => <CUD action={props.match.params.action} entity={props.resolved.namespace} permissions={props.permissions} />
|
||||
},
|
||||
share: {
|
||||
title: t('share'),
|
||||
|
@ -36,7 +44,7 @@ function getMenus(t) {
|
|||
},
|
||||
create: {
|
||||
title: t('create'),
|
||||
panelRender: props => <CUD action="create" />
|
||||
panelRender: props => <CUD action="create" permissions={props.permissions} />
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue