-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.tsx
85 lines (80 loc) · 3.1 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { AppBar, Box, Container, Toolbar } from '@mui/material'
import { Fragment } from 'react'
import { checkUserAccess, getFullStudyProgrammeRights, isDefaultServiceProvider } from '@/common'
import { hasFullAccessToTeacherData } from '@/components/Teachers/util'
import { useGetAuthorizedUserQuery } from '@/redux/auth'
import { Logo } from './Logo'
import { NavigationButton } from './NavigationButton'
import { NavigationDivider } from './NavigationDivider'
import { NavigationItem, navigationItems } from './navigationItems'
import { UserButton } from './UserButton'
export const NavigationBar = () => {
const { fullAccessToStudentData, isAdmin, isLoading, programmeRights, roles, iamGroups } = useGetAuthorizedUserQuery()
const fullStudyProgrammeRights = getFullStudyProgrammeRights(programmeRights)
const getVisibleNavigationItems = () => {
const visibleNavigationItems: Record<string, NavigationItem> = {}
if (isLoading) {
return visibleNavigationItems
}
Object.keys(navigationItems).forEach(key => {
if (key === 'populations') {
if (!fullAccessToStudentData && programmeRights.length === 0) return
}
if (key === 'students') {
if (
!checkUserAccess(['admin', 'fullSisuAccess', 'studyGuidanceGroups'], roles) &&
fullStudyProgrammeRights.length === 0
) {
return
}
} else if (key === 'courseStatistics') {
if (
!checkUserAccess(['admin', 'fullSisuAccess', 'courseStatistics'], roles) &&
fullStudyProgrammeRights.length === 0
) {
return
}
} else if (key === 'faculty') {
if (!checkUserAccess(['admin', 'fullSisuAccess', 'facultyStatistics'], roles)) return
} else if (key === 'feedback') {
if (!isDefaultServiceProvider()) return
} else if (key === 'admin') {
if (!isAdmin) return
} else if (key === 'teachers') {
if (!checkUserAccess(['teachers'], roles) && !hasFullAccessToTeacherData(roles, iamGroups)) {
return
}
}
const { reqRights } = navigationItems[key]
if (!reqRights || reqRights.every(role => roles.includes(role))) {
visibleNavigationItems[key] = navigationItems[key]
}
})
return { ...visibleNavigationItems }
}
const visibleNavigationItems = getVisibleNavigationItems()
return (
<AppBar position="static">
<Container maxWidth="xl">
<Toolbar disableGutters>
<Logo />
{!isLoading && (
<>
<Box data-cy="nav-bar" sx={{ display: 'flex', flexGrow: 1, justifyContent: 'space-between' }}>
<NavigationDivider />
{Object.values(visibleNavigationItems).map(item => (
<Fragment key={item.key}>
{['feedback', 'admin'].includes(item.key) && <NavigationDivider />}
<NavigationButton item={item} />
</Fragment>
))}
<NavigationDivider />
</Box>
<UserButton />
</>
)}
</Toolbar>
</Container>
</AppBar>
)
}