I installed the og_user_roles module on my site, and noticed something odd: it was redirecting the node/add pages when I was currently looking at group-related content. Although this is a very useful feature once I realized what it was doing, there remains (so I think) one problem: it redirectsall content add pages, not just the ones that are group related.
I haven't looked closely at your code, but wherever you have the applicable code, something like this should check to see if the node is applicable to groups:
$og_audience_required = variable_get('og_audience_required', FALSE);
$og_omitted = variable_get('og_omitted', array());
if ($og_audience_required && in_array($type, $og_omitted) { // I'm assuming you already have some sort of content type variable, thus $type; if not, additional code will need to be added.
//Chunk of code that generates the redirects goes here.
}
I haven't tested this, as I'm not sure how your code work, but here it is if you get the chance to incorporate it into your code.
Thanks,
cwgordon7
Comments
Comment #1
somebodysysop commentedThis is not true. It only redirects create content links from a Group Home page. When you look at the code, this is what you should see:
// If this is a group node/add, re-direct to ognodeaddif (arg(0) == 'node' && arg(1) == 'add' && isset($_REQUEST['gids'])) {
?>
You'll have to give me a bit more information about your site because, according to everything I've seen and the code itself, OG User Roles does NOT re-direct Main Menu create content links (unless, of course, they include the gids[] variable which, it is my understanding, is only included on group node creation.
Comment #2
somebodysysop commentedComment #3
cwgordon7 commentedLet me be more specific. On my site, if I am on a group home page, and click on a link in a global menu to a site-wide (non-group associated) create content link, I am automatically redirected to a create content link in this group. When I hover over the menu link, I see the node/add/... page, but when I click on it, I am redirected to the group create content page. I have checked the Require Audience for OG setting on the OG administration page, and have selected several node types as Omitted Content Types. I thus get an access denied message (not a Drupal access denied message - just the words "access denied" at the top of the page where the content would normally begin). This occurs both when I try to create nodes defined as organic groups from a group home page or nodes that cannot exist within an organic group. In case this is the issue, I am using a custom-defined menu item; not the default "Create content" and subitems menu. However, the links in question are still the same.
Thank you for your fast reply,
cwgordon7
Comment #4
somebodysysop commentedThanks. I see your issue more clearly. May I ask: Why does the /node/add link include the query "gids[]" if it is not a group link and specifically omitted by OG?
Comment #5
cwgordon7 commentedIt doesn't contain the query gids[]. For example, one of the menu items in question is story, with a path of node/add/cz-business-listing (this is a cck-created node type): it is redirected to node/ognodeadd?type=cz-business-listing&gids[]=56 where cz-business-listing is a content type that cannot be created within a group, thus the access denied error. If you still think this is a bug on my part, I would be happy to perform any tests that you can think of to fix this- I may have any number of unique situations on my site that are unrelated to the og_user_roles module.
Thanks,
cwgordon7
Comment #6
somebodysysop commentedOops. You're right. Looks like I didn't notice this code:
This could do it. However, before I try to fix this, shouldn't the test line be:
as opposed to:
Troubleshooting isn't always the easiest thing. Thanks for your patience.
Comment #7
cwgordon7 commentedYes, sorry, I made a mistake in my code. You should check to see if the content type is NOT omitted. Sorry for the mistake, thanks for helping me with this problem.
-cwgordon7
Comment #8
somebodysysop commentedThen try this patch against a clearn version of the 5.x-2.4 release. Let me know if it works for you.
Comment #9
somebodysysop commentedHere's the actual patch.
Comment #10
riverfr0zen commentedThe patch certainly fixed the issue - I haven't tested out the general module functionality to see if it broke anything, however - will post any issues if they come up.
Comment #11
somebodysysop commentedComment #12
cwgordon7 commentedSorry it took me this long to get back to you, I've been busy lately. I've applied the path, but I'm getting only mixed results. For some unknown reason, the redirect still occurs on some node types, but is fixed on others that used to be a problem.
This completely baffles me. I've looked at your code, and it theoretically should be working. I don't understand why it's still redirecting on some node types. I have checked to make sure I'm actually omitting these node types.
If you have any further ideas, it would be much appreciated.
Thanks,
cwgordon7
Comment #13
somebodysysop commentedI need some specifics. I have to try and re-create the problem. What node types are omitted that still get re-directed by OGR. Is the audience required check valid for the group?
Tell me what I need to know to consistently recreate the problem.
Comment #14
devin.gardner commentedI'm getting this same issue. I have a block on the left panel of all pages that has a link to create a new group (so it's '/node/add/basic-group'), but when in a group context this gets redirected to ognodeadd. It seems like the og_user_roles code is a bit overzealous with redirecting when $_SESSION['og_last'] is set.
Comment #15
devin.gardner commentedApplying the changes in that patch seems to have cleared everything up.
Same thing for the redirecting to oguseredit, which was also giving me problems.
Comment #16
cwgordon7 commentedThe specifics:
The types that redirect incorrectly are, now that I think about it, all completely cck-based. Module or system defined content types such as "blog" or "story" do not redirect incorrectly. All of these should be in the og_omitted array. The "Audience Required" checkbox is checked.
-cwgordon7
Comment #17
somebodysysop commentedGreat. This is a good start. Now, give me an exact example of a cck-based type that is being re-directed incorrectly. I still don't know what you mean, or why this is happening, so I'd like to re-create the same exact environment to see what needs to be done.
Thanks!
Comment #18
cwgordon7 commentedAn example:
I used cck to create a content type called "business-listing". This type is defined as having a location, a title, a body, a phone number, and a website field. After creating this content type, I went to organic groups, and selected it on the og_omitted list. Og audience required was already checked. If you need any more information, or would like me to test something for you, I'd be happy to.
-cwgordon7
Comment #19
cwgordon7 commentedOk, I partially solved my own problem. I took a closer look into the og_omitted array through the devel module to make sure my node types were in there; some of the problem redirects are in there, but group node types (content types that act as organic groups) are not in the array. These content types, on redirect don't make much sense- trying to create a group within a group- don't make sense unless you have subgroups enabled (which I don't), and might not even make sense in that case. Group node types are stored in a variable called og_node_types; there should probably be an additional check for these node types in the patch. I'm not sure what the other problems are, but I'll keep testing.
Thanks,
cwgordon7
Comment #20
cwgordon7 commentedAnother update:
I created a new cck node type as a testing tool. I made it very simple: just title, body, and one word user interface title and matching machine readable title. I created the node type, and then omitted it from og. I went to a group homepage, and clicked the new menu link I had created for node/add/test. The node did not redirect. I played around with the content type for a while, and I believe I have found the problem (or at least part of the problem): it started redirecting when I changed the name to include spaces: "Test Type", "test-type". Maybe with this information, you'll be able to figure out what the problem is.
-cwgordon7
Comment #21
somebodysysop commentedI ran some tests.
First off, from the way I see it, if you have a node type "Test", and it is omitted from group content, then no group role should have the "Create test" permission. And, if no group role has this permission, then it won't appear on the group menu. However, if you give site-side permission to "create test" nodes to a user, then it will appear in his main menu.
One way to cancel group context is to NOT expand your "Create content" links in the Main Menu. By doing this, you will no longer have a link to "Create test" under any circumstances while a user is within a group. This would solve your problem right away.
I ran this test:
1. Create content type named "Test Content Type" (type = "test").
2. Omitted it in group settings.
3. Expanded the "Create content" menu so that link to create "Test Content Type" will appear in main menu.
4. Went into group that previously had "Create Test Content Type" link. Link no longer appears.
5. Clicked on "Test Content Type" under "Create content" in main menu. No re-direction.
6. Changed name to "Test Type". Repeated test. No re-direction.
This appears to be the desired behaviour.
It sounds like from everything you've reported, the patch is working even in your case -- with the exception of when you alter the name of a content type. However, I've not been able to duplicate that particular problem.
My suggestions at this point:
1. Unexpand the "Create content" link on the main menu.
2. If possible, do not give sitewide permission "create test" to role(s) that group members will have.
Comment #22
cwgordon7 commentedI'm sorry, neither of your suggestions is possible for me to comply with, as 1) I am using a delicate combination of access control modules, and 2) I am using nice_menus, not drupal's default menus.
I should have made my problems more clear. Firstly, the content type redirects in the case of group type nodes, which it should not do, because group type nodes are not in og_omittted array. Secondly, the content type redirects in the case of a machine-readable content name with dashes in it and a human-readable name with spaces (sorry, can't be more specific than that).
-cwgordon7
Comment #23
somebodysysop commentedThen, I'm not sure I can help you because with the default Drupal main menu expanded, when I click on the "Group" submenu item under "Create content" from within a group, I am NOT re-directed. This is as it should be.
Since OGR supports creating subgroups, it is not possible to eliminate a content type simply because it is a group content type.
This does sound pretty weird. I don't see anything in OGR code that would cause this on it's own. What I would do here is simply make a note in the OGR documentation that this sort of behaviour has been reported, so try to avoid dashes in your machine-readable content name. I can not reproduce the problem with spaces in the human-readable name.
If someone can produce some code that they think would solve this issue, I'm certainly happy to take a look at it.
Comment #24
cwgordon7 commentedOh well, thanks very much for putting this much time into helping me. I've given up on the problem, and am attempting, as you advised, to rename the content types with dashes in their machine readable name. Other than that, I don't know what to do.
Once again, thanks,
cwgordon7
Comment #25
somebodysysop commentedComment #26
icstars commentedThis was an issue for us for dashed content types as well as ognodeadd overwriting a url scheme we are using to handle petition signatures that link back to a parent node(http://drupal.org/node/158172#comment-1026155). The code below seems to fix both problems. I am not sure why omitted was not adequate, but in our case it was not.
$og_permitted = og_is_group_post_type ($type);
if ($og_permitted && $og_audience_required && (!in_array($type, $og_omitted)) ) {
Comment #27
heacu commentedsubscribing
Comment #28
somebodysysop commented@icstars:
So, you're saying this:
should be replaced with this:
Comment #29
somebodysysop commented$og_permitted patch committed to 5.x and 6.x dev releases.