Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3023 from XRFoundation/ft-add-scope-to-hooks
Browse files Browse the repository at this point in the history
Added scopes for controlling access to admin functionality.
  • Loading branch information
barankyle authored Sep 16, 2021
2 parents ae32095 + 9a22759 commit eaf8b5b
Show file tree
Hide file tree
Showing 43 changed files with 2,069 additions and 332 deletions.
5 changes: 5 additions & 0 deletions .env.local.default
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,8 @@ REDIS_PORT=6379
# Map-related Variables (Harp, Mapbox, etc) ---------------
HARPGL_API_KEY=""
# --------------------------------


#define user scope
DEFAULT_GUEST_SCOPES=editor:write,location:read,location:write
DEFAULT_USER_SCOPES=editor:write,location:read,location:write
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"cli": "1.0.1",
"concurrently": "6.2.1",
"cpy-cli": "3.1.1",
"esbuild": "0.12.28",
"esbuild": "0.12.25",
"esbuild-plugin-sass": "0.6.0",
"jest": "27.2.0",
"jest-puppeteer": "5.0.4",
Expand All @@ -140,4 +140,4 @@
"trace-unhandled": "2.0.1",
"yuka": "0.7.6"
}
}
}
320 changes: 320 additions & 0 deletions packages/client-core/index.ts

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions packages/client-core/src/admin/components/Bots/styles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { makeStyles, Theme, createStyles } from '@material-ui/core/styles'

