mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-11 03:24:16 +00:00
check permissions route
This commit is contained in:
parent
e1ca4f5b31
commit
da6c1837cf
@ -8,6 +8,8 @@ import Drawer from "./drawer"
|
|||||||
import Sidedrawer from "./sidedrawer"
|
import Sidedrawer from "./sidedrawer"
|
||||||
import BottomBar from "./bottomBar"
|
import BottomBar from "./bottomBar"
|
||||||
|
|
||||||
|
import routes from "schemas/routes"
|
||||||
|
|
||||||
const LayoutRenders = {
|
const LayoutRenders = {
|
||||||
mobile: (props) => {
|
mobile: (props) => {
|
||||||
return <antd.Layout className={classnames("app_layout", ["mobile"])} style={{ height: "100%" }}>
|
return <antd.Layout className={classnames("app_layout", ["mobile"])} style={{ height: "100%" }}>
|
||||||
@ -87,8 +89,13 @@ export default class Layout extends React.PureComponent {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// this is a hacky one to fix app.setLocation not working on when app not render a router
|
||||||
window.app.setLocation = (location) => {
|
window.app.setLocation = (location) => {
|
||||||
return window.history.pushState(null, null, location)
|
// update history
|
||||||
|
window.history.pushState(null, null, location)
|
||||||
|
|
||||||
|
// reload page
|
||||||
|
window.location.reload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,6 +130,26 @@ export default class Layout extends React.PureComponent {
|
|||||||
return JSON.stringify(this.state.renderError)
|
return JSON.stringify(this.state.renderError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.debug(`Rendering layout [${this.state.layoutType}] for current route [${window.location.pathname}]`)
|
||||||
|
|
||||||
|
// check with the current route if it's a protected route or requires some permissions
|
||||||
|
const routeDeclaration = routes.find((route) => route.path === window.location.pathname)
|
||||||
|
|
||||||
|
if (routeDeclaration) {
|
||||||
|
if (typeof routeDeclaration.requiredRoles !== "undefined") {
|
||||||
|
const isAdmin = this.props.user?.roles?.includes("admin") ?? false
|
||||||
|
|
||||||
|
if (!isAdmin && !routeDeclaration.requiredRoles.some((role) => this.props.user?.roles?.includes(role))) {
|
||||||
|
return <antd.Result
|
||||||
|
status="403"
|
||||||
|
title="403"
|
||||||
|
subTitle="Sorry, you are not authorized to access this page."
|
||||||
|
extra={<antd.Button type="primary" onClick={() => window.app.setLocation("/")}>Back Home</antd.Button>}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const layoutComponentProps = {
|
const layoutComponentProps = {
|
||||||
...this.props.bindProps,
|
...this.props.bindProps,
|
||||||
...this.state,
|
...this.state,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user