How to develop a Not Permission
1. What is the problem?
You want to configure the userview permissions or form permissions to not be in groups, departments, etc.2. What is your idea of solving the problem?
You can develop a Userview Permission/ Form Permission Plugin to reverse the result of other permission plugins.3. What is the input needed for your plugin?
To develop a Not Permission plugin, consider providing the following as input.- Permission: To configure a Permission plugin to get the result for reversing it.
- Must be Logged In User: The result will only be valid if the user is also a logged-in user.
4. What is the output and expected outcome of your plugin?
The reverse value of the configured permission plugin.5. Is there any resources/API that can be reused?
You can refer to How to develop a Gantt Chart UI Menu on how to reuse an existing plugin.6. Prepare your development environment
You need to always have your Joget DX Source Code ready and built by following this guideline.The following tutorial is prepared with a Macbook Pro and Joget Source Code version 8.0-Snapshot. Please refer to Guideline for Developing a Plugin for other platform commands.
Let's say your folder directory is as follows:
The plugins
directory is the folder you will create and store all your plugins and the jw-community
directory is where the Joget DX Source code is stored.
Run the following command to create a Apache Maven project in plugins
directory.
Then, the shell script will ask you to key in a version for your plugin and ask you for confirmation before generating the Apache Maven project.
We should get the "BUILD SUCCESS" message shown in your terminal and a not_permission
folder created in plugins
folder.
Open the Apache Maven project with your IDE of choice. This tutorial uses NetBeans.
7. Just code it!
a. Extending the abstract class of a plugin type
Create aNotPermission
class under the org.joget.tutorial
package. Then, extend the class with the 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.
b. Implement all the abstract methods
As usual, you have to implement all the abstract methods. You will use theAppPluginUtil.getMessage
method to support i18n and use the MESSAGE_PATH
constant variable for the message resource bundle directory.
Then, you have to do a UI for the admin user to provide inputs for your plugin. In the getPropertyOptions
method, you already specify your Plugin Properties Options definition file is located at /properties/notPermission.json
. Let's create a resources/properties
directory under the not_permission/src/main
directory. After creating the directory, create a file named notPermission.json
in the properties
folder.
In the properties definition options file, you will need to provide options as below. Please note that you can use the @@message.key@@
syntax to support i18n in your properties options.
After doing the properties option to collect input, you can work on the main method of the plugin which is the isAuthorize
method.
c. Manage the dependency libraries of your plugin
There are no extra dependencies for this plugin.
d. Make your plugin internationalization (i18n) ready for you
are using the i18n message key in thegetLabel
and getDescription
method. You also used the i18n message key in your properties options definition as well. So, you will need to create a message resource bundle properties file for your plugin. Create the resources/messages
directory under the not_permission/src/main
directory. Then, create a NotPermission.properties
" file in the folder. In the properties file, let's add all the message keys and their labels as below.
e. Register your plugin to Felix Framework
You will have to register your plugin class in the Activator class (auto-generated in the same class package) to tell Felix Framework that this is a plugin.
f. Build it and testing
Let's build your plugin. Once the building process is done, you will find anot_permission-5.0.0.jar
file is created under the not_permission/target
directory.
Then, let's upload the plugin jar to Manage Plugins. After uploading the jar file, double-check if the plugin is uploaded and activated correctly.
Let's open a userview and change one of the category permissions to Not Permission. You will want the current user to not be in a Managers group.
After completing the configuration and saving the userview, let's test it. First, check if the admin user is not in Managers group.
Check the userview if the Personal category configured is not in the Managers group and is shown correctly.
Now, assign the admin user to the Managers group.
The Personal category has now disappeared.
8. Take a step further, share it or sell it
You can download the source code from not_permission.zip.To download the ready-to-use plugin jar, please find Not Permission at http://marketplace.joget.org/.