export const useStylesForBots = makeStyles((theme: Theme) =>
const useStylesForBots = makeStyles((theme: Theme) =>
createStyles({
root: {
width: '100%',
Expand Down Expand Up @@ -146,7 +146,7 @@ export const useStylesForBots = makeStyles((theme: Theme) =>
})
)

export const useStyle = makeStyles({
const useStyle = makeStyles({
autPaper: {
background: '#43484F'
},
Expand All @@ -161,3 +161,5 @@ export const useStyle = makeStyles({
color: '#f1f1f1'
}
})

export { useStylesForBots, useStyle }
101 changes: 53 additions & 48 deletions packages/client-core/src/admin/components/Location/LocationTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { fetchAdminScenes } from '../../reducers/admin/scene/service'
import { selectAdminSceneState } from '../../reducers/admin/scene/selector'
import { fetchUsersAsAdmin } from '../../reducers/admin/user/service'
import { fetchAdminInstances } from '../../reducers/admin/instance/service'
import { selectScopeErrorState } from '../../../common/reducers/error/selector'
import { connect } from 'react-redux'
import { useTranslation } from 'react-i18next'
import { locationColumns, LocationProps } from './variable'
Expand All @@ -30,6 +31,7 @@ import Button from '@material-ui/core/Button'
import { removeLocation } from '../../reducers/admin/location/service'
import ViewLocation from './ViewLocation'
import { LOCATION_PAGE_LIMIT } from '../../reducers/admin/location/reducers'
import FormDialog from '../UI/SubmitDialog'

const mapStateToProps = (state: any): any => {
return {
Expand All @@ -38,7 +40,8 @@ const mapStateToProps = (state: any): any => {
adminLocationState: selectAdminLocationState(state),
adminUserState: selectAdminUserState(state),
adminInstanceState: selectAdminInstanceState(state),
adminSceneState: selectAdminSceneState(state)
adminSceneState: selectAdminSceneState(state),
adminScopeErrorState: selectScopeErrorState(state)
}
}

Expand All @@ -65,6 +68,7 @@ const LocationTable = (props: LocationProps) => {
adminUserState,
adminInstanceState,
adminSceneState,
adminScopeErrorState,
removeLocation
} = props
const [page, setPage] = React.useState(0)
Expand All @@ -73,12 +77,11 @@ const LocationTable = (props: LocationProps) => {
const [locationId, setLocationId] = React.useState('')
const [viewModel, setViewModel] = React.useState(false)
const [locationAdmin, setLocationAdmin] = React.useState('')
const adminScopeReadErrMsg = adminScopeErrorState.get('readError').get('scopeErrorMessage')
const user = authState.get('user')
const adminLocations = adminLocationState.get('locations').get('locations')
const adminLocationCount = adminLocationState.get('locations').get('total')
const { t } = useTranslation()

console.log(adminLocations)
const handlePageChange = (event: unknown, newPage: number) => {
const incDec = page < newPage ? 'increment' : 'decrement'
fetchAdminLocations(incDec)
Expand All @@ -91,7 +94,7 @@ const LocationTable = (props: LocationProps) => {
}

useEffect(() => {
if (user?.id != null && adminLocationState.get('locations').get('updateNeeded') === true) {
if (user?.id !== null && adminLocationState.get('locations').get('updateNeeded') && !adminScopeReadErrMsg) {
fetchAdminLocations()
}
if (user?.id != null && adminSceneState.get('scenes').get('updateNeeded') === true) {
Expand Down Expand Up @@ -201,50 +204,52 @@ const LocationTable = (props: LocationProps) => {

return (
<div>
<TableContainer className={classes.container}>
<Table stickyHeader aria-label="sticky table">
<TableHead>
<TableRow>
{locationColumns.map((column) => (
<TableCell
key={column.id}
align={column.align}
style={{ minWidth: column.minWidth }}
className={classex.tableCellHeader}
>
{column.label}
</TableCell>
))}
</TableRow>
</TableHead>
<TableBody>
{rows.map((row, id) => {
return (
<TableRow hover role="checkbox" tabIndex={-1} key={row.id}>
{locationColumns.map((column) => {
const value = row[column.id]
return (
<TableCell key={column.id} align={column.align} className={classex.tableCellBody}>
{value}
</TableCell>
)
})}
</TableRow>
)
})}
</TableBody>
</Table>
</TableContainer>
<TablePagination
rowsPerPageOptions={[LOCATION_PAGE_LIMIT]}
component="div"
count={adminLocationCount}
rowsPerPage={rowsPerPage}
page={page}
onPageChange={handlePageChange}
onRowsPerPageChange={handleRowsPerPageChange}
className={classex.tableFooter}
/>
<React.Fragment>
<TableContainer className={classes.container}>
<Table stickyHeader aria-label="sticky table">
<TableHead>
<TableRow>
{locationColumns.map((column) => (
<TableCell
key={column.id}
align={column.align}
style={{ minWidth: column.minWidth }}
className={classex.tableCellHeader}
>
{column.label}
</TableCell>
))}
</TableRow>
</TableHead>
<TableBody>
{rows.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map((row, id) => {
return (
<TableRow hover role="checkbox" tabIndex={-1} key={row.id}>
{locationColumns.map((column) => {
const value = row[column.id]
return (
<TableCell key={column.id} align={column.align} className={classex.tableCellBody}>
{value}
</TableCell>
)
})}
</TableRow>
)
})}
</TableBody>
</Table>
</TableContainer>
<TablePagination
rowsPerPageOptions={[12]}
component="div"
count={adminLocationCount}
rowsPerPage={rowsPerPage}
page={page}
onPageChange={handlePageChange}
onRowsPerPageChange={handleRowsPerPageChange}
className={classex.tableFooter}
/>
</React.Fragment>
<Dialog
open={popConfirmOpen}
onClose={() => setPopConfirmOpen(false)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { patchLocation } from '../../reducers/admin/location/service'
import { bindActionCreators, Dispatch } from 'redux'
import MuiAlert from '@material-ui/lab/Alert'
import Snackbar from '@material-ui/core/Snackbar'
import { selectAuthState } from '@xrengine/client-core/src/user/reducers/auth/selector'

interface Props {
openView: any
Expand All @@ -39,7 +40,8 @@ interface Props {
const mapStateToProps = (state: any): any => {
return {
adminSceneState: selectAdminSceneState(state),
adminLocationState: selectAdminLocationState(state)
adminLocationState: selectAdminLocationState(state),
authState: selectAuthState(state)
}
}

Expand All @@ -52,7 +54,8 @@ const Alert = (props) => {
}

const ViewLocation = (props: Props) => {
const { openView, closeViewModel, adminSceneState, adminLocationState, patchLocation, locationAdmin } = props
const { openView, closeViewModel, adminSceneState, adminLocationState, patchLocation, locationAdmin, authState } =
props
const classex = useLocationStyle()
const classes = useLocationStyles()
const [editMode, setEditMode] = React.useState(false)
Expand Down Expand Up @@ -81,6 +84,16 @@ const ViewLocation = (props: Props) => {
const { t } = useTranslation()
const adminScenes = adminSceneState.get('scenes').get('scenes')
const locationTypes = adminLocationState.get('locationTypes').get('locationTypes')
const user = authState.get('user') // user initialized by getting value from authState object.
const scopes = user.scopes || []
let isLocationWrite = false

for (const scope of scopes) {
if (scope.type.split(':')[0] === 'location' && scope.type.split(':')[1] === 'write') {
isLocationWrite = true
break
}
}

React.useEffect(() => {
if (locationAdmin) {
Expand Down Expand Up @@ -523,6 +536,7 @@ const ViewLocation = (props: Props) => {
) : (
<div className={classes.marginTpM}>
<Button
disabled={!isLocationWrite}
className={classes.saveBtn}
onClick={() => {
setEditMode(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export const useLocationStyles = makeStyles((theme: Theme) =>
padding: '2px 4px',
display: 'flex',
alignItems: 'center',
//width: "45vw",
marginTop: '10px',
marginBottom: '15px',
background: '#343b41',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ export interface LocationProps {
adminInstanceState?: any
adminSceneState?: any
removeLocation?: any
adminScopeErrorState?: any
}
38 changes: 38 additions & 0 deletions packages/client-core/src/admin/components/Setting/Account.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react'
import { Grid, Paper, Button, Typography } from '@material-ui/core'
import InputBase from '@material-ui/core/InputBase'
import { useStyles } from './styles'

const Account = () => {
const classes = useStyles()

const handleSubmit = () => {}
return (
<div className={`${classes.root} ${classes.container}`}>
<Typography component="h1" className={classes.settingsHeading}>
{' '}
Login
</Typography>
<Grid container spacing={3}>
<Grid item xs={12} sm={6}>
<form autoComplete="off" onSubmit={handleSubmit}>
<label>Email</label>
<Paper component="div" className={classes.createInput}>
<InputBase name="email" style={{ color: '#fff' }} className={classes.input} placeholder="Email" />
</Paper>
<label>Password</label>
<Paper component="div" className={classes.createInput}>
<InputBase name="password" style={{ color: '#fff' }} className={classes.input} placeholder="Password" />
</Paper>
<Button className={classes.login}>Login</Button>
</form>
</Grid>
<Grid item xs={12} sm={6}>
social media
</Grid>
</Grid>
</div>
)
}

export default Account
48 changes: 48 additions & 0 deletions packages/client-core/src/admin/components/UI/SubmitDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react'
import Button from '@material-ui/core/Button'
import TextField from '@material-ui/core/TextField'
import Dialog from '@material-ui/core/Dialog'
import DialogActions from '@material-ui/core/DialogActions'
import DialogContent from '@material-ui/core/DialogContent'
import DialogContentText from '@material-ui/core/DialogContentText'
import DialogTitle from '@material-ui/core/DialogTitle'
import ErrorIcon from '@material-ui/icons/Error'
import { useStyle, useStyles } from './styles'

const FormDialog = () => {
const classes = useStyles()
const classex = useStyle()
const [open, setOpen] = React.useState(true)
const handleClose = () => {
setOpen(false)
}

return (
<div>
<Dialog
open={open}
onClose={handleClose}
aria-labelledby="form-dialog-title"
classes={{ paper: classes.paperDialog }}
>
<DialogTitle id="form-dialog-title"> No access</DialogTitle>
<DialogContent>
<DialogContentText className={classex.spanNone}>
To access this resource, please enter your username here to ask for access.
</DialogContentText>
<TextField autoFocus id="name" label="Username" type="text" fullWidth />
</DialogContent>
<DialogActions>
<Button onClick={handleClose} className={classex.spanNone}>
Cancel
</Button>
<Button onClick={handleClose} className={classex.spanDange}>
Submit
</Button>
</DialogActions>
</Dialog>
</div>
)
}

export default FormDialog
33 changes: 33 additions & 0 deletions packages/client-core/src/admin/components/UI/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles'

const useStyles = makeStyles((theme: Theme) =>
createStyles({
paperDialog: {
background: 'rgb(58, 65, 73) !important',
color: '#f1f1f1'
},
flex: {
display: 'flex',
justifyContent: 'center',
alignContent: 'center'
},
input: {
marginLeft: theme.spacing(1),
color: '#f1f1f1'
}
})
)

const useStyle = makeStyles({
spanDange: {
color: '#FF8C00'
},
spanNone: {
color: '#808080'
},
spanWhite: {
color: '#f1f1f1'
}
})

export { useStyle, useStyles }
Loading

0 comments on commit eaf8b5b

Please sign in to comment.