wbmnfktr Posted November 20, 2021 Share Posted November 20, 2021 Maybe I missed a lot of things or the day was way too long, yet... the question is here and around. How do I grant permissions to modules and their actions/settings/whatever for (restricted) Roles when there is nothing like a permission within those modules? In this case I looked for a permission for ImportPagesCSV... the module itself doesn't have any permissions set (as far as I can tell) compared to ProcessJumplinks (L:477). Never needed this kind of detailed user settings so far... so please enlighten me or at least point me into a direction... or the easier way: place a way bigger stone on the one I live under. Thanks in advance, guys! Link to comment Share on other sites More sharing options...
Robin S Posted November 20, 2021 Share Posted November 20, 2021 5 hours ago, wbmnfktr said: How do I grant permissions to modules and their actions/settings/whatever for (restricted) Roles when there is nothing like a permission within those modules? You would need to edit the module to add the permission settings in the getModuleInfo() method or equivalent "info" file. You can refer to Ryan's ProcessHello module as an example: // name of permission required of users to execute this Process (optional) 'permission' => 'helloworld', // permissions that you want automatically installed/uninstalled with this module (name => description) 'permissions' => array( 'helloworld' => 'Run the HelloWorld module' ), If you want the permission to be automatically installed you would need to uninstall and then reinstall the module. 1 Link to comment Share on other sites More sharing options...
BitPoet Posted November 20, 2021 Share Posted November 20, 2021 8 hours ago, wbmnfktr said: In this case I looked for a permission for ImportPagesCSV... the module itself doesn't have any permissions set In that case, the most straight forward approach is to add a custom permission through the backend (e.g. 'import-pages'), hook before your module's execute method and check if the current user has this permission. Untested code for site/ready.php: <?php namespace ProcessWire; wire()->addHookBefore("ImportPagesCSV::execute", function(HookEvent $event) { if(wire('user')->isSuperuser() || wire('user')->hasPermission('import-pages')) return; $event->return = '<h3>You do not have permission to import pages. Please contact the administrator!</h3>'; $event->replace = true; }); Of course, this still leaves the backend menu item in place, but unlike modifying third party modules, it is upgrade safe. 4 1 Link to comment Share on other sites More sharing options...
wbmnfktr Posted November 22, 2021 Author Share Posted November 22, 2021 Thanks @Robin S. I'll add those settings/permissions to my modules later on. Just in case. For 3rd party modules I might to keep it a bit more future-proof. Thanks @BitPoet. Your untested but working code was the solution for my upcoming problems here. That it's safe for future updates is one of the best parts. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now