Joget DX 8 Stable Released
The stable release for Joget DX 8 is now available, with a focus on UX and Governance.
...
In this tutorial, we will following the guideline of developing a plugin to develop our Not Permission plugin. Please also refer to the very first tutorial วิธีการพัฒนา Bean Shell Hash Variable for more details steps.
I want to configure the userview permission or form permission to not in groups, department or etc.
We can develop a Userview Permission/ Form Permission Plugin to reverse the result of other permission plugins.
To develop a Not Permission plugin, we can consider to provide the following as input.
The reverse value of the configured permission plugin.
You can refer to วิธีการพัฒนา Gantt Chart Userview Menu on how to reuse a existing plugin.
We need to always have our Joget Workflow Source Code ready and builded by following this guideline.
...
Open the maven project with your favour IDE. I will be using NetBeans.
Create a "NotPermission" class under "org.joget.tutorial" package. Then, extend the class with org.joget.apps.userview.model.UserviewPermission abstract class and implement org.joget.apps.form.model.FormPermission interface. Please refer to Userview Permission/ Form Permission Plugin.
As usual, we have to implement all the abstract methods. We will using AppPluginUtil.getMessage method to support i18n and using constant variable MESSAGE_PATH for message resource bundle directory.
...
Code Block | ||
---|---|---|
| ||
@Override public boolean isAuthorize() { boolean isAuthorize = false; try { if ("true".equals(getPropertyString("loggedIn")) && WorkflowUtil.isCurrentUserAnonymous()) { return false; } //get the binder Object permissionData = getProperty("permission"); if (permissionData != null && permissionData instanceof Map) { Map pMap = (Map) permissionData; if (pMap != null && pMap.containsKey("className") && !pMap.get("className").toString().isEmpty()) { PluginManager pluginManager = (PluginManager) AppUtil.getApplicationContext().getBean("pluginManager"); UserviewPermission permission = (UserviewPermission) pluginManager.getPlugin(pMap.get("className").toString()); if (permission != null) { Map pProps = (Map) pMap.get("properties"); permission.setProperties(pProps); permission.setCurrentUser(getCurrentUser()); permission.setRequestParameters(getRequestParameters()); isAuthorize = !permission.isAuthorize(); } } } } catch (Exception e) { LogUtil.error(getClassName(), e, ""); } return isAuthorize; } |
There are no extra dependency for this plugin.
We are using i18n message key in getLabel and getDescription method. We also used i18n message key in our properties options definition as well. So, we will need to create a message resource bundle properties file for our plugin.
...
Code Block |
---|
org.joget.tutorial.NotPermission.pluginLabel=Not Permission org.joget.tutorial.NotPermission.pluginDesc=Used to reverse the result of other permission plugin userview.notpermission.config=Configure Not Permission userview.notpermission.permission=Permission userview.notpermission.loggedIn=Must be Logged In User |
We will have to register our plugin class in Activator class (Auto generated in the same class package) to tell Felix Framework that this is a plugin.
Code Block | ||
---|---|---|
| ||
public void start(BundleContext context) { registrationList = new ArrayList<ServiceRegistration>(); //Register plugin here registrationList.add(context.registerService(NotPermission.class.getName(), new NotPermission(), null)); } |
Let build our plugin. Once the building process is done, we will found a "not_permission-5.0.0.jar" file is created under "not_permission/target" directory.
...
The "Personal" category is now disappeared.
You can download the source code from not_permission.zip.
...