Skip to content

Commit

Permalink
[DUOS-3021][risk=no] Handle null roles better (#2523)
Browse files Browse the repository at this point in the history
  • Loading branch information
rushtong authored Apr 4, 2024
1 parent 16ef26c commit 532985a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/AuthenticatedRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const AuthenticatedRoute = ({ component: Component, props: componentProps, roles
// Verifies if user is logged and if the user matches with any component allowed roles which is trying to navigate.
const verifyUser = (allowedComponentRoles, usrRoles) => {
if (Storage.userIsLogged() && usrRoles !== undefined) {
const currentUserRoles = usrRoles.roles.map(roles => roles.name);
const currentUserRoles = (usrRoles.roles) ? usrRoles.roles.map(roles => roles.name) : [];
return allowedComponentRoles.some(
componentRole => (currentUserRoles.indexOf(componentRole) >= 0 || componentRole === Utils.USER_ROLES.all)
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ReportIcon from '@mui/icons-material/Report';
import style from './Notification.module.css';

export const Notification = (props) => {
const {notificationData, index} = props;
const {notificationData, index=1} = props;
let notificationDiv = <div key={index} style={{display: 'none'}}/>;

if (!isEmpty(notificationData)) {
Expand Down
4 changes: 4 additions & 0 deletions src/components/SignIn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Spinner } from './Spinner';
import ReactTooltip from 'react-tooltip';
import { GoogleIS } from '../libs/googleIS';
import eventList from '../libs/events';
import { StackdriverReporter } from '../libs/stackdriverReporter';

export const SignIn = (props) => {
const [clientId, setClientId] = useState('');
Expand Down Expand Up @@ -40,6 +41,9 @@ export const SignIn = (props) => {
const checkToSAndRedirect = async (redirectPath) => {
// Check if the user has accepted ToS yet or not:
const user = await User.getMe();
if (!user.roles) {
await StackdriverReporter.report('roles not found for user: ' + user.email);
}
setUserRoleStatuses(user, Storage);
await onSignIn();
const userStatus = await ToS.getStatus();
Expand Down
2 changes: 1 addition & 1 deletion src/libs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const convertLabelToKey = (label = '') => {
};

export const setUserRoleStatuses = (user, Storage) => {
const currentUserRoles = user.roles.map(roles => roles.name);
const currentUserRoles = (user.roles) ? user.roles.map(roles => roles.name) : [];
user.isChairPerson = currentUserRoles.indexOf(USER_ROLES.chairperson) > -1;
user.isMember = currentUserRoles.indexOf(USER_ROLES.member) > -1;
user.isAdmin = currentUserRoles.indexOf(USER_ROLES.admin) > -1;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/manage_dac/ManageDac.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const ManageDac = function ManageDac() {
const reloadUserRole = useCallback(async () => {
setIsLoading(true);
const currentUser = Storage.getCurrentUser();
const roles = currentUser.roles.map(r => r.name);
const roles = (currentUser.roles) ? currentUser.roles.map(r => r.name) : [];
const role = contains(ADMIN)(roles) ? ADMIN : CHAIR;
let dacIDs = filter({name: CHAIR})(currentUser.roles);
dacIDs = map('dacId')(dacIDs);
Expand Down

0 comments on commit 532985a

Please sign in to comment.