Creating a hierarchy of users with the Drupal Subuser module
Share with Others
In this episode we cover the Drupal Subuser module. This module makes it easy to allow your users to manage other users on your site. This works great if you want to allow a site manager to be able to add in users of a specific role, but not have access to the full Drupal User Administration pages.
In the video we go through the following example. Imagine you have a “manager” role that needs to be able to create users with the “reviewer” role. This might be a use case for larger blogs with content managers, content reviewers, content editors, etc. This way a manager can safely manage the “reviewers” of the site, without having to worry about accidentally giving them the “administrator” role.
Using the Drupal 7 Subuser module you are able to define permissions to pick which roles a user can create, and to also decide if the user can edit and delete their subusers. The module also provides a simple interface for viewing and managing a users subusers.
Overall a pretty handy module that I think a lot of larger sites might have a use for. Check it out and let me know what you think!
Hello everyone and welcome to another Daily Dose of Drupal. Today we’re on episode number 198. And today we’re going to be going over the Sub-User Module. The Sub-User Module allows you to create a user and then have that user be able to create users underneath themselves so you could have and what our example is going to be is a manager user that can create a content reviewers underneath them and then you can give them permissions to control, if they can edit or delete those sub-users and you can do all kinds of cool things.
So we’re going to be going over that today, but before we get started make sure to follow me on Twitter at smthomas3 if you haven’t already and check out codekarate.com. Make sure you’ll get some of the other videos and posts and you can learn a lot about Drupal and click this little link over here for the free sticker giveaway if you haven’t already and we will send you a Code Karate sticker right to your door. So let’s go ahead and get started.
We have our development site here that we will be working on and I’m going to go ahead and turn on the sub-user modules. The two we’re going to be going on today are just the sub-user and the sub-user UI. The Sub-User Switch Module allows you to switch to a sub-user or login as a sub-user. We won’t be going over that one. You can see I’m using the dev version, you shouldn’t have to use the dev version, but I was doing some testing. It does require the relation module so you’ll need to have that downloaded and installed in order for this to work.
So we’re going to go ahead and install this. And the next step, once these are installed, is to go to the permissions page and set permissions for the sub-user module. So I’m going to go ahead and sort this just for Sub-User permissions. And you can see we have a list of permissions here. The important one that you need to have is to allow them to create enough authenticated user. So in this case you can see I have a manager role and a reviewer role. Well what I would like to do is to allow the manager to create other accounts and possibly give those accounts a reviewer role so that I could either create just authenticated users or an actual authenticated user with reviewer role.
So in order to do that I need to make sure they have the manager account or manager role has create an authenticated permission check. I’m also going to give it create a reviewer permission. So let’s save that and what we will do is we will go ahead and create an account called Manager Quick and we will give it the manager role and in this case you’ll notice there’s a field, it’s user relations, so the store relationship that will allow for the management of the user. So I’ll go ahead and allow that. And just to check, you’ll notice that when you come to your account page, when I click over here there’s a sub-users option here. Under Sub-Users, I now have this manager option. So now this manager is technically a sub-user of Code Karate. And so if I edit this, you can see that it’s just like a normal edit page, there’s a sub-user limit.
We will go ahead and login as this manager. And you’ll notice if we go to your My Account page as the manager you’ll see sub-users here. It says the user currently doesn’t have any sub-users which make sense, but you can add a user. So if we click add you get the normal or what looks like the normal user add form. You’ll notice one difference, you don’t see any role selection and I’ll explain why in a second. That’s actually something that should be there, but it’s not showing up currently.
But let’s go ahead and create a reviewer. Okay so now a reviewer has been created. If I come back to my account page and go to sub-users I can see that reviewer one has been created. I don’t have any access to edit this user and currently the user only has the authenticated user role so obviously this isn’t right. So what we can do is let’s come back to our admin side and let’s go back to the permissions page. And let’s give the manager permission to edit sub-users and delete sub-users. So we will go ahead and save that and now if we come back our manager account and we refresh the page, you’ll see I now have Edit and Delete links.
So if I edit this user you will notice the role option does show up and it only shows those roles that I have permission to create for. So I can give them the reviewer role now. I can save that, and now when I come to the sub-users page you’re going to see they have the authenticated and reviewer role. So you might be wondering why you can’t select the actual role when you’re creating the account and there’s actually a bug out here on drupal.org which hopefully…by the time you’re watching this might already be fixed.
If it’s not you can see there’s a solution here and in the next video I’m actually going to show you not using necessarily this solution but how you could debug this and fix it on your own so we’ll get into a little module development and you’ll look at the details of the sub-user module and figure out how you could fix this to kind of work. And then of course you could have posted this issue yourself but we’ll go through that in the next video. But you’ll see what the sub-user module does is it allows you to really create a hierarchy of users of I guess relationships between users.
So, in this case, the manager is the sub-user of the Code Karate account but it also has sub-users of its own. So a manager could then manage multiple reviewers, manage their accounts on their site and they could be in charge of possibly reviewing content. They would only have the permissions that a reviewer would have. Make sure you’re careful of course when you’re giving out these permissions because these…whatever roles you allow to create accounts, they can possibly do things that could harm your site so you want to be very careful with the permissions. You, for example probably don’t want managers being able to create administrators.
So just keep that mind, it’s a really simple to use module, besides that one bug it seems to work really smooth and it allows you to go ahead and create all different kinds of user hierarchies on your site which can be really good especially if you have a lot of content and you want people to review it or you’re creating some kind of social networking site. I can see a lot of users for it.
So go ahead and give the sub-user module a try, make sure to check out codekarate.com, check the next video if you’re interested in learning a little bit of module development on how you could debug the problem that we found earlier on not being to actually select the role when you’re creating the account.
So we’ll do a little module investigation in the next episode. But that’s it for this time, make sure you get your free Code Karate sticker and I will see you next time. Goodbye!