Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
05862533
Commit
05862533
authored
Aug 26, 2021
by
filip mertens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix permission state handling
parent
63489f5c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
85 deletions
+68
-85
permissionsSettings.tsx
...plugin-manager/src/lib/components/permissionsSettings.tsx
+68
-85
No files found.
libs/remix-ui/plugin-manager/src/lib/components/permissionsSettings.tsx
View file @
05862533
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import
React
,
{
Fragment
,
use
Effect
,
use
State
}
from
'react'
import
React
,
{
Fragment
,
useState
}
from
'react'
/* eslint-disable-line */
/* eslint-disable-line */
import
{
ModalDialog
}
from
'@remix-ui/modal-dialog'
import
{
ModalDialog
}
from
'@remix-ui/modal-dialog'
import
useLocalStorage
from
'../custom-hooks/useLocalStorage'
import
useLocalStorage
from
'../custom-hooks/useLocalStorage'
import
{
PluginPermissions
}
from
'../../types'
import
{
PluginPermissions
}
from
'../../types'
// import { PluginManagerSettings, PluginPermissions } from '../../types'
interface
PermissionSettingsProps
{
interface
PermissionSettingsProps
{
pluginSettings
:
any
pluginSettings
:
any
}
}
function
PermisssionsSettings
({
pluginSettings
}:
PermissionSettingsProps
)
{
function
PermisssionsSettings
({
pluginSettings
}:
PermissionSettingsProps
)
{
/**
* Declare component local state
*/
const
[
modalVisibility
,
setModalVisibility
]
=
useState
<
boolean
>
(
true
)
const
[
modalVisibility
,
setModalVisibility
]
=
useState
<
boolean
>
(
true
)
const
[
permissions
,
setPermissions
]
=
useLocalStorage
<
PluginPermissions
>
(
'plugins/permissions'
,
{}
as
PluginPermissions
)
const
[
permissions
,
setPermissions
]
=
useLocalStorage
<
PluginPermissions
>
(
'plugins/permissions'
,
{}
as
PluginPermissions
)
const
[
checkBoxState
,
setCheckBoxState
]
=
useState
<
boolean
[]
>
(()
=>
{
const
newAllowValues
=
[]
Object
.
keys
(
permissions
).
map
(
topName
=>
{
Object
.
keys
(
permissions
[
topName
]).
map
(
methodName
=>
{
Object
.
keys
(
permissions
[
topName
][
methodName
]).
map
(
pluginName
=>
{
newAllowValues
.
push
(
permissions
[
topName
][
methodName
][
pluginName
].
allow
)
})
})
})
return
newAllowValues
})
const
closeModal
=
()
=>
setModalVisibility
(
true
)
const
closeModal
=
()
=>
setModalVisibility
(
true
)
const
openModal
=
()
=>
{
const
openModal
=
()
=>
{
const
currentValue
=
JSON
.
parse
(
window
.
localStorage
.
getItem
(
'plugins/permissions'
)
||
'{}'
)
const
currentValue
=
JSON
.
parse
(
window
.
localStorage
.
getItem
(
'plugins/permissions'
)
||
'{}'
)
...
@@ -34,29 +21,40 @@ function PermisssionsSettings ({ pluginSettings }: PermissionSettingsProps) {
...
@@ -34,29 +21,40 @@ function PermisssionsSettings ({ pluginSettings }: PermissionSettingsProps) {
setModalVisibility
(
!
modalVisibility
)
setModalVisibility
(
!
modalVisibility
)
}
}
const
handleCheckboxClick
=
(
position
:
number
)
=>
{
const
getState
=
(
targetPlugin
:
string
,
funcName
:
string
,
pluginName
:
string
)
=>
{
const
updatedCheckedState
=
checkBoxState
.
map
((
item
,
index
)
=>
return
permissions
[
targetPlugin
][
funcName
][
pluginName
].
allow
index
===
position
?
!
item
:
item
}
)
setCheckBoxState
(
updatedCheckedState
)
const
handleCheckboxClick
=
(
targetPlugin
:
string
,
funcName
:
string
,
pluginName
:
string
)
=>
{
checkBoxState
.
map
(
value
=>
{
setPermissions
((
permissions
)
=>
{
Object
.
keys
(
permissions
).
map
(
topName
=>
{
permissions
[
targetPlugin
][
funcName
][
pluginName
].
allow
=
!
permissions
[
targetPlugin
][
funcName
][
pluginName
].
allow
Object
.
keys
(
permissions
[
topName
]).
map
(
methodName
=>
{
return
permissions
Object
.
keys
(
permissions
[
topName
][
methodName
]).
map
(
pluginName
=>
{
})
}
function
clearFunctionPermission
(
targetPlugin
:
string
,
funcName
:
string
,
pluginName
:
string
)
{
setPermissions
((
permissions
)
=>
{
delete
permissions
[
targetPlugin
][
funcName
][
pluginName
]
if
(
Object
.
keys
(
permissions
[
targetPlugin
][
funcName
]).
length
===
0
)
delete
permissions
[
targetPlugin
][
funcName
]
if
(
Object
.
keys
(
permissions
[
targetPlugin
]).
length
===
0
)
delete
permissions
[
targetPlugin
]
return
permissions
})
}
})
function
clearTargetPermission
(
targetPlugin
:
string
)
{
})
setPermissions
((
permissions
)
=>
{
})
delete
permissions
[
targetPlugin
]
return
permissions
})
})
}
}
function
ShowPluginHeading
({
headingName
})
{
function
RenderPluginHeader
({
headingName
})
{
return
(
return
(
<
div
className=
"pb-2 remixui_permissionKey"
>
<
div
className=
"pb-2 remixui_permissionKey"
>
<
h3
>
{
headingName
}
permissions:
</
h3
>
<
h3
>
{
headingName
}
permissions:
</
h3
>
<
i
<
i
onClick=
{
()
=>
{
onClick=
{
()
=>
{
clear
Pers
mission
(
headingName
)
clear
TargetPer
mission
(
headingName
)
}
}
}
}
className=
"far fa-trash-alt"
className=
"far fa-trash-alt"
data
-
id=
{
`pluginManagerSettingsClearAllPermission-${headingName}`
}
>
data
-
id=
{
`pluginManagerSettingsClearAllPermission-${headingName}`
}
>
...
@@ -66,26 +64,39 @@ function PermisssionsSettings ({ pluginSettings }: PermissionSettingsProps) {
...
@@ -66,26 +64,39 @@ function PermisssionsSettings ({ pluginSettings }: PermissionSettingsProps) {
)
)
}
}
function
clearAllPersmissions
(
pluginName
:
string
,
topLevelPluginName
:
string
,
funcName
:
string
)
{
function
RenderPermissions
({
targetPlugin
})
{
const
permissionsCopy
=
permissions
// don't mutate state
return
<>
{
Object
.
keys
(
permissions
[
targetPlugin
]).
map
(
funcName
=>
{
if
(
permissionsCopy
[
topLevelPluginName
]
&&
permissionsCopy
[
topLevelPluginName
][
funcName
])
{
return
Object
.
keys
(
permissions
[
targetPlugin
][
funcName
]).
map
((
pluginName
,
index
)
=>
(
delete
permissionsCopy
[
topLevelPluginName
][
funcName
][
pluginName
]
<
div
className=
"form-group remixui_permissionKey"
key=
{
pluginName
}
>
if
(
Object
.
keys
(
permissionsCopy
[
topLevelPluginName
][
funcName
]).
length
===
0
)
{
{
permissions
&&
Object
.
keys
(
permissions
).
length
>
0
delete
permissionsCopy
[
topLevelPluginName
][
funcName
]
?
(
}
<><
div
className=
"remixui_checkbox"
>
if
(
Object
.
keys
(
permissionsCopy
[
topLevelPluginName
]).
length
===
0
)
{
<
span
className=
"mr-2"
>
delete
permissionsCopy
[
topLevelPluginName
]
<
input
}
type=
"checkbox"
}
onChange=
{
()
=>
handleCheckboxClick
(
targetPlugin
,
funcName
,
pluginName
)
}
setPermissions
(
permissionsCopy
)
checked=
{
getState
(
targetPlugin
,
funcName
,
pluginName
)
}
}
id=
{
`permission-checkbox-${targetPlugin}-${funcName}-${pluginName}`
}
aria
-
describedby=
{
`module ${pluginName} asks permission for ${funcName}`
}
/>
function
clearPersmission
(
topLevelPluginName
:
string
)
{
<
label
const
permissionsCopy
=
permissions
className=
"ml-4"
if
(
permissionsCopy
[
topLevelPluginName
])
{
htmlFor=
{
`permission-checkbox-${targetPlugin}-${funcName}-${targetPlugin}`
}
delete
permissionsCopy
[
topLevelPluginName
]
data
-
id=
{
`permission-label-${targetPlugin}-${funcName}-${targetPlugin}`
}
}
>
setPermissions
({}
as
PluginPermissions
)
Allow
<
u
>
{
pluginName
}
</
u
>
to call
<
u
>
{
funcName
}
</
u
>
</
label
>
</
span
>
</
div
><
i
onClick=
{
()
=>
{
clearFunctionPermission
(
targetPlugin
,
funcName
,
pluginName
)
}
}
className=
"fa fa-trash-alt"
data
-
id=
{
`pluginManagerSettingsRemovePermission-${targetPlugin}-${funcName}-${targetPlugin}`
}
/></>
)
:
null
}
</
div
>
))
})
}
</>
}
}
return
(
return
(
...
@@ -104,44 +115,16 @@ function PermisssionsSettings ({ pluginSettings }: PermissionSettingsProps) {
...
@@ -104,44 +115,16 @@ function PermisssionsSettings ({ pluginSettings }: PermissionSettingsProps) {
<
form
className=
"remixui_permissionForm"
data
-
id=
"pluginManagerSettingsPermissionForm"
>
<
form
className=
"remixui_permissionForm"
data
-
id=
"pluginManagerSettingsPermissionForm"
>
<
div
className=
"p-2"
>
<
div
className=
"p-2"
>
{
{
Object
.
keys
(
permissions
).
map
(
toplevelName
=>
(
Object
.
keys
(
permissions
).
map
(
targetPlugin
=>
(
<
ShowPluginHeading
key=
{
toplevelName
}
headingName=
{
toplevelName
}
/>
<>
<
RenderPluginHeader
key=
{
targetPlugin
}
headingName=
{
targetPlugin
}
/>
<
RenderPermissions
targetPlugin=
{
targetPlugin
}
/>
</>
))
))
}
}
{
{
permissions
&&
Object
.
keys
(
permissions
).
length
>
0
?
Object
.
keys
(
permissions
).
map
(
topName
=>
{
permissions
&&
Object
.
keys
(
permissions
).
length
>
0
?
Object
.
keys
(
permissions
).
map
(
targetPlugin
=>
{
return
Object
.
keys
(
permissions
[
topName
]).
map
(
funcName
=>
{
return
Object
.
keys
(
permissions
[
topName
][
funcName
]).
map
((
pluginName
,
index
)
=>
(
<
div
className=
"form-group remixui_permissionKey"
key=
{
pluginName
}
>
{
permissions
&&
Object
.
keys
(
permissions
).
length
>
0
?
(
<><
div
className=
"remixui_checkbox"
>
<
span
className=
"mr-2"
>
<
input
type=
"checkbox"
onChange=
{
()
=>
handleCheckboxClick
(
index
)
}
checked=
{
checkBoxState
[
index
]
}
id=
{
`permission-checkbox-${topName}-${funcName}-${pluginName}`
}
aria
-
describedby=
{
`module ${pluginName} asks permission for ${funcName}`
}
/>
<
label
className=
"ml-4"
htmlFor=
{
`permission-checkbox-${topName}-${funcName}-${topName}`
}
data
-
id=
{
`permission-label-${topName}-${funcName}-${topName}`
}
>
Allow
<
u
>
{
pluginName
}
</
u
>
to call
<
u
>
{
funcName
}
</
u
>
</
label
>
</
span
>
</
div
><
i
onClick=
{
()
=>
{
clearAllPersmissions
(
pluginName
,
topName
,
funcName
)
}
}
className=
"fa fa-trash-alt"
data
-
id=
{
`pluginManagerSettingsRemovePermission-${topName}-${funcName}-${topName}`
}
/></>
)
:
null
}
</
div
>
))
})
})
:
null
})
:
null
}
}
</
div
>
</
div
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment