0

I use Drupal 7 and would prefer to do so but if I need to use Drupal 6 I will. I have a Drupal 7 site that I allow "advisors" to create authenticated users. I am an admin on the site so I see and can do everything. All that an "advisor" can do is create and edit authenticated users. Is there a way to make a view that displays the users that the particular advisor has created while the advisor is logged in?

If you don't understand what I'm saying let me put it this way. I am the admin of the site so I can do everything. I created a user role called advisor. There's also an authenticated role for users. Advisors can create authenticated users. So I have Advisor 1. Advisor 1 created 10 users. I also have Advisor 2. Advisor 2 created 3 users. I'd like a page (more than likely built with views - and I've used views before on other sites so I'm familiar with them) - I'd like a page that Advisor 1 could go to once logged in and it would display all of the 10 users that they created. Advisor 1 wouldn't see the users that Advisor 2 create.

Is this possible? Any help on this would be greatly appreciated. Thank you in advance.

  • This certainly requires building custom features with custom permissions. There is no such features or module(s) available which offer the feature out of the box. – Bhavin Joshi Oct 11 '14 at 05:56

2 Answers2

0

I have implemented something similar and I can give you some guidelines. First of all drupal 7 doesn't store the information of the creator of the users. So, in order to track this you will need to attach a custom field to the user to keep this information.

In such case you ll have to make sure that every creator can insert only himself in this field and not anyone else or you 'll have to find an automated way to fill it in. I suggest you use field permission module for setting permissions to this field (users probably should not even have view, creators should not be able to change it etc ) and computed field module for automatically populate the field (eg creator_field) upon creation for example with the uid of the creator.

Finally when creating the view you could add contextual filtering by using the logged in user on the creator_field.

You should also have a look at Organic Groups. I haven't use it but might be helpful

Hope it helps.

Updated

Add

  global $user;
  $entity_field[0]['value'] = $user -> uid;

to the Computed Code (PHP) in the computed field settings and store the value as integer in "Database store settings". Then in your view you should add a view of user with contextual filter of creator_field. In the contextual filter settings you must set "provide default value" -> "User ID from logged in user" in the "WHEN THE FILTER VALUE IS NOT IN THE URL" section.

geoandri
  • 2,360
  • 2
  • 15
  • 28
  • Thanks, makes sense. I will try it out and let you know how it goes. – mobile phone app developer Oct 12 '14 at 02:41
  • Ok geoandri (or anyone), I need some help. I've added the computed field as you've said but what exactly would I be putting into the "Computed Code (PHP)" field and the "Display Code (PHP)" field within my new field called "creator_field". See this screen grab and you'll se what Drupal put in there as default. http://michaeljbaran.com/field-setting.jpg – mobile phone app developer Oct 14 '14 at 02:00
  • try global $user; $entity_field[0]['value'] = $user -> uid; in the Computed Code and set "database storage setting" to integer. I ll add it to my post also – geoandri Oct 14 '14 at 05:26
  • Ok, I found an error in what I did and was wondering if anyone can help. So I have a computed field that's hidden from display on my site. I wanted to tie the admin who created it to the new user account. This computed field is called "creator_field" and I have the Computed Code (PHP) global $user; $entity_field[0]['value'] = $user -> uid; and I have the Display Code (PHP) $display_output = $entity_field_item['value']; – mobile phone app developer Jan 02 '15 at 20:55
  • This does what I want BUT if another admin (we'll call him admin2) was to edit the new user (we'll call the new user account Bob) that the admin1 created THAN the user account Bob would fall under admin2's user list because they edited it. I'm sure there is any easy fix for this and I just can't figure it out. Anyone have any ideas? Much appreciated and Happy New Year! – mobile phone app developer Jan 02 '15 at 20:55
0

This could be done relatively easily in Drupal 7 by adding a field to the user profile that points back to the user creator (using the Entity Reference module). Profile2 could offer a shortcut to making this field available on a profile, though if this is the only customization that you need to add to your profiles, it would be cleaner to do this in a custom module.

A view (Views module) could be configured to output a list of users with the current logged in user as the creator.

You'll also need to add similar logic for user_access to allow/restrict profile editing (if the current user is the user referenced in the profile). A permissions hook also could be useful if you plan to have different admin levels.

The Tokens module should work to insert this value for the new user, by inserting the current user into the field. Or you can do this before the user is saved. It would go a little something like this:

function mymodule_user_presave(&$edit, $account, $category) {
  if ($account->is_new) {
    global $user; 
    $created_by = $user->uid; 
    $edit['created_by'] = $created_by;
  }
}

Good luck.

baaj
  • 105
  • 5
  • on top from my comment below to geoandri, I tried what you suggested baaj and there's only one thing, how the heck would I get that new field to automatically get populated with the creators ID? I've tried several different approaches and nothing was successful. I don't really care how I get this done as long as I can get it done : ) – mobile phone app developer Oct 14 '14 at 04:40
  • Updated my answer to address your question above – baaj Oct 14 '14 at 11:25