Drupal how to have certain admins only see the users they've created - drupal

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.

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.

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.

Related

Restrict view access of a Phabricator (Maniphest) Task field to only a specific group of users?

On our company's Phabricator site, for example, I have an Approver select (dropdown) field that is part of the form when I create a new Task. I want only a specific group of people to be able to see this Approver field when someone creates a new Task or edits the Task. Is there any way to accomplish this?
You can create forms for creating maniphest tasks and pre fill them with values. Therefore go to https://<phabricator-uri/transactions/editengine/maniphest.task/ .
You can additionally set permissions to different groups to grant access to these forms.
For more details just read: https://secure.phabricator.com/book/phabricator/article/forms/

Get all user data with custom field drupal 7

I am new to Drupal. How do I get all user data in a single query or function, including extra fields like middle name, phone # from:
Configuration » People » Account settings
I want all the records of all the users, including the extra fields listed above. How can I achieve this?
If the fields are attached to the user : user_load();
Something like :
$user = user_load(1); // 1 = uid of admin user
drupal_set_message($user->field_middle_name); // print a message with your user custom field named middle_name.
If you got many users to load, use user_load_multiple, the perfs will be better.

How can a user choose items from a view?

I've 3 types of users:
Author
Reader
Site Admin
What I've done so far?:
I've created Content Type named Book. Authorscreate account on my site & login & then add the information about the books they authored. I've a View with page-display named books which lists all the books which can be seen even by Anonymous user.
What do I need?
Reader should be able to pick 'x' no. of books from the this view. The no. of books a Reader can pick depends on his level Voracious Reader, Moderate Reader, Occasional Reader.
After Reader choosing Book(s), Site Admin will be see the list of books picked by all Readers.
He'll then ship the book to their address (offline) & update the status as "Shipped".
of course Readers should be able to see the list of all the books they've chosen along with its status.
How do I accomplish the rest?
Install the field collection module.
Create a new field_collection field on the user profile called "ordered books".
Edit your "ordered books" field collection and add 2 fields:
1 called book - this will be an entity reference to your books
content type. You will need the entity reference module for
this.
1 called status. This can be a list with values of "ordered" and
"sent".
Now when users edit their profile then can select which books they want.
You will need to disable the status field at this point to lock it to ordered. (Use hook_form_alter).
Then also using hook_form_alter in a custom module add some extra validation to the user profile form.
In your new validation function check what sort of user is submitting the form (Voracious, Moderate or Occasional) and how many books they have selected and raise any errors as appropriate.
When a user looks back at their profile they will see a list of books and their statuses.
You may want to look into creating a new node type called "orders" or something. This could have an entity reference to the user, and entity references to books. That way you could have a status for the order a a whole as well as the separate books, but this is just an idea - you may not need it.

Drupal 7: dynamic elements/tokens (logged in user's name) in basic page

I'm looking for a simple and clean way to create a basic page that shows something like this:
Hello $user, your ID: $userid
$user and $userid should show respective values. I want to achieve this with Drupal 7 without having to:
enable PHP filter
hack Drupal core files (like http://drupal.org/node/1073886 would do)
use unstable modules (if possible)
create new modules/code (if possible)
Thanks for your help!
You could do this by creating a view using Views module:
set the logged in user as argument.
Then you can add the user name and user id as fields but select not to display them.
Add a global text where you can insert the user id and user name values in the text using placeholders.

Drupal Views Content Profile User as an argument

I have a normal Drupal User. I have used the content_profile module to create a profile content type. This content type contains a node reference to another content type company. The company node then references a type of node called Task.
I want to create a view that list all the tasks for a given user id.
So I imagine I would create a view with an argument of user id. Then I would add the relationship to the profile and the company and output the Task title.
The user id used seems to work on the created used ID and not the user id of the content profile that it is referencing. In our system the "admin" user creates the profiles so it causing some problems.
Any ideas? I feel I may need to write a custom module to do what I want.
i have answered a similar question in the past about how to create a view using part of the url as an argument to filter the view by the user profile. check out this url. the answer you are looking for may be a variation of my original response.
also, how are you creating those profiles? on one of my sites, when i created the profile page, its author ID is automatically changed to the user it is associated with.

Resources