diff --git a/og_moderation.module b/og_moderation.module index 95ed032..a2edf55 100644 --- a/og_moderation.module +++ b/og_moderation.module @@ -6,17 +6,33 @@ function og_moderation_og_permission() { $perms = array(); $infos = node_type_get_types(); - foreach($infos as $info) { + $moderated_content_types = implode(', ', revisioning_moderated_content_types(FALSE)); + + foreach ($infos as $info) { if (og_is_group_content_type('node', $info->type)) { $perms["view any unpublished " . $info->type . " content"] = array( 'title' => t('View any unpublished %type_name content', array('%type_name' => $info->name)), ); + $perms["publish revisions"] = array( + 'title' => t("Publish content revisions (of anyone's content)"), + 'description' => t('Applies to content types that are subject to moderation, i.e.: %moderated_content_types.', array('%moderated_content_types' => $moderated_content_types)), + ); + $perms["publish revisions of own " . $info->type . " content"] = array( + 'title' => t('Publish revisions of own %type_name content', array('%type_name' => $info->name)), + ); + $perms["publish revisions of any " . $info->type . " content"] = array( + 'title' => t('Publish revisions of any %type_name content', array('%type_name' => $info->name)), + ); $perms["access publishing options of " . $info->type . " content"] = array( 'title' => t('Access publishing options of %type_name content', array('%type_name' => $info->name)), ); $perms["access revisions options of " . $info->type . " content"] = array( 'title' => t('Access revisions options of %type_name content', array('%type_name' => $info->name)), ); + $perms["unpublish current revision"] = array( + 'title' => t("Unpublish current revision (of anyone's content)"), + 'description' => t('Applies to content types that are subject to moderation, i.e.: %moderated_content_types.', array('%moderated_content_types' => $moderated_content_types)), + ); } } return $perms; @@ -113,3 +129,47 @@ function og_moderation_node_revision_access($node, $op = 'view') { return _node_revision_access($node, $op = 'view'); } +/** + * Implements hook_revisioning_access_node_revision(). + * + * Apply OG user roles to the revisioning action taken here. + */ +function og_moderation_revisioning_access_node_revision($revision_op, $node, $access = NULL, $account = NULL) { + $result = ($access == 1) ? NODE_ACCESS_ALLOW : NODE_ACCESS_IGNORE; + if (og_is_group_content_type('node', $node->type) && !empty($node->og_group_ref)) { + $gid = $node->og_group_ref[LANGUAGE_NONE][0]['target_id']; + switch ($revision_op) { + case 'publish revisions': + if (og_user_access('node', $gid, "publish revisions")) { + return NODE_ACCESS_ALLOW; + } + if (og_user_access('node', $gid, 'publish revisions of any ' . $node->type . ' content')) { + return NODE_ACCESS_ALLOW; + } + if ($account != NULL) { + if (($node->uid == $account->uid) && og_user_access('node', $gid, 'publish revisions of own ' . $node->type . ' content', $account)) { + return NODE_ACCESS_ALLOW; + } + } + break; + + case 'unpublish current revision': + if (og_user_access('node', $gid, "unpublish current revision", NULL, FALSE, FALSE)) { + return NODE_ACCESS_ALLOW; + } + break; + + default: + if (og_user_access('node', $gid, 'view any unpublished ' . $node->type . ' content')) { + return NODE_ACCESS_ALLOW; + } + if ($account != NULL) { + if (($node->uid == $account->uid) && og_user_access('node', $gid, 'view own unpublished ' . $node->type . ' content', $account)) { + return NODE_ACCESS_ALLOW; + } + } + } + } + + return $result; +}