I'm marking this as a bug report but I understand it may be a new feature request or potentially just a support request.

I have one node type Group, set up as an OG Group, with Group Visibility field.

I have another node type Post, set up as an OG Group Content, with a Group Audience being in Group, and Group Content Visibility set to use Default from group.

Steps to reproduce:

1. Create a group node, marking it private.

2. Create a post node, leaving visibility set as Default from group. It will be private.

3. Change the group visibility to Public. The post node is still private.

This goes the other way as well--posting to a public group and then making the group private leaves the posts public.

If the group content is re-saved after the group's group visibility changes, it will update to the group's new visibility.

I think it would be much more intuitive for the group content visibility to be updated as the group visibility changes. Is there currently any setting, or any expected way to do this beyond a custom module implementing hook_node_update()?

Comments

shushu’s picture

While the behavior you describe is known, there is no simple solution for it that will be able to cover all of the different OG use cases (some with big sites and large amount of nodes in each group).
Patches are always welcome.

Specifically for your use case, if it is a small site, you can create several solutions, among them creating some rules that will change content permissions once group permission is changed.

dtarc’s picture

That is understandable. I see how it would be difficult to create a solution that will apply everywhere.

Here's what we ended up using to achieve this functionality on our site:

/*
 * Implements hook_node_presave()
 */
function mymodule_node_presave($node) {
  // Check if OG Access module is enabled.
  if (module_exists('og_access')) {
    // Check if this node is an og group
    if (og_is_group_type('node', $node->type)) {
      // Check if this will be an update rather than an insert
      if (isset($node->original)) {
        // Check if the visibility setting on the group has changed
        $node_wrapper = entity_metadata_wrapper('node', $node);
        $orig_wrapper = entity_metadata_wrapper('node', $node->original);
        $node_visibility = $node_wrapper->{OG_ACCESS_FIELD}->value();
        $orig_visibility = $orig_wrapper->{OG_ACCESS_FIELD}->value();
        if (strcmp($node_visibility, $orig_visibility)) {
          $node->mymodule_og_access_update = 1;
        }
      }
    }
  }
}

/*
 * Implements hook_node_update()
 */
function mymodule_node_update($node) {
  if (isset($node->mymodule_og_access_update)) {
    // Group visiblity has changed, update all group content nodes
    // Get all node og_memberships for this group
    $query = new EntityFieldQuery();
    $query->entityCondition('entity_type', 'og_membership', '=')
      ->propertyCondition("entity_type", 'node', "=")
      ->propertyCondition("gid", $node->nid, "=");
    $result = $query->execute();
    if (isset($result['og_membership'])) {
      $og_memberships = og_membership_load_multiple(array_keys($result['og_membership']));
      $group_content_nids = array();
      foreach ($og_memberships as $og_membership) {
        $group_content_nids[] = $og_membership->etid;
      }
      // Filter group content nids down to those with group content visibility set to "Default from group"
      $query = new EntityFieldQuery();
      $query->entityCondition('entity_type', 'node', '=')
        ->propertyCondition('nid', $group_content_nids, 'IN')
        ->fieldCondition('group_content_access', 'value', OG_CONTENT_ACCESS_DEFAULT, '=');
      $result = $query->execute();
      if (isset($result['node'])) {
        // Clear cache to ensure that recent visibility change gets used
        entity_get_controller('node')->resetCache();            
        $group_content_nodes = node_load_multiple(array_keys($result['node']));
        foreach ($group_content_nodes as $group_content_node) {
          node_access_acquire_grants($group_content_node);
        }
      }
    }
  }
}

For our purposes, we really only needed the private/public toggling to apply to node-based group content. This did the trick. For us it makes a lot more sense to do this with hooks than with rules.

I'd be willing to turn this into a patch if it could be used in og_access...I suppose this could be turned on/off by a setting, so that people not looking for this functionality wouldn't get it.

jastraat’s picture

Sadly these would only work if the group was a node. Groups can also be other types of entities though.