Skip to content

Commit

Permalink
Merge pull request #19 from ciatph/dev
Browse files Browse the repository at this point in the history
v1.0.4
  • Loading branch information
ciatph authored Apr 7, 2022
2 parents 6b8cc5c + 2ea5b52 commit 9da5f1b
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 6 deletions.
7 changes: 7 additions & 0 deletions client/src/components/common/alert_message/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const styles = {
message: {
overflowWrap: 'break-word'
}
}

export default styles
29 changes: 27 additions & 2 deletions client/src/components/home/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
function Home () {
import PropTypes from 'prop-types'
import Card from '@mui/material/Card'
import CardContent from '@mui/material/CardContent'
import AlertMessage from '../../components/common/alert_message'
import styles from './styles'

function Home (props) {
return (
<h1>Home</h1>
<div>
<h1>Home</h1>

{props.currentUser &&
<AlertMessage
severity='info'
title='Your Firebase Authorization Token'
/>}

{props.currentUser &&
<Card sx={{ marginTop: '16px' }}>
<CardContent sx={styles.token}>
{props.currentUser.accessToken}
</CardContent>
</Card>}
</div>
)
}

Home.propTypes = {
currentUser: PropTypes.object
}

export default Home
8 changes: 8 additions & 0 deletions client/src/components/home/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const styles = {
token: {
overflowWrap: 'break-word',
fontSize: '12px'
}
}

export default styles
2 changes: 1 addition & 1 deletion client/src/containers/createuser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function CreateUserContainer () {

const onInputChange = (e) => {
const { id, value } = e.target
const key = (id !== undefined) ? id : 'accountlevel'
const key = (id !== undefined) ? id : 'account_level'
setState({ ...state, [key]: value })

if (loading.error !== '' || loading.message !== '') {
Expand Down
7 changes: 4 additions & 3 deletions server/src/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
} = require('./user')

const validFirebaseToken = require('../middleware/valid-token')
const isSuperAdmin = require('../middleware/superadmin')

// ----------------------------------------
// USERS
Expand Down Expand Up @@ -59,7 +60,7 @@ const validFirebaseToken = require('../middleware/valid-token')
*
* const result = await axios({ ...obj, url: 'http://localhost:3001/api/user', method: 'POST' })
*/
router.post('/user', validFirebaseToken, createUser)
router.post('/user', validFirebaseToken, isSuperAdmin, createUser)

/**
* @api {patch} /user Update UserRecord
Expand Down Expand Up @@ -93,7 +94,7 @@ router.post('/user', validFirebaseToken, createUser)
*
* const res = await axios({ ...obj, url: 'http://localhost:3001/api/user', method: 'PATCH' })
*/
router.patch('/user', validFirebaseToken, updateUser)
router.patch('/user', validFirebaseToken, isSuperAdmin, updateUser)

/**
* @api {delete} /user/:uid Delete UserRecord
Expand All @@ -117,7 +118,7 @@ router.patch('/user', validFirebaseToken, updateUser)
*
* await axios.delete('http://localhost:3001/api/user/6uHhmVfPdjb6MR4ad5v9Np38z733', obj)
*/
router.delete('/user/:uid', validFirebaseToken, deleteUser)
router.delete('/user/:uid', validFirebaseToken, isSuperAdmin, deleteUser)

/**
* @api {get} /user Get UserRecord
Expand Down
11 changes: 11 additions & 0 deletions server/src/middleware/superadmin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { ACCOUNT_LEVEL } = require('../utils/constants')

const isSuperAdmin = async (req, res, next) => {
if (req.user.account_level === ACCOUNT_LEVEL.SUPERADMIN) {
next()
} else {
res.status(403).send('Unauthorized. Not a superadmin.')
}
}

module.exports = isSuperAdmin
8 changes: 8 additions & 0 deletions server/src/utils/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const ACCOUNT_LEVEL = {
SUPERADMIN: 1,
ADMIN: 2
}

module.exports = {
ACCOUNT_LEVEL
}

0 comments on commit 9da5f1b

Please sign in to comment.