Have a look at this example implementation which creates a new OG Permission View unpublished content and uses Node Grants to decide who can view unpublished nodes. You now can configure which OG Role in your groups are allowed to view unpublished nodes.
<?php
define('MY_MODULE_REALM_VIEW_UNPUBLISHED', 'my_module_view_unpublished');
/**
* Implements hook_og_permission().
*/
function my_module_og_permission() {
// Add OG permission to view unpublished nodes.
return array(
'view unpublished' => array(
'title' => t('View unpublished content'),
'description' => t("Allow user to see unpublished content within the group."),
// Determine to which roles the permissions will be enabled by default.
'default role' => array(OG_ADMINISTRATOR_ROLE),
),
);
}
/**
* Implements hook_node_grants().
*/
function my_module_node_grants($account, $op) {
if ($op != 'view') {
return;
}
$grants = array();
// Handle access to unpublished nodes.
// Get all OG Group IDs the user is allowed to view unpublished nodes in.
$entities = og_get_entity_groups();
foreach ($entities['node'] as $entity_id) {
if (og_user_access('node', $entity_id, 'view unpublished')) {
$grants[MY_MODULE_REALM_VIEW_UNPUBLISHED][] = $entity_id;
}
}
return $grants;
}
/**
* Implements hook_node_access_records().
*/
function my_module_node_access_records($node) {
// Node is unpublished and belongs to a OG group.
if (!(empty($node->status) && $groups = og_get_entity_groups('node', $node))) {
return array();
}
foreach ($groups['node'] as $nid) {
$grants[] = array(
'realm' => MY_MODULE_REALM_VIEW_UNPUBLISHED,
'gid' => $nid,
'grant_view' => 1,
'grant_update' => 0,
'grant_delete' => 0,
'priority' => 10,
);
}
return $grants;
}