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.

Comments

Egon Bianchet’s picture

Duh, I meant "But this way if you do the following to clone nodes:"

moshe weitzman’s picture

perhaps 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.

Egon Bianchet’s picture

Status: Active » Needs review
StatusFileSize
new1.9 KB
colorado’s picture

I can confirm this patch works :-)

Veggieryan’s picture

Title: og_save_permissions inconsistency » killed 2 birds with that one

wow..
http://drupal.org/node/66215
http://drupal.org/node/67038

FIXED!!!
now.. why is casetracker still incompatible with mailhandler?
http://drupal.org/node/68732

Egon Bianchet’s picture

Title: killed 2 birds with that one » og_save_permissions inconsistency
dww’s picture

this 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

dww’s picture

StatusFileSize
new1.92 KB

and 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 the foreach() 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?

dww’s picture

by 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:

-  if (!og_is_group_type($node->type)) {
+  if ($node->type != 'og') {

haven't yet tested the patch from my last followup in 4.6, but it definitely does that it should in 4.7/HEAD.

moshe weitzman’s picture

Status: Needs review » Fixed

this last patch looks good. committed to HEAD and 4.7.

Anonymous’s picture

Status: Fixed » Closed (fixed)