Skip to content

Commit

Permalink
Merge pull request #2478 from botpress/ya-admin-perms
Browse files Browse the repository at this point in the history
fix(admin): redirect if no permissions
  • Loading branch information
allardy committed Oct 8, 2019
2 parents 553f457 + 6dc040d commit cf4a500
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/bp/ui-admin/src/Pages/Layouts/Tabs.tsx
Expand Up @@ -2,12 +2,12 @@ import classnames from 'classnames'
import React, { Component, Fragment } from 'react'
import { MdHome, MdKeyboardArrowLeft } from 'react-icons/md'
import { connect } from 'react-redux'
import { generatePath, RouteComponentProps } from 'react-router'
import { generatePath, Redirect, RouteComponentProps } from 'react-router'
import { matchPath, Route, Switch } from 'react-router-dom'
import { Col, Container, Nav, NavItem, NavLink, Row } from 'reactstrap'

import { fetchLicensing } from '../../reducers/license'
import AccessControl from '../../App/AccessControl'
import AccessControl, { isOperationAllowed } from '../../App/AccessControl'

export interface AdminTab {
id?: string
Expand All @@ -18,7 +18,7 @@ export interface AdminTab {
/** Name of the resource in permissions */
res?: string
/** Type of operation: read or write */
op?: string
op?: 'read' | 'write'
/** By default, the page size is 10 cols, but it can be overrided here */
size?: number
/** When true, tab is only displayed when pro is enabled in the workspace */
Expand Down Expand Up @@ -86,6 +86,12 @@ class TabLayout extends Component<Props> {
const size = (currentTab && currentTab.size) || 10
const offset = (currentTab && currentTab.offset) || 1

if (currentTab && currentTab.op && currentTab.res) {
if (!isOperationAllowed({ operation: currentTab.op, resource: currentTab.res })) {
return <Redirect to="/admin/workspace/bots" />
}
}

return (
<Fragment>
<div className="bp_container-header">
Expand Down

0 comments on commit cf4a500

Please sign in to comment.