Jump to content

User admin roles..that can only add new users with certain roles


Sinmok
 Share

Recommended Posts

Hello all,

Need a bit of advice.

I have a page structure where users with a specific role either can or can't view the page.

The problem is, is that I need to be able to have users who can add other users..but only assign them to specific roles.

For example:

A manager can add users and assign the roles: 

Supervisor or worker

A supervisor can add users but only assign the new users with the role of worker

A worker can't add any users.

Is this currently possible to do in processwire? If not, how would you go about doing it?

Link to comment
Share on other sites

Depends where you want to start with this really. The very simplest way would be to use Ryan's form builder module. This form could be made available only to each of your two types of users that can create other users. The form builder can publish straight to pages. Users are also just pages. Just make two identical forms, one for managers and one for supervisors; the only difference being one has extra options in the role drop down. Just make sure your fields match the 'user' page fields.

Or, it's fairly simple to make your own user registration page. Create a form in html. Post the form back to the same template and process it.

You'll find $user->hasRole($role) useful.

Here's a simple example from the docs:

<?php
$u = new User(); 
$u->name = "gonzo"; 
$u->pass = "BamBam!";
$u->addRole("guest");  // substitute this for your worker, manager or supervisor role
$u->save();

Both are pretty simple. Personally, I'd start with the do it yourself method so you understand how pw works better. You'll find lot's of help if you have a go.

  • Like 1
Link to comment
Share on other sites

The first question to ask would be, if you want this to happen in the processwire admin backend or via a selfwritten frontend form on your site. The latter is explained by davo, while the first one would need a different approach. Initially the backend only offers a "user-admin" permission, which grants full user editing permission. You would need to enhance the permission management via a small hooking module to get your restrictions working there.

Link to comment
Share on other sites

Yeah, ideally this would all happen in the Processwire admin area.

Small module that checks roles sounds like the best approach, I'm guessing I just need to hook into Page::save and check if the template is a user, and if so, what their roles are.

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...