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
|
@ -20,7 +20,7 @@ import {
|
|||
withFormErrorHandlers
|
||||
} from '../lib/form';
|
||||
import {withErrorHandling} from '../lib/error-handling';
|
||||
import {NamespaceSelect, validateNamespace} from '../lib/namespace';
|
||||
import {getDefaultNamespace, NamespaceSelect, validateNamespace} from '../lib/namespace';
|
||||
import {DeleteModalDialog} from "../lib/modals";
|
||||
|
||||
import {getMailerTypes} from "./helpers";
|
||||
|
@ -60,7 +60,8 @@ export default class CUD extends Component {
|
|||
static propTypes = {
|
||||
action: PropTypes.string.isRequired,
|
||||
wizard: PropTypes.string,
|
||||
entity: PropTypes.object
|
||||
entity: PropTypes.object,
|
||||
permissions: PropTypes.object
|
||||
}
|
||||
|
||||
onMailerTypeChanged(mutStateDate, key, oldType, type) {
|
||||
|
@ -96,7 +97,7 @@ export default class CUD extends Component {
|
|||
this.populateFormValues({
|
||||
name: '',
|
||||
description: '',
|
||||
namespace: mailtrainConfig.user.namespace,
|
||||
namespace: getDefaultNamespace(this.props.permissions),
|
||||
from_email: '',
|
||||
from_email_overridable: false,
|
||||
from_name: '',
|
||||
|
|
|
@ -4,13 +4,13 @@ import React, {Component} from 'react';
|
|||
import {withTranslation} from '../lib/i18n';
|
||||
import {Icon} from '../lib/bootstrap-components';
|
||||
import {LinkButton, requiresAuthenticatedUser, Title, Toolbar, withPageHelpers} from '../lib/page';
|
||||
import {withAsyncErrorHandler, withErrorHandling} from '../lib/error-handling';
|
||||
import {withErrorHandling} from '../lib/error-handling';
|
||||
import {Table} from '../lib/table';
|
||||
import moment from 'moment';
|
||||
import {getMailerTypes} from './helpers';
|
||||
import {checkPermissions} from "../lib/permissions";
|
||||
import {tableAddDeleteButton, tableRestActionDialogInit, tableRestActionDialogRender} from "../lib/modals";
|
||||
import {withComponentMixins} from "../lib/decorator-helpers";
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
|
||||
@withComponentMixins([
|
||||
|
@ -29,28 +29,16 @@ export default class List extends Component {
|
|||
tableRestActionDialogInit(this);
|
||||
}
|
||||
|
||||
@withAsyncErrorHandler
|
||||
async fetchPermissions() {
|
||||
const result = await checkPermissions({
|
||||
createSendConfiguration: {
|
||||
entityTypeId: 'namespace',
|
||||
requiredOperations: ['createSendConfiguration']
|
||||
}
|
||||
});
|
||||
|
||||
this.setState({
|
||||
createPermitted: result.data.createSendConfiguration
|
||||
});
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
// noinspection JSIgnoredPromiseFromCall
|
||||
this.fetchPermissions();
|
||||
static propTypes = {
|
||||
permissions: PropTypes.object
|
||||
}
|
||||
|
||||
render() {
|
||||
const t = this.props.t;
|
||||
|
||||
const permissions = this.props.permissions;
|
||||
const createPermitted = permissions.createSendConfiguration;
|
||||
|
||||
const columns = [
|
||||
{ data: 1, title: t('name') },
|
||||
{ data: 2, title: t('id'), render: data => <code>{data}</code> },
|
||||
|
@ -87,7 +75,7 @@ export default class List extends Component {
|
|||
return (
|
||||
<div>
|
||||
{tableRestActionDialogRender(this)}
|
||||
{this.state.createPermitted &&
|
||||
{createPermitted &&
|
||||
<Toolbar>
|
||||
<LinkButton to="/send-configurations/create" className="btn-primary" icon="plus" label={t('createSendConfiguration')}/>
|
||||
</Toolbar>
|
||||
|
|
|
@ -6,6 +6,7 @@ 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) {
|
||||
|
@ -13,7 +14,14 @@ function getMenus(t) {
|
|||
'send-configurations': {
|
||||
title: t('sendConfigurations-1'),
|
||||
link: '/send-configurations',
|
||||
panelComponent: List,
|
||||
checkPermissions: {
|
||||
createSendConfiguration: {
|
||||
entityTypeId: 'namespace',
|
||||
requiredOperations: ['createSendConfiguration']
|
||||
},
|
||||
...namespaceCheckPermissions('createSendConfiguration')
|
||||
},
|
||||
panelRender: props => <List permissions={props.permissions}/>,
|
||||
children: {
|
||||
':sendConfigurationId([0-9]+)': {
|
||||
title: resolved => t('templateName', {name: ellipsizeBreadcrumbLabel(resolved.sendConfiguration.name)}),
|
||||
|
@ -26,7 +34,7 @@ function getMenus(t) {
|
|||
title: t('edit'),
|
||||
link: params => `/send-configurations/${params.sendConfigurationId}/edit`,
|
||||
visible: resolved => resolved.sendConfiguration.permissions.includes('edit'),
|
||||
panelRender: props => <CUD action={props.match.params.action} entity={props.resolved.sendConfiguration} />
|
||||
panelRender: props => <CUD action={props.match.params.action} entity={props.resolved.sendConfiguration} permissions={props.permissions} />
|
||||
},
|
||||
share: {
|
||||
title: t('share'),
|
||||
|
@ -38,7 +46,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