The function og_save_permissions is called from hook_nodeapi, case 'insert', to store access permission for nodes.
foreach ($node->og_groups as $gid => $checked) {
if ($checked) {
$sql = "INSERT INTO {node_access} (nid, gid, realm, grant_view, grant_update, grant_delete) VALUES (%d, %d, 'og_subscriber', 1, 1, 1)";
db_query($sql, $node->nid, $gid);
if ($node->og_public) {
$sql = "INSERT INTO {node_access} (nid, gid, realm, grant_view) VALUES (%d, 0, 'og_public', %d)";
db_query($sql, $node->nid, $gid);
}
}
}
This cycle expects the og_groups array to be structured as $gid => $checked, but the same array on node object loaded with node_load is structured as a simple array of gids. I think it's because the function was design to work with nodes coming straight from the form submission.
But this way if you can't do the following to clone nodes:
$node = node_load($nid);
unset($node->nid);
node_save($node);
like eventrepeat and maybe other modules do, you get a messed node_access table.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | og-save-perm_1.patch.txt | 1.92 KB | dww |
| #3 | og-save-perm.patch.txt | 1.9 KB | Egon Bianchet |
Comments
Comment #1
Egon Bianchet commentedDuh, I meant "But this way if you do the following to clone nodes:"
Comment #2
moshe weitzman commentedperhaps the best way to address this is to use nodeapi('submit') to massage the form submitted data so it looks like the nodeapi(load) data ... i will review patches for this, but i'm not actively working on it.
Comment #3
Egon Bianchet commentedComment #4
colorado commentedI can confirm this patch works :-)
Comment #5
Veggieryan commentedwow..
http://drupal.org/node/66215
http://drupal.org/node/67038
FIXED!!!
now.. why is casetracker still incompatible with mailhandler?
http://drupal.org/node/68732
Comment #6
Egon Bianchet commentedComment #7
dwwthis inconsistency is at the heart of the problems i've been having getting OG to play nicely with the project module's issues and followups (http://drupal.org/node/60599). haven't had a chance to try out this specific patch, but it's very similar to some stuff i was starting to try in #60599 (before i had to quit working on it and deal with other emergencies before i went out of town for a little while). so, +1 in principle. ;) i'll test it to see if it a) solves my problems, too, and b) doesn't break anything else...
thanks,
-derek
Comment #8
dwwand lo, this does solve the problems with OG + project issue followups i previously mentioned. ;)
here's a new version of the patch with a slight simplification: i use
array_filter()instead of theforeach()loop to unset the groups that aren't selected. the comments in og_save_permissions() should probably be updated, too, but moshe wasn't around in IRC to confirm my understanding of things, so i'm not going to mess with those just now.i think this is RTBC. moshe/webchick?
Comment #9
dwwby the way, that patch applies cleanly to 4.7 and HEAD. i tried it on 4.6 and the 2nd hunk failed. however, that's because
og_save_permissions()already looks exactly like this in the 4.6 branch. ;) in fact, after you apply the patch to 4.7, the only diff between the 4.6 and 4.7 versions of og_save_permissions() are a few minor changes to some comments, and this:haven't yet tested the patch from my last followup in 4.6, but it definitely does that it should in 4.7/HEAD.
Comment #10
moshe weitzman commentedthis last patch looks good. committed to HEAD and 4.7.
Comment #11
(not verified) commented