Jump to content

Is it possible to permit non-process-modules configurations for non superusers?


blynx
 Share

Recommended Posts

The title says it all, I wonder:

Is it possible to permit non-process-modules configurations for non superusers?

I tried to set up permissions on a module (MarkupSEO) like I would on a process module - but it didn't work ...

Link to comment
Share on other sites

10 hours ago, blynx said:

Is it possible to permit non-process-modules configurations for non superusers?

It's possible, but I don't think there is a way to limit the access to a single module. Module configuration uses the ProcessModule process. If you check the source for that class you can see the permission that is needed to get access to the process: 'module-admin'. So you can create that permission and give it to a role, but then they can configure any installed module, which would be quite dangerous. Also, the modules menu still doesn't appear for the role - you'd have to dig around in the admin theme modules to find out what prevents that menu item from rendering.

An alternative would be to create a custom Process module that provides the same config fields and then save to the MarkupSEO config on page save. Then you can give access to that one Process module.

  • Like 2
Link to comment
Share on other sites

10 hours ago, Robin S said:

An alternative would be to create a custom Process module that provides the same config fields and then save to the MarkupSEO config on page save. Then you can give access to that one Process module.

Thanks for the insight!
Yup. I was thinking about that and will go that route now - stay tuned ;)

  • Like 1
Link to comment
Share on other sites

13 hours ago, Robin S said:

So you can create that permission and give it to a role, but then they can configure any installed module, which would be quite dangerous.

I thought of another option around this: you could give the 'module-admin' permission to the role, and then use a hook to check which module is being requested and only allow access to a particular module.

$this->addHookBefore('ProcessModule::executeEdit', function($event) {
    if(!$this->user->isSuperuser() && $this->input->get->name !== 'MarkupSEO') {
        throw new WirePermissionException('You do not have permission to configure this module.');
    }
});

Now you just need to create a custom link in admin to the module config page, maybe using a simple Process module. Or I think AdminOnSteroids lets you add custom menu items - haven't tried it myself.

  • Like 4
Link to comment
Share on other sites

  • 1 year later...

Just came across this need for the SEO module as well. I have posted this request: https://github.com/processwire/processwire-requests/issues/170

Until there is some progress on that, here is my hacky solution. I am sure it could be improved, but it works for now.

$this->addHookBefore('ProcessModule::executeEdit', function($event) {
    if(!$this->wire('user')->isSuperuser() && $this->wire('input')->get->name !== 'MarkupSEO') {
        throw new WirePermissionException('You do not have permission to configure this module.');
    }
});

$this->addHookAfter('ProcessModule::executeNavJSON', function($event) {
    if(!$this->wire('user')->isSuperuser()) {
        if($this->wire('input')->get->site === '1') {
	    // note \/admin\/module\/ - if your site admin is at /processwire/, then use: \/processwire\/module\/
            $event->return = '{"url":"\/admin\/module\/","label":"Modules","icon":"plug","list":[{"url":"edit?name=MarkupSEO","label":"MarkupSEO","icon":"gear"}]}';
        }
        else {
            $event->return = null;
        }
    }
});

 

That results in this - Modules > Site contains just the SEO link and all the others are empty.

limited_module_permissions.gif.896e7a38ada18078c6a8800d8bbbcb33.gif

 

Thanks @Robin S for the headstart on this!

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

  • 5 years later...

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

×
×
  • Create New...