Plugin permissions - Infomaker/Dashboard-Plugin GitHub Wiki
This feature is coming with IMID integration
plugin permissions
functionality you will be able to control who can use your plugin or a part of it or to use some functionality or... you are smart you got the picture 🤓
With How to use:
- First with
plugin permissions
you need to registerpermission keys
to be used in your plugin code. - Each key will be an
ID
for you to check in your code if the current user can use/see a button for example or can do an action maybe 🤔 you decide! - The applied roles comes from
Plugin permissions
section in the installed plugin -> about. - Only the
Admin
can change the roles and remove them for users.
Sounds confusing? let's dig in and see how it looks, shall we 😎
Register a key:
with register
function you were be able to register an Application, Widget, Agent, Health, reducer, bundle...
and now you can register your permissions by passing an array of your key objects with permissionKeys
property, ex:
Dashboard.register({
bundle: "@plugin_bundle",
application: Application,
permissionKeys: [
{
label: 'Create Item',
id: '@plugin_bundle-create-item',
description: 'Create items for specific list within the column view.'
},
{
label: 'Update Item',
id: '@plugin_bundle-update-item',
description: 'Update items for specific list within the column view.'
},
{
label: 'Delete Item',
id: '@plugin_bundle-delete-item',
description: 'Delete cards from the sidebar of the application'
},
{
label: 'Modify list items',
id: '@plugin_bundle-whatever',
description: 'Create items for specific list within the column view.'
},
]
})
Property | Description |
---|---|
label |
Your key name. |
id |
Your key id, Tip: should be unique and explain it self 😉 |
description |
A description for your key, what it does and what is it for! |
Q: How my keys look in
Plugin permissions
?
A:
Use your key in your code:
With Plugin permissions
functionality we add a function called hasPermission
to check if the current user has a permission to see/use your Component/do an action "you name it!"
you can call it from Dashboard components Application, Widget, Health and Agent
, ex:
Display a create button if the user have a permission.
import { Application } from 'Dashboard'
class MyComponent extends Application {
render() {
const hasPermission = this.hasPermission('@plugin_bundle-create-item')
return (
<>
{ hasPermission && <GUI.Button text={'Create'}/> }
</>
)
}
}
You can see that we called this.hasPermission() with passing the permission key that we have registered before 👆🏽 , and this.hasPermission() will return a Boolean
value true if the current user have a permission and false if not!