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 How to develop a Bean Shell Hash Variable for more details steps.
Permission: To configure a Permission plugin to get the result for reverse it.
Must be Logged In User: The result will only valid if and only if the user is also a logged in user.
The following of this tutorial is prepared with a Macbook Pro and Joget Source Code version 5.0.0. Please refer to Guideline for developing a plugin for other platform command.
Let said our folder directory as following.
- Home - joget - plugins - jw-community -5.0.1
The "plugins" directory is the folder we will create and store all our plugins and the "jw-community" directory is where the Joget Workflow Source code stored.
Run the following command to create a maven project in "plugins" directory.
cd joget/plugins/ ~/joget/jw-community/5.0.1/wflow-plugin-archetype/create-plugin.sh org.joget.tutorial not_permission 5.0.1
Then, the shell script will ask us to key in a version for your plugin and ask us for confirmation before generate the maven project.
Define value for property 'version': 1.0-SNAPSHOT: : 5.0.0 [INFO] Using property: package = org.joget.tutorial Confirm properties configuration: groupId: org.joget.tutorial artifactId: not_permission version: 5.0.0 package: org.joget.tutorial Y: : y
We should get "BUILD SUCCESS" message shown in our terminal and a "not_permission" folder created in "plugins" folder.
Open the maven project with your favour IDE. I will be using NetBeans.
Then, we have to do a UI for admin user to provide inputs for our plugin. In getPropertyOptions method, we already specify our Plugin Properties Options definition file is locate at "/properties/notPermission.json". Let us create a directory "resources/properties" under "not_permission/src/main" directory. After create the directory, create a file named "notPermission.json" in the "properties" folder.
In the properties definition options file, we will need to provide options as below. Please note that we can use "@@message.key@@" syntax to support i18n in our properties options.
[{ title : '@@userview.notpermission.config@@', properties : [{ name : 'permission', label : '@@userview.notpermission.permission@@', type : 'elementselect', options_ajax : '[CONTEXT_PATH]/web/property/json/getElements?classname=org.joget.apps.userview.model.UserviewPermission', url : '[CONTEXT_PATH]/web/property/json[APP_PATH]/getPropertyOptions' }, { name : 'loggedIn', label : '@@userview.notpermission.loggedIn@@', type : 'checkbox', value : 'true', options : [{ value : 'true', label : '' }] }] }]
After done the properties option to collect input, we can work on the main method of the plugin which is isAuthorize method.
@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; }
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
public void start(BundleContext context) { registrationList = new ArrayList<ServiceRegistration>(); //Register plugin here registrationList.add(context.registerService(NotPermission.class.getName(), new NotPermission(), null)); }
Then, let upload the plugin jar to Manage Plugins. After upload the jar file, double check the plugin is uploaded and activated correctly.
Let us open an userview and change one of the category permission to Not Permission. We will want the current user not in a "Managers" group.
After done the configuration and save the userview. Let us test it. First, check the admin user is not in "Managers" group.
Check the userview, the "Personal" category configured with not in "Managers" group is shown correctly.
Now, assign the "admin" user to "Managers" group.
The "Personal" category is now disappeared.
To download the ready-to-use plugin jar, please find it in http://marketplace.joget.org/.