HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Custom Permission
Hi, Is There any specific way to create our custom permissions.Kindly help!
0
Hi, Is There any specific way to create our custom permissions.Kindly help!
Comments
What do you mean?
There is a good permission grid for categories and users or you can create custom users with custom permissions. What do you want to achieve?
I assume you like to define permissions for your plugin and you want to know how to add them? You can simply do so by namig them in the PluginsInfo array / the addon.json
There is a snippet in the docs about that: https://docs.vanillaforums.com/developer/addons/addon-quickstart/#define-new-permissions
You can also look at the Pockets plugin for an example:
https://github.com/vanilla/addons/blob/release/2.2/plugins/Pockets/class.pockets.plugin.php
https://github.com/vanilla/addons/blob/master/plugins/Pockets/addon.json
Are you allowed to share what you are working on? I'm just super curious!
Actually I am creating my own application.
Here is my controller code--
$userCategories = $this->categoryService->getCategories(['followed'=>true]);
So i want to made a custom permission for this types of restrictions, Some other frameworks provides middlewares types of functionalities for such operations, So I want to know how can we handle this in vanilla.
I would be something like that in the addon.json:
And in your controller you would be able to handle this like that:
By the way: I'm pretty sure you need to write only
redirectTo
and notreturn redirectTo
I am little bit confused now, Where can we set criteria for this 'Plugins.MyAddon.View' to be true. Is there any way where we can set the definition for this permission?
That's the first part of my posting and it is explained in the docs. You simply add the permissions you would like to use to your addon.json file. When the plugin is enabled, all the plugins under the
registerPermissions
key are created automatically.If you change the addon.json during development, you need to delete /cache/addons.php in order to force Vanilla to parse the plugin information again.
You can give default values to this permissions`, see the docs for that.
After you have enabled your plugin, you can see those permissions in the user roles section in the dashboard.