Segmenting users
cosslett - September 17, 2007 - 13:11
I would like to be able to segment my site into hundreds of, well, segments. Each of these segments would have content that could only be viewed and edited by users assigned to the segment (group) in question, and not by other users. How do I do this?

Wow.... that's an interesting one ....
Just thinking on paper... ehhh. keyboard here;
With segments you could talk about a role based system. Drupal, however, accepts for a role the viewing or not of content in general (cant use that one here) and the 'edit own content' (which in this case is too limited), so we are left by the only alternative; building a module of our own.
Module should offer:
1. Segments: Segment administration
2. Users: selection of segment (by administrator)
3. Content: registration of section content belongs to
4. Content: on access check
5 .....
about 3; this wont be needed;
example
access to node 4; we check the creator; uid 2. We check the segment (using our module), find segment 5. The current user accessing node 4 belongs to segment 5? show node.
Now; how to check;
use hook_nodeapi(). on various actions (load, view, edit etc) you need to set actions based on the permission of the user. For edit node you could throw a drupal_access_denied, for a node view in multi node display (arg(0) is NOT 'node') just erase the $node variable in the hook (dirty, i know, but it works) and for a single node view (arg(0) is 'node', arg(1) is a number and arg(2) is not set) throw the drupal_access_denied.
use hook_user() (i think) and hook_form_alter() to be able to select segments (editable only for admins ofcourse, viewable for users)
use hook_menu($may_cache) + a call back for drupal_get_form() to generate the form for segment administration
You might want to allow users to view the members of different segments or just their own; use hook_perm() to define user rights like 'view members of segment', 'view members of all segments' and ofcourse 'administer user segments' (for the team leaders perhaps).
With Drupal, ANYTHING is possible. I learned that in the past 18 months :)
If you never created a module before; this might be a bitch to start with, but its certainly a challenge.
if you need more help and have some patience (busy busy busy) let me know.
Remon.
Thanks for the thoughtful
Thanks for the thoughtful reply. I had no idea this could be so difficult. Have been trying to follow "HowTo: Segment your site with access control" at http://drupal.org/node/153686, which defines access control as "access to certain parts of your site must be restricted to certain users." Thought that was roughly what I was trying to do. Tried to follow instructions to create the first two separate groups, but got messed up. So what am I not getting here? Is it (1) that the author is describing a different situation and you can't do what I want at all with existing modules, or (2) that it becomes more complicated (or impossible) with many ('hundreds') using existing modules and so you're suggesting a module to simplify the process? Thanks for clarification.
What about Taxonomy_access?
Immediate problem seems to be that Taxonomy_access is not installed yet. Will see if that solves it.
organic groups?
Maybe I'm missing something-- but is there a reason you wouldn't want to use organic groups for this? Based on just your brief description above, this exactly what organic groups does. You would just set visibility to "only within the targeted groups".
Re. organic groups
OK, let me try explain a bit more, since the suggestions from you two (which I certainly appreciate) seem to be conflicting. Let's say I want to create 10 groups. I would like to be the one to assign the users to the groups. All content would be specific to one, and only one, of these ten groups. I would like each user, upon login, to be brought to a screen where only content of relevance to his/her group would be visible, a kind of group home-page. Users would then have rights typical of authorized users at any site, i.e., create a blog, comment within a Forum, edit a collaborative page, etc. Their contributions -- and their profiles -- would be visible to members of their group only.
Just to add a twist, it might be nice to allow these externally organized (by me) groups to organize themselves into smaller sub-sets, which would perhaps be the organic groups that you mentioned.
So what do ya'll think?
I still say organic groups
I still say organic groups (with Organic Groups User Roles module for access control) should be exactly what you want-- use closed groups (not subscriptions which means only admin assigns people to groups), make posts default to private to group only. You might have to comment out some code that presents the group visibility option while editing nodes to make it so that users can't change from private posts-- not sure about that. If so, it's trivial to do and I could help you find where to do it.
Organic groups have a built in Home Page so that option is covered. You're just not directed there automatically-- you get the site home page. But I'm fairly certain there is a redirect module that will redirect your users to the page of your choice so you should be able to do that also.
I'm using organic groups + og user roles right now almost exactly as you describe-- except
1) I don't care that users get the "front" page initially-- I use that for info/announcements etc tha i want all groups to see. I then have a menu for folks to quickly navigate to their group home page.
2) I also don't lock posts to one group-- but i do default to private and I use closed non-subscription groups as well. My site is an intranet corporate site.
Of course, with drupal, almost everything can be done multiple ways and each method will have it's proponents. I tend to look for the most easily maintained method and for any group-type application, that's organic groups.
Trying to do it with roles and access control modules is also doable, no question. In fact that's how I was approaching my site (before I discovered the power of the OG family of modules). It seems way more complex and unwieldy to maintain-- for me. YMMV.
In the end with drupal, use whatever method you are most comfortable with.
Edit: one thing i forgot to mention-- many modules are becoming OG aware-- that is they will integrate well with OG so that's also a bonus. If you go the roles/access control method-- you're kind of on your own to make sure the other modules you use will play nicely with your design.
Edit: More Info for you, there's a new module for OG that looks interesting for both our needs:
Haven't tried it yet though it looks promising.
forums
Is it possible to create separate forums for OG users using OG 'out of the box'? I saw mention of a OG Forum module somewhere.
yes
yes
haven't really looked....
Haven't really looked for a module with this description. It's a habit of mine; build build build... :P
Anyways; I haven't looked at organic groups, don't know anything about it :(
I do want to add that I KNOW I often jump to the development of a new module; I like my own coding style and I will know exactly what it does and how it works.
That is by no means a reason that my solution is the only one, on the contrary. There might be a better solution that (even) I didn't think of.
Ah well, just my two cents, hoping it will lead you to a solution of your own :)
LOL, I'm exactly the
LOL, I'm exactly the opposite!
The first thing I do when I need additional functionality is go through the entire modules list (i keep an annotated printout in a binder with my notes about what modules actually do, lol) and see 1) has someone already done this or 2) has someone already done much of it so I only have to adapt it. Only if 1 and 2 are both no do I "build build build", lol.
There are some real GEMS in those modules--- unfortunately, they are very poorly documented in many cases and you have to either load 'em up and take 'em for a test drive or read the code to find out exactly what they do. Most of the descriptions are so minimal as to hide the true power of their functionality, such a shame really. But i learned rather quickly on, playing with a module for an hour or so can save me days or even weeks of coding custom functionality that someone has already tackled-- and usually very well in spite of the lack of clear documentation.
Many thanks to you both.
Many thanks to you both. Looks like I should get started ASAP with one or more of the Organic Groups modules. Which ones exactly do you recommend I start with?
there many to add additional
there many to add additional features, but I would start with organic groups (the base module) and organic groups user roles (the access control module). Learn those, then you can take a look at the others if you need additional functionality.
Hello !! I have started a
Hello !!
I have started a (no-response) thread about a same subject on http://drupal.org/node/174731 and would like to know just a thing about Organic groups...
I have tested it but I don't know if it's possible to do what I want.
I don't want to use powerfull of OG to manage content, but users. I explain : I would like to have an "admin group" role that can have full control on "public" profile fields of users of it's own group ONLY. So "admin_group" role could edit all public field of each profile.
The goal is to have for each group a user who insert some data profile for all members of his group before users starting using the site.
WorldFallz, can you tell me if it's possible, and if it's case, the way to follow to build a correct scheme.
Thanks in advance
Thierry
Will there be just the 2
Will there be just the 2 "groups" or will there be multiple instances of 2 groups... in the first case, then OG is probably overkill and you can setup roles for want you want. In the second case, then you probably want OG. I think of OG as managing multiple groups of roles. In my case i have multiple instances of reader, contributor, editor, & administrator roles-- one for each dept. That would be pretty unwieldy to manage via just roles.
As for field level permissions, that is not something I've had a need for so I'm afraid I don't have much information for you. I'm fairly certain the core profile.module won' be useful to you. But you could look into CCK + CCK Fields + CCK Field Permissions (http://drupal.org/project/cck_field_perms).
I hope that helps...
I just double checked the OG
I just double checked the OG Node authoring permissions, and its a simple check box to force all nodes to be only visible to the group they belong too... no need to comment out anything. very cool.
What happens to search?
I need to divide people into 2-3 groups. But I want the search function to make available only items for the group, not everything. Is this handled automatically?
Thanks
Sorry... I'm not sure about
Sorry... I'm not sure about that and as I don't restrict content like that on my site i have no quick way to test--- either load it up and test it out or post a question in the og or og user roles projects.