1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-11 03:34:35 +00:00

Compare commits

...

19 Commits

Author SHA1 Message Date
semantic-release-bot
cb5be1be21 chore(release): 0.15.1 [skip ci]
## [0.15.1](https://github.com/sasjs/server/compare/v0.15.0...v0.15.1) (2022-08-10)

### Bug Fixes

* **web:** fix UI responsiveness ([d99fdd1](d99fdd1ec7))
2022-08-10 10:34:36 +00:00
Allan Bowe
d90fa9e5dd Merge pull request #251 from sasjs/issue-250
fix(web): fix UI responsiveness
2022-08-10 11:29:41 +01:00
d99fdd1ec7 fix(web): fix UI responsiveness 2022-08-10 15:18:05 +05:00
semantic-release-bot
399b5edad0 chore(release): 0.15.0 [skip ci]
# [0.15.0](https://github.com/sasjs/server/compare/v0.14.1...v0.15.0) (2022-08-05)

### Bug Fixes

* after selecting file in sidebar collapse sidebar in mobile view ([e215958](e215958b8b))
* improve mobile view for studio page ([c67d3ee](c67d3ee2f1))
* improve responsiveness for mobile view ([6ef40b9](6ef40b954a))
* improve user experience for adding permissions ([7a162ed](7a162eda8f))
* show logout button only when user is logged in ([9227cd4](9227cd449d))

### Features

* add multiple permission for same combination of type and principal at once ([754704b](754704bca8))
2022-08-05 09:59:19 +00:00
Allan Bowe
1dbc12e96b Merge pull request #249 from sasjs/issue-225
feat: add multiple permission for same combination of type and principal at once
2022-08-05 10:55:32 +01:00
e215958b8b fix: after selecting file in sidebar collapse sidebar in mobile view 2022-08-05 14:18:59 +05:00
9227cd449d fix: show logout button only when user is logged in 2022-08-05 01:22:27 +05:00
c67d3ee2f1 fix: improve mobile view for studio page 2022-08-05 01:10:15 +05:00
6ef40b954a fix: improve responsiveness for mobile view 2022-08-04 22:57:21 +05:00
semantic-release-bot
0d913baff1 chore(release): 0.14.1 [skip ci]
## [0.14.1](https://github.com/sasjs/server/compare/v0.14.0...v0.14.1) (2022-08-04)

### Bug Fixes

* **apps:** App Stream logo fix ([87c03c5](87c03c5f8d))
* **cookie:** XSRF cookie is removed and passed token in head section ([77f8d30](77f8d30baf))
* **env:** check added for not providing WHITELIST ([5966016](5966016853))
* **web:** show login on logged-out state ([f7fcc77](f7fcc7741a))
2022-08-04 12:10:31 +00:00
Allan Bowe
3671736c3d Merge pull request #248 from sasjs/cookies-management
fix(cookie): XSRF cookie is removed and passed token in head section
2022-08-04 13:06:30 +01:00
34cd84d8a9 chore: improve interface for add permission response 2022-08-04 16:34:15 +05:00
Saad Jutt
f7fcc7741a fix(web): show login on logged-out state 2022-08-04 05:39:28 +05:00
Saad Jutt
18052fdbf6 test: fixed failed specs 2022-08-04 04:01:51 +05:00
Saad Jutt
5966016853 fix(env): check added for not providing WHITELIST 2022-08-04 03:32:04 +05:00
Saad Jutt
87c03c5f8d fix(apps): App Stream logo fix 2022-08-04 03:03:27 +05:00
7a162eda8f fix: improve user experience for adding permissions 2022-08-04 02:51:59 +05:00
754704bca8 feat: add multiple permission for same combination of type and principal at once 2022-08-03 23:26:31 +05:00
Saad Jutt
77f8d30baf fix(cookie): XSRF cookie is removed and passed token in head section 2022-08-03 03:38:11 +05:00
20 changed files with 753 additions and 191 deletions

View File

