diff --git a/jams-react-client/src/auth.js b/jams-react-client/src/auth.js index 39c82ead1b293b70efa2a7e0335202213c999501..c77574c550318926e3280fe0fae62cabd7d5aae5 100644 --- a/jams-react-client/src/auth.js +++ b/jams-react-client/src/auth.js @@ -14,6 +14,8 @@ class Auth { this.admin = false this.installed = false this.uri = '' + this.adminScope = true + this.username = '' } setJWT(access_token) { @@ -30,6 +32,9 @@ class Auth { axios(configApiCall(api_path_post_auth_login, "POST", jsonData, null)).then((response) => { if(response.status == 200){ this.setJWT(response.data['access_token']) + this.adminScope = JSON.parse(atob(response.data['access_token'].split('.')[1])).scope == "ADMIN" ? true : false; + if(!this.adminScope) + this.username= jsonData.username this.authenticated = true } cb() @@ -41,6 +46,8 @@ class Auth { logout(cb) { this.deleteJWT() this.authenticated = false + this.username='' + this.adminScope = true cb() } @@ -101,6 +108,14 @@ class Auth { return this.admin } + hasAdminScope(){ + return this.adminScope + } + + getUsername(){ + return this.username + } + isInstalled() { return this.installed } diff --git a/jams-react-client/src/views/UserProfile/UserProfile.js b/jams-react-client/src/views/UserProfile/UserProfile.js index 12f4131a310502fa02cb6ade74d3b6130f5a7bb5..a0ab97fdb830618f474eabcccd3c191f4fcc53fa 100755 --- a/jams-react-client/src/views/UserProfile/UserProfile.js +++ b/jams-react-client/src/views/UserProfile/UserProfile.js @@ -90,7 +90,7 @@ const styles = { const useStyles = makeStyles(styles); -export default function UserProfile() { +export default function UserProfile(props) { const classes = useStyles(); const [value, setValue] = React.useState(0); diff --git a/jams-react-client/src/views/Users/Users.js b/jams-react-client/src/views/Users/Users.js index bf2a4d0e0e61bcf6a745d80f42a8d5972d8ba973..bf524c105c752716f41682124d5abe375c67354e 100644 --- a/jams-react-client/src/views/Users/Users.js +++ b/jams-react-client/src/views/Users/Users.js @@ -22,6 +22,7 @@ import BusinessOutlinedIcon from '@material-ui/icons/BusinessOutlined'; import MailOutlineIcon from '@material-ui/icons/MailOutline'; import axios from "axios"; import configApiCall from "api.js"; +import auth from "auth.js" import { api_path_get_user_directory_search } from "globalUrls"; import AddCircleOutlineIcon from '@material-ui/icons/AddCircleOutline'; @@ -84,13 +85,13 @@ export default function Users() { return new File([u8arr], filename, {type:mime}); } - if (selectedProfile) { + if (selectedProfile || !auth.hasAdminScope()) { return ( <div> - <Button variant="contained" color="info" href="#contained-buttons" onClick={redirectToUsers}> + {auth.hasAdminScope() && <Button variant="contained" color="info" href="#contained-buttons" onClick={redirectToUsers}> <KeyboardReturnIcon /> - </Button> - <UserProfile /> + </Button>} + <UserProfile username={auth.getUsername()}/> </div> ) } else {