Jump to content

Modules & Permissions (where to set and find those permissions... if any)


wbmnfktr
 Share

Recommended Posts

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

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.

 

  • Thanks 1
Link to comment
Share on other sites

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.

  • Like 4
  • Thanks 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...