@ -60,68 +60,76 @@ export class PluginManagerSettings {
}
}
/** Clear one permission from a plugin */
/** Clear one permission from a plugin */
clearPersmission ( from , to ) {
clearPersmission ( from , to , method ) {
if ( ! this . permissions [ from ] ) return
if ( this . permissions [ to ] && this . permissions [ to ] [ method ] ) {
delete this . permissions [ from ] [ to ]
delete this . permissions [ to ] [ method ] [ from ]
if ( Object . keys ( this . permissions [ from ] ) . length === 0 ) {
if ( Object . keys ( this . permissions [ to ] [ method ] ) . length === 0 ) {
delete this . permissions [ from ]
delete this . permissions [ to ] [ method ]
}
if ( Object . keys ( this . permissions [ to ] ) . length === 0 ) {
delete this . permissions [ to ]
}
}
yo . update ( this . currentSetting , this . settings ( ) )
yo . update ( this . currentSetting , this . settings ( ) )
}
}
}
/** Clear all persmissions from a plugin */
/** Clear all persmissions from a plugin */
clearAllPersmission ( from ) {
clearAllPersmission ( to ) {
if ( ! this . permissions [ from ] ) return
if ( ! this . permissions [ to ] ) return
delete this . permissions [ from ]
delete this . permissions [ to ]
yo . update ( this . currentSetting , this . settings ( ) )
yo . update ( this . currentSetting , this . settings ( ) )
}
}
settings ( ) {
settings ( ) {
const permissionByModule = ( key , permission ) => {
const permissionByToPlugin = ( toPlugin , funcObj ) => {
const permissionByPlugin = ( name , plugin ) => {
const permissionByFunctions = ( fu ncN ame, fromPlugins ) => {
function updatePermission ( ) {
function updatePermission ( plugin ) {
plugin . allow = ! plugin . allow
self . permissions [ toPlugin ] [ funcName ] [ plugin ] . allow = ! self . permissions [ toPlugin ] [ funcName ] [ plugin ] . allow
}
}
const checkbox = plugin . allow
let self = this
? yo ` <input onchange=" ${ updatePermission } " type="checkbox" checked id="permission- ${ name } " aria-describedby="module ${ key } ask permission for ${ name } " /> `
return Object . keys ( fromPlugins ) . map ( fromName => {
: yo ` <input onchange=" ${ updatePermission } " type="checkbox" id="permission- ${ name } " aria-describedby="module ${ key } ask permission for ${ name } " /> `
const fromPluginPermission = fromPlugins [ fromName ]
const checkbox = fromPluginPermission . allow
? yo ` <input onchange= ${ ( ) => updatePermission ( fromName ) } class="mr-2" type="checkbox" checked id="permission-checkbox- ${ toPlugin } - ${ funcName } - ${ toPlugin } " aria-describedby="module ${ fromPluginPermission } ask permission for ${ funcName } " /> `
: yo ` <input onchange= ${ ( ) => updatePermission ( fromName ) } class="mr-2" type="checkbox" id="permission-checkbox- ${ toPlugin } - ${ funcName } - ${ toPlugin } " aria-describedby="module ${ fromPluginPermission } ask permission for ${ funcName } " /> `
return yo `
return yo `
< div class = "form-group ${css.permissionKey}" >
< div class = "form-group ${css.permissionKey}" >
< div class = "${css.checkbox}" >
< div class = "${css.checkbox}" >
$ { checkbox }
$ { checkbox }
< label for = "permission-${name}" data - id = "pluginManagerSettingsP ermission${name}" > Allow < u > $ { name } < /u> to access <u>${key }</u> < / l a b e l >
< label for = "permission-checkbox- ${toPlugi n}-${funcN ame}-${toPlugin} " data - id = "permission-label- ${toPlugi n}-${funcN ame}-${toPlugin }" > Allow < u > $ { fromName } < /u> to call <u>${funcName }</u> < / l a b e l >
< / d i v >
< / d i v >
< i onclick = "${() => this.clearPersmission(key, name)}" class = "fa fa-trash-alt" data - id = "pluginManagerSettingsRemovePermission${name}" > < / i >
< i onclick = "${() => this.clearPersmission(fromName, toPlugin, funcName)}" class = "fa fa-trash-alt" data - id = "pluginManagerSettingsRemovePermission-${toPlugin}-${funcName}-${toPlugin}" > < / i >
< / d i v > `
< / d i v >
`
} )
}
}
const byModule = Object
const permissionsByFunctions = Object
. keys ( permission )
. keys ( funcObj )
. map ( name => permissionByPlugin ( name , permission [ n ame ] ) )
. map ( fu ncN ame => permissionByFunctions ( funcName , funcObj [ funcN ame ] ) )
return yo `
return yo `
< div >
< div border p - 2 >
< div class = "${css.permissionKey}" >
< div class = "pb-2 ${css.permissionKey}" >
< h6 > $ { key } : < / h 6 >
< h3 > $ { toPlugin } permissions : < / h 3 >
< i onclick = "${() => this.clearAllPersmission(key )}" class = "far fa-trash-alt" data - id = "pluginManagerSettingsClearAllPermission" > < / i >
< i onclick = "${() => this.clearAllPersmission(toPlugin )}" class = "far fa-trash-alt" data - id = "pluginManagerSettingsClearAllPermission-${toPlugin} " > < / i >
< / d i v >
< / d i v >
$ { byModule }
$ { permissionsByFunctions }
< / d i v > `
< / d i v > `
}
}
const permissions = Object
const byToPlugin = Object
. keys ( this . permissions )
. keys ( this . permissions )
. map ( key => permissionByModule ( key , this . permissions [ key ] ) )
. map ( toPlugin => permissionByToPlugin ( toPlugin , this . permissions [ toPlugin ] ) )
const title = permissions . length === 0
const title = byToPlugin . length === 0
? yo ` <h4>No Permission requested yet.</h4> `
? yo ` <h4>No Permission requested yet.</h4> `
: yo ` <h4>Current Permission settings</h4> `
: yo ` <h4>Current Permission settings</h4> `
return yo ` <form class=" ${ css . permissionForm } " data-id="pluginManagerSettingsPermissionForm">
return yo ` <form class=" ${ css . permissionForm } " data-id="pluginManagerSettingsPermissionForm">
$ { title }
$ { title }
< hr / >
< hr / >
$ { permissions }
$ { byToPlugin }
< / f o r m > `
< / f o r m > `
}
}