@@ -1,3 +1,36 @@
## [0.15.1](https://github.com/sasjs/server/compare/v0.15.0...v0.15.1) (2022-08-10)
### Bug Fixes
* **web:** fix UI responsiveness ([d99fdd1](https://github.com/sasjs/server/commit/d99fdd1ec7991b94a0d98338d7a7a6216f46ce45))
# [0.15.0](https://github.com/sasjs/server/compare/v0.14.1...v0.15.0) (2022-08-05)
### Bug Fixes
* after selecting file in sidebar collapse sidebar in mobile view ([e215958](https://github.com/sasjs/server/commit/e215958b8b05d7a8ce9d82395e0640b5b37fb40d))
* improve mobile view for studio page ([c67d3ee](https://github.com/sasjs/server/commit/c67d3ee2f102155e2e9781e13d5d33c1ab227cb4))
* improve responsiveness for mobile view ([6ef40b9](https://github.com/sasjs/server/commit/6ef40b954a87ebb0a2621119064f38d58ea85148))
* improve user experience for adding permissions ([7a162ed](https://github.com/sasjs/server/commit/7a162eda8fc60383ff647d93e6611799e2e6af7a))
* show logout button only when user is logged in ([9227cd4](https://github.com/sasjs/server/commit/9227cd449dc46fd960a488eb281804a9b9ffc284))
### Features
* add multiple permission for same combination of type and principal at once ([754704b](https://github.com/sasjs/server/commit/754704bca89ecbdbcc3bd4ef04b94124c4f24167))
## [0.14.1](https://github.com/sasjs/server/compare/v0.14.0...v0.14.1) (2022-08-04)
### Bug Fixes
* **apps:** App Stream logo fix ([87c03c5](https://github.com/sasjs/server/commit/87c03c5f8dbdfc151d4ff3722ecbcd3f7e409aea))
* **cookie:** XSRF cookie is removed and passed token in head section ([77f8d30](https://github.com/sasjs/server/commit/77f8d30baf9b1077279c29f1c3e5ca02a5436bc0))
* **env:** check added for not providing WHITELIST ([5966016](https://github.com/sasjs/server/commit/5966016853369146b27ac5781808cb51d65c887f))
* **web:** show login on logged-out state ([f7fcc77](https://github.com/sasjs/server/commit/f7fcc7741aa2af93a4a2b1e651003704c9bbff0c))
# [0.14.0](https://github.com/sasjs/server/compare/v0.13.3...v0.14.0) (2022-08-02) # [0.14.0](https://github.com/sasjs/server/compare/v0.13.3...v0.14.0) (2022-08-02)

View File

@@ -1,6 +1,6 @@
import path from 'path' import path from 'path'
import express, { ErrorRequestHandler } from 'express' import express, { ErrorRequestHandler } from 'express'
import csrf from 'csurf' import csrf, { CookieOptions } from 'csurf'
import cookieParser from 'cookie-parser' import cookieParser from 'cookie-parser'
import dotenv from 'dotenv' import dotenv from 'dotenv'
@@ -32,9 +32,10 @@ const app = express()
const { PROTOCOL } = process.env const { PROTOCOL } = process.env
export const cookieOptions = { export const cookieOptions: CookieOptions = {
secure: PROTOCOL === ProtocolType.HTTPS, secure: PROTOCOL === ProtocolType.HTTPS,
httpOnly: true, httpOnly: true,
sameSite: PROTOCOL === ProtocolType.HTTPS ? 'none' : undefined,
maxAge: 24 * 60 * 60 * 1000 // 24 hours maxAge: 24 * 60 * 60 * 1000 // 24 hours
} }

View File

@@ -39,12 +39,11 @@ describe('web', () => {
describe('home', () => { describe('home', () => {
it('should respond with CSRF Token', async () => { it('should respond with CSRF Token', async () => {
await request(app) const res = await request(app).get('/').expect(200)
.get('/')
.expect( expect(res.text).toMatch(
'set-cookie', /<script>document.cookie = '(XSRF-TOKEN=.*; Max-Age=86400; SameSite=Strict; Path=\/;)'<\/script>/
/_csrf=.*; Max-Age=86400000; Path=\/; HttpOnly,XSRF-TOKEN=.*; Path=\// )
)
}) })
}) })
@@ -154,10 +153,10 @@ describe('web', () => {
const getCSRF = async (app: Express) => { const getCSRF = async (app: Express) => {
// make request to get CSRF // make request to get CSRF
const { header } = await request(app).get('/') const { header, text } = await request(app).get('/')
const cookies = header['set-cookie'].join() const cookies = header['set-cookie'].join()
const csrfToken = extractCSRF(cookies) const csrfToken = extractCSRF(text)
return { csrfToken, cookies } return { csrfToken, cookies }
} }
@@ -177,7 +176,7 @@ const performLogin = async (
return { cookies: newCookies } return { cookies: newCookies }
} }
const extractCSRF = (cookies: string) => const extractCSRF = (text: string) =>
/_csrf=(.*); Max-Age=86400000; Path=\/; HttpOnly,XSRF-TOKEN=(.*); Path=\//.exec( /<script>document.cookie = 'XSRF-TOKEN=(.*); Max-Age=86400; SameSite=Strict; Path=\/;'<\/script>/.exec(
cookies text
)![2] )![1]

View File

@@ -26,6 +26,7 @@ export const style = `<style>
} }
.app-container .app img{ .app-container .app img{
width: 100%; width: 100%;
height: calc(100% - 30px);
margin-bottom: 10px; margin-bottom: 10px;
border-radius: 10px; border-radius: 10px;
} }

View File

@@ -11,11 +11,15 @@ webRouter.get('/', async (req, res) => {
try { try {
response = await controller.home() response = await controller.home()
} catch (_) { } catch (_) {
response = 'Web Build is not present' response = '<html><head></head><body>Web Build is not present</body></html>'
} finally { } finally {
res.cookie('XSRF-TOKEN', req.csrfToken()) const codeToInject = `<script>document.cookie = 'XSRF-TOKEN=${req.csrfToken()}; Max-Age=86400; SameSite=Strict; Path=/;'</script>`
const injectedContent = response?.replace(
'</head>',
`${codeToInject}</head>`
)
return res.send(response) return res.send(injectedContent)
} }
}) })

View File

@@ -125,8 +125,27 @@ const verifyCORS = (): string[] => {
if (CORS) { if (CORS) {
const corsTypes = Object.values(CorsType) const corsTypes = Object.values(CorsType)
if (!corsTypes.includes(CORS as CorsType)) if (!corsTypes.includes(CORS as CorsType))
errors.push(`- CORS '${CORS}'\n - valid options ${corsTypes}`) errors.push(`- CORS '${CORS}'\n - valid options ${corsTypes}`)
if (CORS === CorsType.ENABLED) {
const { WHITELIST } = process.env
const urls = WHITELIST?.trim()
.split(' ')
.filter((url) => !!url)
if (urls?.length) {
urls.forEach((url) => {
if (!url.startsWith('http://') && !url.startsWith('https://'))
errors.push(
`- CORS '${CORS}'\n - provided WHITELIST ${url} is not valid`
)
})
} else {
errors.push(`- CORS '${CORS}'\n - provide at least one WHITELIST URL`)
}
}
} else { } else {
const { MODE } = process.env const { MODE } = process.env
process.env.CORS = process.env.CORS =

View File

@@ -22,7 +22,7 @@ function App() {
<HashRouter> <HashRouter>
<Header /> <Header />
<Routes> <Routes>
<Route path="/" element={<Login />} /> <Route path="*" element={<Login />} />
</Routes> </Routes>
</HashRouter> </HashRouter>
</ThemeProvider> </ThemeProvider>

View File

@@ -2,16 +2,18 @@ import React, { useState, useEffect, useContext } from 'react'
import { Link, useNavigate, useLocation } from 'react-router-dom' import { Link, useNavigate, useLocation } from 'react-router-dom'
import { import {
Box,
AppBar, AppBar,
Toolbar, Toolbar,
Tabs, Tabs,
Tab, Tab,
Button, Button,
Menu, Menu,
MenuItem MenuItem,
IconButton,
Typography
} from '@mui/material' } from '@mui/material'
import OpenInNewIcon from '@mui/icons-material/OpenInNew' import { OpenInNew, Settings, Menu as MenuIcon } from '@mui/icons-material'
import SettingsIcon from '@mui/icons-material/Settings'
import Username from './username' import Username from './username'
import { AppContext } from '../context/appContext' import { AppContext } from '../context/appContext'
@@ -30,31 +32,38 @@ const Header = (props: any) => {
const [tabValue, setTabValue] = useState( const [tabValue, setTabValue] = useState(
validTabs.includes(pathname) ? pathname : '/' validTabs.includes(pathname) ? pathname : '/'
) )
const [anchorEl, setAnchorEl] = useState<
(EventTarget & HTMLButtonElement) | null const [anchorElNav, setAnchorElNav] = React.useState<null | HTMLElement>(null)
>(null) const [anchorElUser, setAnchorElUser] = React.useState<null | HTMLElement>(
null
)
const handleOpenNavMenu = (event: React.MouseEvent<HTMLElement>) => {
setAnchorElNav(event.currentTarget)
}
const handleOpenUserMenu = (event: React.MouseEvent<HTMLElement>) => {
setAnchorElUser(event.currentTarget)
}
const handleCloseNavMenu = () => {
setAnchorElNav(null)
}
const handleCloseUserMenu = () => {
setAnchorElUser(null)
}
useEffect(() => { useEffect(() => {
setTabValue(validTabs.includes(pathname) ? pathname : '/') setTabValue(validTabs.includes(pathname) ? pathname : '/')
}, [pathname]) }, [pathname])
const handleMenu = (
event: React.MouseEvent<HTMLButtonElement, MouseEvent>
) => {
setAnchorEl(event.currentTarget)
}
const handleClose = () => {
setAnchorEl(null)
}
const handleTabChange = (event: React.SyntheticEvent, value: string) => { const handleTabChange = (event: React.SyntheticEvent, value: string) => {
setTabValue(value) setTabValue(value)
} }
const handleLogout = () => { const handleLogout = () => {
if (appContext.logout) { if (appContext.logout) {
handleClose() handleCloseUserMenu()
appContext.logout() appContext.logout()
} }
} }
@@ -64,43 +73,129 @@ const Header = (props: any) => {
sx={{ zIndex: (theme) => theme.zIndex.drawer + 1 }} sx={{ zIndex: (theme) => theme.zIndex.drawer + 1 }}
> >
<Toolbar variant="dense"> <Toolbar variant="dense">
<img <Box sx={{ display: { xs: 'none', md: 'flex' } }}>
src="logo.png" <img
alt="logo" src="logo.png"
style={{ alt="logo"
width: '35px', style={{
cursor: 'pointer', width: '35px',
marginRight: '25px' height: '35px',
}} marginTop: '9px',
onClick={() => { cursor: 'pointer',
setTabValue('/') marginRight: '25px'
navigate('/') }}
}} onClick={() => {
/> setTabValue('/')
<Tabs navigate('/')
indicatorColor="secondary" }}
value={tabValue}
onChange={handleTabChange}
>
<Tab label="Home" value="/" to="/" component={Link} />
<Tab
label="Studio"
value="/SASjsStudio"
to="/SASjsStudio"
component={Link}
/> />
</Tabs> <Tabs
<Button indicatorColor="secondary"
href={`${baseUrl}/AppStream`} value={tabValue}
target="_blank" onChange={handleTabChange}
rel="noreferrer" >
variant="contained" <Tab label="Home" value="/" to="/" component={Link} />
color="primary" <Tab
size="large" label="Studio"
endIcon={<OpenInNewIcon />} value="/SASjsStudio"
> to="/SASjsStudio"
Apps component={Link}
</Button> />
</Tabs>
<Button
href={`${baseUrl}/AppStream`}
target="_blank"
rel="noreferrer"
variant="contained"
color="primary"
size="large"
endIcon={<OpenInNew />}
>
Apps
</Button>
</Box>
<Box sx={{ flexGrow: 1, display: { xs: 'flex', md: 'none' } }}>
<IconButton size="large" onClick={handleOpenNavMenu} color="inherit">
<MenuIcon />
</IconButton>
<Menu
id="menu-appbar"
anchorEl={anchorElNav}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left'
}}
keepMounted
transformOrigin={{
vertical: 'top',
horizontal: 'left'
}}
open={!!anchorElNav}
onClose={handleCloseNavMenu}
sx={{
display: { xs: 'block', md: 'none' }
}}
>
<MenuItem sx={{ justifyContent: 'center' }}>
<Button
component={Link}
to="/"
onClick={handleCloseNavMenu}
variant="contained"
color="primary"
>
Home
</Button>
</MenuItem>
<MenuItem sx={{ justifyContent: 'center' }}>
<Button
component={Link}
to="/SASjsStudio"
onClick={handleCloseNavMenu}
variant="contained"
color="primary"
>
Studio
</Button>
</MenuItem>
<MenuItem sx={{ justifyContent: 'center' }}>
<Button
href={`${baseUrl}/AppStream`}
target="_blank"
rel="noreferrer"
onClick={handleCloseNavMenu}
variant="contained"
color="primary"
endIcon={<OpenInNew />}
>
Apps
</Button>
</MenuItem>
</Menu>
</Box>
<Box sx={{ display: { xs: 'flex', md: 'none' } }}>
<img
src="logo.png"
alt="logo"
style={{
width: '35px',
height: '35px',
marginTop: '2px',
cursor: 'pointer',
marginRight: '25px'
}}
onClick={() => {
setTabValue('/')
navigate('/')
}}
/>
</Box>
<div <div
style={{ style={{
display: 'flex', display: 'flex',
@@ -110,11 +205,11 @@ const Header = (props: any) => {
> >
<Username <Username
username={appContext.displayName || appContext.username} username={appContext.displayName || appContext.username}
onClickHandler={handleMenu} onClickHandler={handleOpenUserMenu}
/> />
<Menu <Menu
id="menu-appbar" id="menu-appbar"
anchorEl={anchorEl} anchorEl={anchorElUser}
anchorOrigin={{ anchorOrigin={{
vertical: 'bottom', vertical: 'bottom',
horizontal: 'center' horizontal: 'center'
@@ -124,17 +219,30 @@ const Header = (props: any) => {
vertical: 'top', vertical: 'top',
horizontal: 'center' horizontal: 'center'
}} }}
open={!!anchorEl} open={!!anchorElUser}
onClose={handleClose} onClose={handleCloseUserMenu}
> >
{appContext.loggedIn && (
<MenuItem
sx={{ justifyContent: 'center', display: { md: 'none' } }}
>
<Typography
variant="h5"
sx={{ border: '1px solid black', padding: '5px' }}
>
{appContext.displayName || appContext.username}
</Typography>
</MenuItem>
)}
<MenuItem sx={{ justifyContent: 'center' }}> <MenuItem sx={{ justifyContent: 'center' }}>
<Button <Button
component={Link} component={Link}
to="/SASjsSettings" to="/SASjsSettings"
onClick={handleClose} onClick={handleCloseUserMenu}
variant="contained" variant="contained"
color="primary" color="primary"
startIcon={<SettingsIcon />} startIcon={<Settings />}
> >
Settings Settings
</Button> </Button>
@@ -147,7 +255,7 @@ const Header = (props: any) => {
variant="contained" variant="contained"
size="large" size="large"
color="primary" color="primary"
endIcon={<OpenInNewIcon />} endIcon={<OpenInNew />}
> >
Docs Docs
</Button> </Button>
@@ -160,16 +268,21 @@ const Header = (props: any) => {
variant="contained" variant="contained"
color="primary" color="primary"
size="large" size="large"
endIcon={<OpenInNewIcon />} endIcon={<OpenInNew />}
> >
API API
</Button> </Button>
</MenuItem> </MenuItem>
<MenuItem onClick={handleLogout} sx={{ justifyContent: 'center' }}> {appContext.loggedIn && (
<Button variant="contained" color="primary"> <MenuItem
Logout onClick={handleLogout}
</Button> sx={{ justifyContent: 'center' }}
</MenuItem> >
<Button variant="contained" color="primary">
Logout
</Button>
</MenuItem>
)}
</Menu> </Menu>
</div> </div>
</Toolbar> </Toolbar>

View File

@@ -20,7 +20,14 @@ const Username = (props: any) => {
) : ( ) : (
<AccountCircle></AccountCircle> <AccountCircle></AccountCircle>
)} )}
<Typography variant="h6" sx={{ color: 'white', padding: '0 8px' }}> <Typography
variant="h6"
sx={{
color: 'white',
padding: '0 8px',
display: { xs: 'none', md: 'flex' }
}}
>
{props.username} {props.username}
</Typography> </Typography>
</IconButton> </IconButton>

View File

@@ -32,7 +32,13 @@ const BootstrapDialog = styled(Dialog)(({ theme }) => ({
type AddPermissionModalProps = { type AddPermissionModalProps = {
open: boolean open: boolean
handleOpen: Dispatch<SetStateAction<boolean>> handleOpen: Dispatch<SetStateAction<boolean>>
addPermission: (addPermissionPayload: RegisterPermissionPayload) => void addPermission: (
permissions: RegisterPermissionPayload[],
permissionType: string,
principalType: string,
principal: string,
permissionSetting: string
) => void
} }
const AddPermissionModal = ({ const AddPermissionModal = ({
@@ -42,9 +48,9 @@ const AddPermissionModal = ({
}: AddPermissionModalProps) => { }: AddPermissionModalProps) => {
const [paths, setPaths] = useState<string[]>([]) const [paths, setPaths] = useState<string[]>([])
const [loadingPaths, setLoadingPaths] = useState(false) const [loadingPaths, setLoadingPaths] = useState(false)
const [path, setPath] = useState<string>() const [selectedPaths, setSelectedPaths] = useState<string[]>([])
const [permissionType, setPermissionType] = useState('Route') const [permissionType, setPermissionType] = useState('Route')
const [principalType, setPrincipalType] = useState('group') const [principalType, setPrincipalType] = useState('Group')
const [userPrincipal, setUserPrincipal] = useState<UserResponse>() const [userPrincipal, setUserPrincipal] = useState<UserResponse>()
const [groupPrincipal, setGroupPrincipal] = useState<GroupResponse>() const [groupPrincipal, setGroupPrincipal] = useState<GroupResponse>()
const [permissionSetting, setPermissionSetting] = useState('Grant') const [permissionSetting, setPermissionSetting] = useState('Grant')
@@ -72,10 +78,10 @@ const AddPermissionModal = ({
useEffect(() => { useEffect(() => {
setLoadingPrincipals(true) setLoadingPrincipals(true)
axios axios
.get(`/SASjsApi/${principalType}`) .get(`/SASjsApi/${principalType.toLowerCase()}`)
.then((res: any) => { .then((res: any) => {
if (res.data) { if (res.data) {
if (principalType === 'user') { if (principalType.toLowerCase() === 'user') {
const users: UserResponse[] = res.data const users: UserResponse[] = res.data
const nonAdminUsers = users.filter((user) => !user.isAdmin) const nonAdminUsers = users.filter((user) => !user.isAdmin)
setUserPrincipals(nonAdminUsers) setUserPrincipals(nonAdminUsers)
@@ -93,22 +99,40 @@ const AddPermissionModal = ({
}, [principalType]) }, [principalType])
const handleAddPermission = () => { const handleAddPermission = () => {
const addPermissionPayload: any = { const permissions: RegisterPermissionPayload[] = []
path,
type: permissionType, selectedPaths.forEach((path) => {
setting: permissionSetting, const addPermissionPayload: any = {
principalType path,
} type: permissionType,
if (principalType === 'user' && userPrincipal) { setting: permissionSetting,
addPermissionPayload.principalId = userPrincipal.id principalType: principalType.toLowerCase(),
} else if (principalType === 'group' && groupPrincipal) { principalId:
addPermissionPayload.principalId = groupPrincipal.groupId principalType.toLowerCase() === 'user'
} ? userPrincipal?.id
addPermission(addPermissionPayload) : groupPrincipal?.groupId
}
permissions.push(addPermissionPayload)
})
const principal =
principalType.toLowerCase() === 'user'
? userPrincipal?.username
: groupPrincipal?.name
addPermission(
permissions,
permissionType,
principalType,
principal!,
permissionSetting
)
} }
const addButtonDisabled = const addButtonDisabled =
!path || (principalType === 'user' ? !userPrincipal : !groupPrincipal) !selectedPaths.length ||
(principalType.toLowerCase() === 'user' ? !userPrincipal : !groupPrincipal)
return ( return (
<BootstrapDialog onClose={() => handleOpen(false)} open={open}> <BootstrapDialog onClose={() => handleOpen(false)} open={open}>
@@ -122,17 +146,15 @@ const AddPermissionModal = ({
<Grid container spacing={2}> <Grid container spacing={2}>
<Grid item xs={12}> <Grid item xs={12}>
<Autocomplete <Autocomplete
options={paths} multiple
disableClearable disableClearable
value={path} options={paths}
onChange={(event: any, newValue: string) => setPath(newValue)} filterSelectedOptions
renderInput={(params) => value={selectedPaths}
loadingPaths ? ( onChange={(event: any, newValue: string[]) => {
<CircularProgress /> setSelectedPaths(newValue)
) : ( }}
<TextField {...params} autoFocus label="Path" /> renderInput={(params) => <TextField {...params} label="Paths" />}
)
}
/> />
</Grid> </Grid>
<Grid item xs={12}> <Grid item xs={12}>
@@ -154,8 +176,7 @@ const AddPermissionModal = ({
</Grid> </Grid>
<Grid item xs={12}> <Grid item xs={12}>
<Autocomplete <Autocomplete
options={['group', 'user']} options={['Group', 'User']}
getOptionLabel={(option) => option.toUpperCase()}
disableClearable disableClearable
value={principalType} value={principalType}
onChange={(event: any, newValue: string) => onChange={(event: any, newValue: string) =>
@@ -167,7 +188,7 @@ const AddPermissionModal = ({
/> />
</Grid> </Grid>
<Grid item xs={12}> <Grid item xs={12}>
{principalType === 'user' ? ( {principalType.toLowerCase() === 'user' ? (
<Autocomplete <Autocomplete
options={userPrincipals} options={userPrincipals}
getOptionLabel={(option) => option.displayName} getOptionLabel={(option) => option.displayName}

View File

@@ -0,0 +1,120 @@
import React from 'react'
import { Typography, DialogContent } from '@mui/material'
import { BootstrapDialog } from '../../components/modal'
import { BootstrapDialogTitle } from '../../components/dialogTitle'
import { PermissionResponse } from '../../utils/types'
export interface PermissionResponsePayload {
permissionType: string
principalType: string
principal: string
permissionSetting: string
existingPermissions: PermissionResponse[]
newAddedPermissions: PermissionResponse[]
updatedPermissions: PermissionResponse[]
errorPaths: string[]
}
type Props = {
open: boolean
setOpen: React.Dispatch<React.SetStateAction<boolean>>
payload: PermissionResponsePayload
}
const PermissionResponseModal = ({ open, setOpen, payload }: Props) => {
const newAddedPermissionsLength = payload.newAddedPermissions.length
const updatedPermissionsLength = payload.updatedPermissions.length
const existingPermissionsLength = payload.existingPermissions.length
const appliedPermissionsLength =
newAddedPermissionsLength + updatedPermissionsLength
return (
<div>
<BootstrapDialog onClose={() => setOpen(false)} open={open}>
<BootstrapDialogTitle
id="permission-response-modal"
handleOpen={setOpen}
>
Permission Response
</BootstrapDialogTitle>
<DialogContent dividers>
<Typography sx={{ fontWeight: 'bold', marginBottom: '15px' }}>
{`${appliedPermissionsLength} "${payload.permissionSetting}", "${
payload.permissionType
}", "${payload.principalType}", "${payload.principal}" ${
appliedPermissionsLength > 1 ? 'Rules' : 'Rule'
}`}{' '}
Applied:
</Typography>
{newAddedPermissionsLength > 0 && (
<>
<Typography>
{`${newAddedPermissionsLength} ${
newAddedPermissionsLength > 1 ? 'Rules' : 'Rule'
}`}{' '}
Added:
</Typography>
<ul>
{payload.newAddedPermissions.map((permission, index) => (
<li key={index}>{permission.path}</li>
))}
</ul>
</>
)}
{updatedPermissionsLength > 0 && (
<>
<Typography>
{` ${updatedPermissionsLength} ${
updatedPermissionsLength > 1 ? 'Rules' : 'Rule'
}`}{' '}
Updated:
</Typography>
<ul>
{payload.updatedPermissions.map((permission, index) => (
<li key={index}>{permission.path}</li>
))}
</ul>
</>
)}
{existingPermissionsLength > 0 && (
<>
<Typography>
{`${existingPermissionsLength} ${
existingPermissionsLength > 1 ? 'Rules' : 'Rule'
}`}{' '}
Unchanged:
</Typography>
<ul>
{payload.existingPermissions.map((permission, index) => (
<li key={index}>{permission.path}</li>
))}
</ul>
</>
)}
{payload.errorPaths.length > 0 && (
<>
<Typography style={{ color: 'red', marginTop: '10px' }}>
Errors occurred for following paths:
</Typography>
<ul>
{payload.errorPaths.map((path, index) => (
<li key={index}>
<Typography>{path}</Typography>
</li>
))}
</ul>
</>
)}
</DialogContent>
</BootstrapDialog>
</div>
)
}
export default PermissionResponseModal

View File

@@ -31,11 +31,20 @@ const Settings = () => {
<Box <Box
sx={{ sx={{
display: 'flex', display: 'flex',
flexDirection: { xs: 'column', md: 'row' },
marginTop: '65px' marginTop: '65px'
}} }}
> >
<TabContext value={value}> <TabContext value={value}>
<Box component={Paper} sx={{ margin: '0 5px', height: '92vh' }}> <Box
component={Paper}
sx={{
margin: '0 5px',
height: { md: '92vh' },
display: 'flex',
justifyContent: 'center'
}}
>
<TabList <TabList
TabIndicatorProps={{ TabIndicatorProps={{
style: { style: {
@@ -47,7 +56,7 @@ const Settings = () => {
> >
<StyledTab label="Profile" value="profile" /> <StyledTab label="Profile" value="profile" />
{appContext.mode === ModeType.Server && ( {appContext.mode === ModeType.Server && (
<StyledTab label="Permission" value="permission" /> <StyledTab label="Permissions" value="permission" />
)} )}
</TabList> </TabList>
</Box> </Box>

View File

@@ -27,6 +27,9 @@ import { styled } from '@mui/material/styles'
import Modal from '../../components/modal' import Modal from '../../components/modal'
import PermissionFilterModal from './permissionFilterModal' import PermissionFilterModal from './permissionFilterModal'
import AddPermissionModal from './addPermissionModal' import AddPermissionModal from './addPermissionModal'
import PermissionResponseModal, {
PermissionResponsePayload
} from './addPermissionResponseModal'
import UpdatePermissionModal from './updatePermissionModal' import UpdatePermissionModal from './updatePermissionModal'
import DeleteConfirmationModal from '../../components/deleteConfirmationModal' import DeleteConfirmationModal from '../../components/deleteConfirmationModal'
import BootstrapSnackbar, { AlertSeverityType } from '../../components/snackbar' import BootstrapSnackbar, { AlertSeverityType } from '../../components/snackbar'
@@ -36,12 +39,23 @@ import {
PermissionResponse, PermissionResponse,
RegisterPermissionPayload RegisterPermissionPayload
} from '../../utils/types' } from '../../utils/types'
import {
findExistingPermission,
findUpdatingPermission
} from '../../utils/helper'
import { AppContext } from '../../context/appContext' import { AppContext } from '../../context/appContext'
const BootstrapTableCell = styled(TableCell)({ const BootstrapTableCell = styled(TableCell)({
textAlign: 'left' textAlign: 'left'
}) })
const BootstrapGridItem = styled(Grid)({
'&.MuiGrid-item': {
maxWidth: '100%'
}
})
export enum PrincipalType { export enum PrincipalType {
User = 'User', User = 'User',
Group = 'Group' Group = 'Group'
@@ -59,6 +73,20 @@ const Permission = () => {
AlertSeverityType.Success AlertSeverityType.Success
) )
const [addPermissionModalOpen, setAddPermissionModalOpen] = useState(false) const [addPermissionModalOpen, setAddPermissionModalOpen] = useState(false)
const [openPermissionResponseModal, setOpenPermissionResponseModal] =
useState(false)
const [permissionResponsePayload, setPermissionResponsePayload] =
useState<PermissionResponsePayload>({
permissionType: '',
principalType: '',
principal: '',
permissionSetting: '',
existingPermissions: [],
newAddedPermissions: [],
updatedPermissions: [],
errorPaths: []
})
const [updatePermissionModalOpen, setUpdatePermissionModalOpen] = const [updatePermissionModalOpen, setUpdatePermissionModalOpen] =
useState(false) useState(false)
const [deleteConfirmationModalOpen, setDeleteConfirmationModalOpen] = const [deleteConfirmationModalOpen, setDeleteConfirmationModalOpen] =
@@ -181,29 +209,77 @@ const Permission = () => {
setFilterApplied(false) setFilterApplied(false)
} }
const addPermission = (addPermissionPayload: RegisterPermissionPayload) => { const addPermission = async (
permissionsToAdd: RegisterPermissionPayload[],
permissionType: string,
principalType: string,
principal: string,
permissionSetting: string
) => {
setAddPermissionModalOpen(false) setAddPermissionModalOpen(false)
setIsLoading(true) setIsLoading(true)
axios
.post('/SASjsApi/permission', addPermissionPayload) const newAddedPermissions: PermissionResponse[] = []
.then((res: any) => { const updatedPermissions: PermissionResponse[] = []
fetchPermissions() const errorPaths: string[] = []
setSnackbarMessage('Permission added!')
setSnackbarSeverity(AlertSeverityType.Success) const existingPermissions: PermissionResponse[] = []
setOpenSnackbar(true) const updatingPermissions: PermissionResponse[] = []
}) const newPermissions: RegisterPermissionPayload[] = []
.catch((err) => {
setModalTitle('Abort') permissionsToAdd.forEach((permission) => {
setModalPayload( const existingPermission = findExistingPermission(permissions, permission)
typeof err.response.data === 'object' if (existingPermission) {
? JSON.stringify(err.response.data) existingPermissions.push(existingPermission)
: err.response.data return
) }
setOpenModal(true)
}) const updatingPermission = findUpdatingPermission(permissions, permission)
.finally(() => { if (updatingPermission) {
setIsLoading(false) updatingPermissions.push(updatingPermission)
}) return
}
newPermissions.push(permission)
})
for (const permission of newPermissions) {
await axios
.post('/SASjsApi/permission', permission)
.then((res) => {
newAddedPermissions.push(res.data)
})
.catch((error) => {
errorPaths.push(permission.path)
})
}
for (const permission of updatingPermissions) {
await axios
.patch(`/SASjsApi/permission/${permission.permissionId}`, {
setting: permission.setting === 'Grant' ? 'Deny' : 'Grant'
})
.then((res) => {
updatedPermissions.push(res.data)
})
.catch((error) => {
errorPaths.push(permission.path)
})
}
fetchPermissions()
setIsLoading(false)
setPermissionResponsePayload({
permissionType,
principalType,
principal,
permissionSetting,
existingPermissions,
updatedPermissions,
newAddedPermissions,
errorPaths
})
setOpenPermissionResponseModal(true)
} }
const handleUpdatePermissionClick = (permission: PermissionResponse) => { const handleUpdatePermissionClick = (permission: PermissionResponse) => {
@@ -280,11 +356,11 @@ const Permission = () => {
) : ( ) : (
<Box className="permissions-page"> <Box className="permissions-page">
<Grid container direction="column" spacing={1}> <Grid container direction="column" spacing={1}>
<Grid item xs={12}> <BootstrapGridItem item xs={12}>
<Paper elevation={3} sx={{ display: 'flex' }}> <Paper elevation={3} sx={{ display: 'flex' }}>
<Tooltip title="Filter Permissions"> <Tooltip title="Filter Permissions">
<IconButton> <IconButton onClick={() => setFilterModalOpen(true)}>
<FilterListIcon onClick={() => setFilterModalOpen(true)} /> <FilterListIcon />
</IconButton> </IconButton>
</Tooltip> </Tooltip>
{appContext.isAdmin && ( {appContext.isAdmin && (
@@ -299,14 +375,14 @@ const Permission = () => {
</Tooltip> </Tooltip>
)} )}
</Paper> </Paper>
</Grid> </BootstrapGridItem>
<Grid item xs={12}> <BootstrapGridItem item xs={12}>
<PermissionTable <PermissionTable
permissions={filterApplied ? filteredPermissions : permissions} permissions={filterApplied ? filteredPermissions : permissions}
handleUpdatePermissionClick={handleUpdatePermissionClick} handleUpdatePermissionClick={handleUpdatePermissionClick}
handleDeletePermissionClick={handleDeletePermissionClick} handleDeletePermissionClick={handleDeletePermissionClick}
/> />
</Grid> </BootstrapGridItem>
</Grid> </Grid>
<BootstrapSnackbar <BootstrapSnackbar
open={openSnackbar} open={openSnackbar}
@@ -340,6 +416,11 @@ const Permission = () => {
handleOpen={setAddPermissionModalOpen} handleOpen={setAddPermissionModalOpen}
addPermission={addPermission} addPermission={addPermission}
/> />
<PermissionResponseModal
open={openPermissionResponseModal}
setOpen={setOpenPermissionResponseModal}
payload={permissionResponsePayload}
/>
<UpdatePermissionModal <UpdatePermissionModal
open={updatePermissionModalOpen} open={updatePermissionModalOpen}
handleOpen={setUpdatePermissionModalOpen} handleOpen={setUpdatePermissionModalOpen}
@@ -478,8 +559,8 @@ const DisplayGroup = ({ group }: DisplayGroupProps) => {
<Typography sx={{ p: 1 }} variant="h6" component="div"> <Typography sx={{ p: 1 }} variant="h6" component="div">
Group Members Group Members
</Typography> </Typography>
{group.users.map((user) => ( {group.users.map((user, index) => (
<Typography sx={{ p: 1 }} component="li"> <Typography key={index} sx={{ p: 1 }} component="li">
{user.username} {user.username}
</Typography> </Typography>
))} ))}

View File

@@ -92,7 +92,7 @@ const PermissionFilterModal = ({
onChange={(event: any, newValue: string[]) => { onChange={(event: any, newValue: string[]) => {
setPathFilter(newValue) setPathFilter(newValue)
}} }}
renderInput={(params) => <TextField {...params} label="URIs" />} renderInput={(params) => <TextField {...params} label="Paths" />}
/> />
</Grid> </Grid>
<Grid item xs={12}> <Grid item xs={12}>

View File

@@ -1,4 +1,11 @@
import React, { useEffect, useRef, useState, useContext } from 'react' import React, {
Dispatch,
SetStateAction,
useEffect,
useRef,
useState,
useContext
} from 'react'
import axios from 'axios' import axios from 'axios'
import { import {
@@ -58,13 +65,17 @@ const StyledTab = styled(Tab)(() => ({
type SASjsEditorProps = { type SASjsEditorProps = {
selectedFilePath: string selectedFilePath: string
setSelectedFilePath: (filePath: string, refreshSideBar?: boolean) => void setSelectedFilePath: (filePath: string, refreshSideBar?: boolean) => void
tab: string
setTab: Dispatch<SetStateAction<string>>
} }
const baseUrl = window.location.origin const baseUrl = window.location.origin
const SASjsEditor = ({ const SASjsEditor = ({
selectedFilePath, selectedFilePath,
setSelectedFilePath setSelectedFilePath,
tab,
setTab
}: SASjsEditorProps) => { }: SASjsEditorProps) => {
const appContext = useContext(AppContext) const appContext = useContext(AppContext)
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)
@@ -81,7 +92,6 @@ const SASjsEditor = ({
const [log, setLog] = useState('') const [log, setLog] = useState('')
const [ctrlPressed, setCtrlPressed] = useState(false) const [ctrlPressed, setCtrlPressed] = useState(false)
const [webout, setWebout] = useState('') const [webout, setWebout] = useState('')
const [tab, setTab] = useState('1')
const [runTimes, setRunTimes] = useState<string[]>([]) const [runTimes, setRunTimes] = useState<string[]>([])
const [selectedRunTime, setSelectedRunTime] = useState('') const [selectedRunTime, setSelectedRunTime] = useState('')
const [selectedFileExtension, setSelectedFileExtension] = useState('') const [selectedFileExtension, setSelectedFileExtension] = useState('')
@@ -161,7 +171,7 @@ const SASjsEditor = ({
} }
setLog('') setLog('')
setWebout('') setWebout('')
setTab('1') setTab('code')
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedFilePath]) }, [selectedFilePath])
@@ -200,10 +210,11 @@ const SASjsEditor = ({
setLog(parsedLog) setLog(parsedLog)
setWebout(`${res.data?._webout}`) setWebout(`${res.data?._webout}`)
setTab('2') setTab('log')
// Scroll to bottom of log // Scroll to bottom of log
window.scrollTo(0, document.body.scrollHeight) const logElement = document.getElementById('log')
if (logElement) logElement.scrollTop = logElement.scrollHeight
}) })
.catch((err) => { .catch((err) => {
setModalTitle('Abort') setModalTitle('Abort')
@@ -353,29 +364,24 @@ const SASjsEditor = ({
sx={{ sx={{
borderBottom: 1, borderBottom: 1,
borderColor: 'divider', borderColor: 'divider',
position: 'fixed', background: 'white'
background: 'white',
width: '85%'
}} }}
> >
<TabList onChange={handleTabChange} centered> <TabList onChange={handleTabChange} centered>
<StyledTab label="Code" value="1" /> <StyledTab label="Code" value="code" />
<StyledTab label="Log" value="2" /> <StyledTab label="Log" value="log" />
<StyledTab <StyledTab
label={ label={
<Tooltip title="Displays content from the _webout fileref"> <Tooltip title="Displays content from the _webout fileref">
<Typography>Webout</Typography> <Typography>Webout</Typography>
</Tooltip> </Tooltip>
} }
value="3" value="webout"
/> />
</TabList> </TabList>
</Box> </Box>
<StyledTabPanel <StyledTabPanel sx={{ paddingBottom: 0 }} value="code">
sx={{ paddingBottom: 0, marginTop: '45px' }}
value="1"
>
<Box sx={{ display: 'flex', justifyContent: 'center' }}> <Box sx={{ display: 'flex', justifyContent: 'center' }}>
<RunMenu <RunMenu
fileContent={fileContent} fileContent={fileContent}
@@ -441,14 +447,16 @@ const SASjsEditor = ({
</p> </p>
</Paper> </Paper>
</StyledTabPanel> </StyledTabPanel>
<StyledTabPanel value="2"> <StyledTabPanel value="log">
<div style={{ marginTop: '50px' }}> <div>
<h2>SAS Log</h2> <h2>Log</h2>
<pre>{log}</pre> <pre id="log" style={{ overflow: 'auto', height: '75vh' }}>
{log}
</pre>
</div> </div>
</StyledTabPanel> </StyledTabPanel>
<StyledTabPanel value="3"> <StyledTabPanel value="webout">
<div style={{ marginTop: '50px' }}> <div>
<pre>{webout}</pre> <pre>{webout}</pre>
</div> </div>
</StyledTabPanel> </StyledTabPanel>

View File

@@ -14,6 +14,7 @@ const Studio = () => {
const [searchParams, setSearchParams] = useSearchParams() const [searchParams, setSearchParams] = useSearchParams()
const [selectedFilePath, setSelectedFilePath] = useState('') const [selectedFilePath, setSelectedFilePath] = useState('')
const [directoryData, setDirectoryData] = useState<TreeNode | null>(null) const [directoryData, setDirectoryData] = useState<TreeNode | null>(null)
const [tab, setTab] = useState('code')
useEffect(() => { useEffect(() => {
setSelectedFilePath(searchParams.get('filePath') ?? '') setSelectedFilePath(searchParams.get('filePath') ?? '')
@@ -83,16 +84,20 @@ const Studio = () => {
return ( return (
<Box sx={{ display: 'flex' }}> <Box sx={{ display: 'flex' }}>
<CssBaseline /> <CssBaseline />
<SideBar {tab === 'code' && (
selectedFilePath={selectedFilePath} <SideBar
directoryData={directoryData} selectedFilePath={selectedFilePath}
handleSelect={handleSelect} directoryData={directoryData}
removeFileFromTree={removeFileFromTree} handleSelect={handleSelect}
refreshSideBar={fetchDirectoryData} removeFileFromTree={removeFileFromTree}
/> refreshSideBar={fetchDirectoryData}
/>
)}
<SASjsEditor <SASjsEditor
selectedFilePath={selectedFilePath} selectedFilePath={selectedFilePath}
setSelectedFilePath={handleSelect} setSelectedFilePath={handleSelect}
tab={tab}
setTab={setTab}
/> />
</Box> </Box>
) )

View File

@@ -1,6 +1,15 @@
import React, { useState, useMemo } from 'react' import React, { useState, useMemo } from 'react'
import axios from 'axios' import axios from 'axios'
import { Backdrop, Box, CircularProgress, Drawer, Toolbar } from '@mui/material' import {
Backdrop,
Box,
Paper,
CircularProgress,
Drawer,
Toolbar,
IconButton
} from '@mui/material'
import { FolderOpen } from '@mui/icons-material'
import TreeView from '../../components/tree' import TreeView from '../../components/tree'
import BootstrapSnackbar, { AlertSeverityType } from '../../components/snackbar' import BootstrapSnackbar, { AlertSeverityType } from '../../components/snackbar'
@@ -33,6 +42,17 @@ const SideBar = ({
const [snackbarSeverity, setSnackbarSeverity] = useState<AlertSeverityType>( const [snackbarSeverity, setSnackbarSeverity] = useState<AlertSeverityType>(
AlertSeverityType.Success AlertSeverityType.Success
) )
const [mobileOpen, setMobileOpen] = React.useState(false)
const handleDrawerToggle = () => {
setMobileOpen(!mobileOpen)
}
const handleFileSelect = (filePath: string) => {
setMobileOpen(false)
handleSelect(filePath)
}
const defaultExpanded = useMemo(() => { const defaultExpanded = useMemo(() => {
const splittedPath = selectedFilePath.split('/') const splittedPath = selectedFilePath.split('/')
const arr = [''] const arr = ['']
@@ -147,15 +167,8 @@ const SideBar = ({
.finally(() => setIsLoading(false)) .finally(() => setIsLoading(false))
} }
return ( const drawer = (
<Drawer <div>
variant="permanent"
sx={{
width: drawerWidth,
flexShrink: 0,
[`& .MuiDrawer-paper`]: { width: drawerWidth, boxSizing: 'border-box' }
}}
>
<Backdrop <Backdrop
sx={{ color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }} sx={{ color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }}
open={isLoading} open={isLoading}
@@ -168,7 +181,7 @@ const SideBar = ({
<TreeView <TreeView
node={directoryData} node={directoryData}
selectedFilePath={selectedFilePath} selectedFilePath={selectedFilePath}
handleSelect={handleSelect} handleSelect={handleFileSelect}
deleteNode={deleteNode} deleteNode={deleteNode}
addFile={addFile} addFile={addFile}
addFolder={addFolder} addFolder={addFolder}
@@ -189,7 +202,65 @@ const SideBar = ({
title={modalTitle} title={modalTitle}
payload={modalPayload} payload={modalPayload}
/> />
</Drawer> </div>
)
return (
<>
<Box
component={Paper}
sx={{
margin: '5px',
height: '97vh',
paddingTop: '45px',
display: 'flex',
alignItems: 'flex-start'
}}
>
<IconButton
color="inherit"
size="large"
aria-label="open drawer"
edge="start"
onClick={handleDrawerToggle}
sx={{ left: '5px', display: { md: 'none' } }}
>
<FolderOpen />
</IconButton>
</Box>
<Drawer
variant="temporary"
open={mobileOpen}
onClose={handleDrawerToggle}
ModalProps={{
keepMounted: true // Better open performance on mobile.
}}
sx={{
display: { xs: 'block', md: 'none' },
flexShrink: 0,
[`& .MuiDrawer-paper`]: {
width: 240,
boxSizing: 'border-box'
}
}}
>
{drawer}
</Drawer>
<Drawer
variant="permanent"
sx={{
display: { xs: 'none', md: 'block' },
width: drawerWidth,
flexShrink: 0,
[`& .MuiDrawer-paper`]: {
width: drawerWidth,
boxSizing: 'border-box'
}
}}
>
{drawer}
</Drawer>
</>
) )
} }

View File

@@ -80,7 +80,18 @@ const AppContextProvider = (props: { children: ReactNode }) => {
}) })
.catch(() => { .catch(() => {
setLoggedIn(false) setLoggedIn(false)
axios.get('/') // get CSRF TOKEN // get CSRF TOKEN and set cookie
axios
.get('/')
.then((res) => res.data)
.then((data: string) => {
const result =
/<script>document.cookie = '(XSRF-TOKEN=.*; Max-Age=86400; SameSite=Strict; Path=\/;)'<\/script>/.exec(
data
)?.[1]
if (result) document.cookie = result
})
}) })
axios axios

View File

@@ -13,7 +13,7 @@ code {
} }
.main { .main {
margin-top: 50px; margin: 50px 10px 0 10px;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;

59
web/src/utils/helper.ts Normal file
View File

@@ -0,0 +1,59 @@
import { PermissionResponse, RegisterPermissionPayload } from './types'
export const findExistingPermission = (
existingPermissions: PermissionResponse[],
newPermission: RegisterPermissionPayload
) => {
for (const permission of existingPermissions) {
if (
permission.user?.id === newPermission.principalId &&
hasSameCombination(permission, newPermission)
)
return permission
if (
permission.group?.groupId === newPermission.principalId &&
hasSameCombination(permission, newPermission)
)
return permission
}
return null
}
export const findUpdatingPermission = (
existingPermissions: PermissionResponse[],
newPermission: RegisterPermissionPayload
) => {
for (const permission of existingPermissions) {
if (
permission.user?.id === newPermission.principalId &&
hasDifferentSetting(permission, newPermission)
)
return permission
if (
permission.group?.groupId === newPermission.principalId &&
hasDifferentSetting(permission, newPermission)
)
return permission
}
return null
}
const hasSameCombination = (
existingPermission: PermissionResponse,
newPermission: RegisterPermissionPayload
) =>
existingPermission.path === newPermission.path &&
existingPermission.type === newPermission.type &&
existingPermission.setting === newPermission.setting
const hasDifferentSetting = (
existingPermission: PermissionResponse,
newPermission: RegisterPermissionPayload
) =>
existingPermission.path === newPermission.path &&
existingPermission.type === newPermission.type &&
existingPermission.setting !== newPermission.setting