Not all group types should be listed in the Subgroup parent selector. The OG module will allow for many different group types to be created and each group type can have a vastly different purpose. There should be a way to restrict which group types can be used to build hierarchies.
I'll give my use case as a perfect example.
I'm working on an app that has thousands of "interest groups" which are similar to groups.drupal.org. I also have thousands of "organization groups" that we use to build out the Organizational structure. We also have old legacy groups that need to be around for historical purposes.
Interest groups should not be allowed to have a hierarchy while the organization groups should and legacy groups just need to be ignored.
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | og_subgroups-976042-35.patch | 31.93 KB | bschilt |
| #27 | Screen shot 2011-03-04 at 10.46.47 AM.jpg | 91.56 KB | capellic |
| #26 | og_subgroups-976042-26.patch | 24.78 KB | bschilt |
| #18 | og subgroups patch | 12.52 KB | massud |
| #10 | og_subgroup.patch | 11.59 KB | massud |
Comments
Comment #1
morbiD commentedGood idea. Are you thinking of a simple boolean setting where group types either can be used for all hierarchies, or can't be used for any hierarchies? (That's how it sounds).
Perhaps you could extend the idea so that relationships could be defined between group types.
Imagine you wanted a "Geography" hierarchy and a "Military Ranks" hierarchy. You could optionally define group type relationships of:
Continent => Country => City
Major => Captain => Lieutenant
Then, if you were creating a City you wouldn't get any Majors in the parent selector, and if you were creating a Lieutenant you wouldn't get any Continents in the parent selector.
Comment #2
massud commentedHere is a patch to add this functionality. This adds a "allowed subgroup types" to the content type edit form (in section organic groups) to set allowed subgroup types of a specific group node type. Also this patch adds a link for creating a subgroup to the og block for every allowed subgroup types.
Hope this helps
Comment #3
bschilt commentedMassud, thanks for taking the initiative with this, its a great start. I've reviewed that patch and the functionality that it provides. Below is what I found that needs to be changed/improved before the patch can be accepted.
Let me know if you have questions.
Comment #4
massud commentedBschilt, here is a new patch with some bug fixes and new features. The added variables are now removed during uninstall. In addition, I have implemented a way to configure who can create a subgroup for a group node type ( see #1034024: User can create a child group for a parent that they're not a member of for more information).
I have noticed that there is a misunderstanding that I would like to clear up here:
Finally, since I am not using Hierarchical Select module, unfortunately I am not able to implement parent selector of Hierarchical Select Subgroups module, at the moment.
Comment #5
bschilt commentedthanks for the updated patch. I'll install it and take a look. #1 above definitely clears up the misunderstanding on how you are setting it up. I hadn't envisioned it working that way, but I think its beneficial.
Once the core subgroups module is set up with this new feature I'll take care of the Hierarchical Select module.
I'll get back to you after I review the patch.
Comment #6
morbiD commentedOne thought that occurred to me is that in @massud's example, by defining that "departments" are children of "organisations" and "teams" are children of "departments", you are implicitly restricting your hierarchy to a maximum of 3 levels:
organisation > department > team
However, if your hierarchy is defined such that content type "generic_group" can have children of type "generic_group," that implicit restriction no longer applies, allowing an infinite number of levels:
generic_group > generic_group > generic_group > generic_group > generic_group > generic_group ...and so on.
Does anyone see this as a problem?
Should there be an extra setting for explicitly defining a maximum number of levels under that particular condition?
Comment #7
massud commentedIn response to #6, Although I have not tested - this is possible with the patch and there is no limitation for the levels.
Comment #8
bschilt commentedI'm getting an error when applying the patch and its not creating the og_subgroups.js file.
I'm not able to properly test.
Comment #9
bschilt commented-morbiD-
I don't see this as a problem as some use cases would need to allow for an infinite number of levels to be created. Also having a restricted hierarchy such as organization > department > team would also need to be accommodated. Both of these use cases are exactly what I need to utilize in my projects at work.
I thought about some use cases and here are some examples we can use in developing this patch:
Use case 1: Organic flat groups
Suppose there is a group type called Interest Group. Interest groups would be similar to groups.drupal.org in that groups can be created for a particular subject or interest and hierarchies are not allowed to be created using interest groups.
Use case 2: Organic sub groups
Taking use case #1 a bit further, suppose a site needs to be able to create hierarchies out of the interest groups in order to create something like the following:
In this case a simple or complex hierarchy should be possible and only the interest group type can be use to create the structure. This would allow for an infinite amount of branches to be created.
When adding or editing an interest group hierarchy, all interest groups will need to be selectable in the “Parent” field, represented in hierarchical form.
Use case 3: Pre-defined Hierarchy
In this case a pre-defined hierarchy means that a limited number of levels can be created. Here is a real life example using the Arizona K-12 School system. The structured levels will be Organization > County > District > School.
The Organization group type would be at the top level, County groups can only be children of Organizations, District groups can only be children of County groups and School groups can only be children of Districts.
The patch so far is shaping up to handle these use cases but I can see some areas that need to be adjusted. I'll list my findings once a new patch is posted that I can install.
Comment #10
massud commentedbschilt, sorry for the error. Here is the correct patch.
Comment #11
morbiD commentedYes, I wasn't so much thinking that allowing inifinite levels would be problematic, but rather that the only way to restrict the number of levels is to define multiple content types, which may not fit in with certain use cases.
I was kind of thinking that there could be an optional setting, whereby, if a content type is allowed to be a child of itself, an extra (previously hidden or greyed out) field becomes active in which a maximum number of levels can optionally be set.
I'm just imagining that in your "Use case 2" a site admin may want to limit the number of sub-levels to some arbitrary number to prevent users getting carried away and making site navigation a nightmare. What if a confused or malicious user went and made 100 sub-levels using your Interest Group content type and then your navigation menu or hierarchical select became so bloated that it filled a whole page when those sub-levels were expanded?
Of course, that was already a possibility before this patch, but I think this patch provides a good opportunity to include a prevention mechanism.
Anyhow, this is already a great patch :)
Comment #12
bschilt commented@-morbiD-
yeah you're right about having an optional subgroup limit field to help keep things under control. If massud wants to add it into this patch then cool, other wise we can create a new feature request and get it added in that way.
Comment #13
bschilt commentedI tested the patch and I have identified some issues with each of the use cases described in comment #9.
Testing Use case 1:
When testing this use case (no allowable subgroups have been selected) it functions properly in that I can only create groups at the root level. Here are a few things to improve this functionality.
Testing use case 2:
1. When creating a new interest group from Create content > Interest group (node/add/interest-group) the parent field in the subgroups section only has the top level interest groups. The parent selector needs to return all interest groups in hierarchical order. That way this new interest group can be added as a child to any portion of the tree.
2. Clicking the "Create Interest Group" link from the OG block doesn't work the way I would expect. When I click this link I see that the group's gid is passed in the URL which tells me that the new group will automatically be added as a child to the group represented in the gids[] param. But when submitting, the group is created at the root level. I see that the subgroups fieldset is collapsed and when I open it, is selected. When expanding the Parent field, the options only shows the interest groups at the top level, I can't even select the group thats represented in the URL.
Here's the way I think this link should work when clicked:
Testing use case 3:
The patch is shaping up to handle this use case nicely but I may have encountered a bug when trying to build a structure like: Organization > County > District > School
When creating an organization group called Arizona K-12, it works as expected. When creating a county group called Maricopa it works as expected in that I was able to choose the Arizona K-12 group as the parent. But when trying to create a district group called Mesa Unified District, the parent selector is returning top level and Arizona K-12 only. It should return the county group called Maricopa. So currently I'm unable to build out my pre-defined hierarchy. The Allowed subgroup type variables are set correctly:
I'm not sure whats causing this issue.
Comment #14
massud commentedComment #15
massud commented@-morbiD-
Having an option to limit hierarchy levels is a good idea but let's work on it after fixing the current bugs of the patch.
@bschilt
Thanks for your comprehensive test and feedback.
Use case 1
An option can be added to the subgroups' configuration section in the content type edit form to be able to completely disable subgroups for a specific group type. So, the fieldset will not appear in the node add/edit form if subgroups is disabled for that content type.
Alternatively, "Allowed subgroup types" concept can be replaced by "Allowed parent group types" so that subgroups can be disabled by selecting none of group types as allowed parent and consequently the subgroup fieldset will not shown up in the node add/edit form of that content type.
Use case 2
I have not tested this use case. I will do it and will let you know the result.
Use case 3
There is a conceptual problem with filtering hierarchy tree. Suppose "organization" can have "school" subgroups, too. In other words, a new "school" can be added to "organization" and "district" but "country". How should I filter the hierarchy tree in this case?
I think there is no way to reliably filter the allowed parents while presenting them as a tree (am I wrong?). My solution is not to filter the tree. Instead, selecting disallowed parents can result an error message for the user in the form validation state. I have already implemented such an approach for "Privileged users to create subgroups" feature in the patch. Have you tested it?
Please let me know your thoughts and suggestions.
Comment #16
bschilt commentedThe current version of the module allows for a hierarchy to be created by any group automatically. And any group type can be a parent or child of a different type. I don't want these new settings to change that behavior if the allowed subgroup types is left blank. I don't want this new version to disrupt current installations.
So with that being said I think a checkbox that disables subgroups for a group type is the way we should go. I do like your idea of changing "Allowed subgroup types" to "Allowed parent group types" because it will have a better work flow when defining hierarchies. With the "Allowed subgroup types" method, when I create the Organization group I can't select the County group to be the child because it hasn't been created yet. I then have to return to the Organization content type settings page after the County group has been set up to make County the allowed child. Changing the settings to "Allowed parent group types" would eliminate that workflow.
I need to look further into your comments for Use Case 3 and see what I can come up with for a solution. But as far as user experience goes, I don't want them to be able to select a group then have the form validation tell them that they cannot select it. If they shouldn't select it, it shouldn't be in the Parent selector field.
I have not looked into the "Privileged users to create subgroups" portion of the patch yet. I'm taking this one step at a time.
Comment #17
bschilt commentedI found a bug in the patch that might help make forward progress. In the og_subgroups_tree_recurse() function you added a check in an IF statement that never passes.
Look at
and change it to
I'm not uploading a patch because its a simple change and I don't want to give you any headaches in applying a patch if you've already started modifying the existing one.
Comment #18
massud commentedHere is a new patch. I replaced "Allowed subgroup types" with "Allowed parent group types" and fixed a couple of bugs including the one mentioned in comment #17. Though, the parent tree filtering problem persists (All children groups will be filtered in the tree regardless of allowed parent types if their parent is not allowed to be a parent of that group type).
To keep backward compatibility, all group types are allowed to be the parent by default. So, I think we don't need to add an additional option to disable subgroups.
Comment #19
bschilt commentedThe patch is working better now, still a couple issues I'm finding.
yeah it works well the way you have it. I say we leave it as is and if someone wants it any different they can create a new issue for it.
Use case 1
done!
Use case 2
The functionality for this use case is working great, the only thing I would like to add is a simple UI component:
1. When clicking on "create interest group" from the OG block, a message should be displayed at the top of the form telling the user that the new group will automatically be a child of "blah".
Use case 3
I'm still getting the similar issue that I posted about before. When I try setting up a structure like Organization > County > District > School, the subgoup fieldset is not showing up on the add/edit form for District. Organization and County groups are working great though.
Comment #20
bschilt commentedWas testing out the "Privileged users to create subgroups" portion and it doesn't seem to work. All three settings, Admins, Members, and Everyone doesn't make that link show up. Looks like the link only shows up for the Node author.
It appears that the issue is in the og_subgroups_og_create_links() function, look at:
you are invoking the node_access function which will basically check the user account against all of the privileges found at admin/user/permissions for the node module. In this case it will always return false unless its the node author. You either need to forget about using that IF statement, or look at implementing hook_node_grants function.
Comment #21
massud commentedI tested it again and it works for me. For example, if you would like only the admins of "org" to be able to create a new "dept" in the org -> dept -> team example, you should set the privileged users of "org" content type to "Group administrators" (I think you are setting the dept's).
This is to check if the user has "create" permission for that content type. So, it will return false if the user does not have "create" permission.
By the way, did you think about the subgroups' tree filtering issue? do you have any solution?
Comment #22
bschilt commentedThe privileged users to create subgroups feature is working, but I guess I assumed it would or should work a bit differently. I was able to get it to work when I gave my test users the "create content" permission. I could then toggle the radio button between group members and group admins and that link would show and hide properly.
The "Everyone" option doesn't work due to the fact that the Group Details block is only available to group members, otherwise that block just has a "Join" link. To me, "Everyone" means any non member could create a subgroup. Is that what its supposed to do? Explain your intentions behind the Everyone setting.
It would be nice to have the privileged users to create subgroups settings not rely on the node create permissions. Look at my scenario...
I have a normal group member with no extra privileges and I have "group member" selected for the privileged users to create subgroups field. When that user visits the group page, the "Create Interest Group" link does not show up. I give that user the create interest_group content permission and now that link shows up. The problem with that is now this user has access to Drupal's default "Create Content" link (node/add) and can create interest groups all he wants.
Comment #23
bschilt commentedRegarding the tree filtering issue, it seems that we might need to create a new function that does some custom queries to the DB and gets all of the appropriate groups to display in the parent field. I also think that we can forget about using the og_subgroups_get_eligable_groups() function because I think that is one of the things that limiting us. I don't think that function does what its supposed to do anyway: #1033114: Subgroups showing in subgroup tree block despite no access - MASSIVE FAILURE!!!
I'm thinking we might need a new recursive function that gets all of the top level groups first, then one by one retrieves the children for each top level. This way we don't have to worry about dealing with multiple group types because we only care about the group's children.
Does that seem like a good approach?
Comment #24
massud commentedYou are right about the group details block but notice that there is another way to create a subgroup using "create content -> content type" that "everyone" option should work in this case.
The og module's hook_og_create_links() implementation checks if the user has create permission:
So, I think we should also check for this permission to keep consistency with the og module.
I think the tree filtering issue is a bit more complicated. For example, consider the org -> dept -> team -> project case:
Suppose a "project" can only be a subgroup of either "org" or "team"
Suppose we have the following tree:
-org1
--dept1
---team1
--dept2
---team2
How should we filter and display this tree?
Anyhow, you can disable the tree filtering of the patch by removing array_key_exists() from "if" condition of both og_subgroups_tree() and og_subgroups_tree_recurse().
Comment #25
bschilt commentedI have made some commits recently for other issues and the patch above will no longer apply properly. I have started working on a new patch that will properly roll with the latest changes. I am also going to re-work the existing patch to hopefully resolve our filtering issues described above.
Comment #26
bschilt commentedhere is an updated patch. I added quite a bit of new code in order to get the filtering to happen correctly. There is probably still some bugs and use cases to work out but we should be able to make forward progress again.
This patch satisfies the three use cases identified in comment #9 as well as the hierarchy illustrated in comment #24.
The only change to the UI is on the subgroup settings section on the node type form. I had to add a checkbox that enables or disables a group from being apart of a hierarchy because without it the logic was getting too messy. I also added a "Top Level" option to the "allowed parent types" field. I needed this so that I could distinguish between groups that could only be posted at the root level and the default groups that can be added as a child to all groups.
There's still more work to be done with this. I wanted to post what I had so it can get tested new bugs could get identified.
Comment #27
capellicALL: This is *great* work -- exactly what I needed. I have three different group types and only one of them can have a sub-group and it can only have a sub-group of it's own type: Club, Sub-Club.
I have an interesting use case were groups are created as a reaction to another activity (through a custom module, but it makes me think that Rules support would be helpful here - but that's for another day). So, due to this, I don't want anybody to have permission to create a sub-group. For this reason, I request that you add another option to this list, which would really amount to "blank."
Privileged users to create subgroups:
O Group administrators
O Group members
O Everyone
O Nobody <<< New value
I have attached a screenshot of the configuration section of the content type form for others following along so that they may instantly "get it."
Comment #28
bschilt commented@capellic
I'm glad this is working for your use case. Let me know if you find any issues or bugs as this patch is still under development. Adding support for the Rules module is a great idea. Please create an issue for that and put as much detail as you can.
The "privileged users to create subgroups" section only controls the create link inside of the "Group Details" block. Any user role with the create permission granted will be able to create the groups through the standard Create Content (node/add) page.
For your use case you have a group that is auto created by some other means. Does this mean that you absolutely do not want any users, even site admins, to be able to create this group type? What if we changed the "nobody" option to "default" or "site admins".
Comment #29
capellicThe patch in #26 doesn't appear to be obeying the "Allowed parent group types" field.
I have 3 group types: Club, Project, Group.
Club is not allowed to have a sub-group, "Enable subgroups for this group type" is unchecked and that IS being obeyed.
Project and Group are both allowed to have sub-groups, but with only parents of their own type: A Project can have sub-Projects and a Group can have sub-Groups. I am seeing both Projects and Groups when editing Project node and I am also seeing both Projects and Groups when editing a Group node.
Each content type is configured appropriately:
Project
Allowed parent group types:
Top Level
Group
X Project
Group
Allowed parent group types:
Top Level
X Group
Project
Thanks for all your work on this -- a great addition!
Comment #30
capellic@bschilt
I'll think about this a bit more and see what I can come up with.
Ah yes, I since figured some of this out. Please add this to the description of the field because I was thinking more about permissions rather than themeing. I realized that if I was creating a new club node (not within the context of a club), then how would it know if I was the admin? I love the way the gid is passed in, the select is defaulted to the gid and it's disabled. I'm likely to do a hook_form_alter to hide that fieldset completely. You may consider keeping the Subgroups fieldset open, rename to "Subgroup" and then add some markup to say "This group will be created as a subgroup of XYZ" and then not even show the select. That stuff is fine for tech people, but tends to be a bit confusing for lay people.
Given the clarification above (this isn't a permissions thing, it's a themeing thing), I realize that my issue is taken care of through the permissions page for the content type.
Comment #31
capellic@bschilt
On second thought, it would be nice if the setting "privileged users to create subgroups" did in fact have an option so that those who had "create" permissions for that content type would see the "Create Project" link in the "Group Details" block.
Sorry all for muddying up the queue!
Comment #32
bschilt commentedI am unable to reproduce the issue you're having from #29. I set up two group types to be parents of themselves and when creating a new group as well as editing an existing node I only see the groups of the same type.
I have downloaded the latest dev copy and re applied the patch just to be sure there wasn't some code that didn't make it into the patch. It all works so far for me.
Can you confirm that you downloaded the latest dev build?
Comment #33
massud commentedNot only does "privileged users to create subgroups" control the create link inside of the Group Details block, it also validates if the user is permitted to create the groups through the standard Create Content page (see og_subgroups_form_validate()).
@capellic
What is the use case of "Nobody" in the "privileged users to create subgroups"? Nobody will be able to create a subgroup if you don't select any group type as allowed parent type.
Comment #34
capellic@bschilt: Yes, I had the latest dev version that I applied the patch to.
@massud: I realized that this is a themeing setting rather than a real permissions setting and have asked that description text be added to the field to clarify that this has nothing to do with node add perms, rather only for whether or not the link appears in the Group Details block.
Comment #35
bschilt commentedHere is an updated patch. I added support for Hierarchical select module, updated the Views integration, added code comments and added some descriptive text to the Allowed Parent Types field.
I have completely removed the "privileged users to create subgroups" feature. This feature is already available via the og_user_roles module. This module allows you to assign default roles to group admins as well as group members. The og_user_roles module can't assign roles to group admins and members for each group type, but thats where a patch should come in.
Please test and let me know what kinds of issues arise.
Comment #36
tbenice commentedsub
Comment #37
mstef commentedI went ahead and took care of this without any of these patches. So much has changed so quickly that it wasn't necessary.
http://drupalcode.org/project/og_subgroups.git/commitdiff/4c1c4f4?hp=028...
Comment #38
bschilt commentedThe functionality referenced in the original description of this issue has been implemented. The patches in this issue was to create extra functionality. This issue is now closed because the original requirement has been met. For a continuation of the development of the extra functionality mentioned in this issue, please see #1127856: Create ability to define a structured hierarchy between group types.