Skip to content

Instantly share code, notes, and snippets.

@Renrhaf
Created March 22, 2016 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Renrhaf/789656c59163ba7d80df to your computer and use it in GitHub Desktop.
Save Renrhaf/789656c59163ba7d80df to your computer and use it in GitHub Desktop.
AFOUND-648
diff --git a/modules/features/foundation_editorial/foundation_editorial.module b/modules/features/foundation_editorial/foundation_editorial.module
index 9cfda1f..28a3645 100644
--- a/modules/features/foundation_editorial/foundation_editorial.module
+++ b/modules/features/foundation_editorial/foundation_editorial.module
@@ -14,10 +14,12 @@ include_once 'foundation_editorial.features.inc';
function foundation_editorial_permission() {
return array(
'foundation view unpublished nodes' => array(
- 'title' => t('Access unpublished content created by other users'),
+ 'title' => t('View unpublished nodes'),
+ 'description' => t('Grant view access to all unpublished nodes.'),
),
'foundation publish or unpublish nodes' => array(
- 'title' => t('Publish or Unpublish nodes the user already has access to'),
+ 'title' => t('Publish or unpublish nodes'),
+ 'description' => t('Allow to publish or unpublish nodes the user has already access to.'),
),
);
}
@@ -35,9 +37,7 @@ function foundation_editorial_check_permissions($permission_to_check, $account_t
}
/**
- * Implements hook_node_access
- *
- * Checks if the user was granted the 'foundation view unpublished nodes' permission
+ * Implements hook_node_access().
*/
function foundation_editorial_node_access($node, $op, $account) {
// If user is granted special permission, let him view the node
@@ -55,6 +55,46 @@ function foundation_editorial_node_access($node, $op, $account) {
}
/**
+ * Implements hook_node_access_records().
+ *
+ * @TODO implement node access for 'update' access for unpublished nodes ?
+ */
+function foundation_editorial_node_access_records($node) {
+ $grants = array();
+
+ // We only care about the node if is unpublished. If not, it is
+ // treated just like any other node and we completely ignore it.
+ if ($node->status == 0) {
+ // Unpublished nodes should be viewable with permission.
+ $grants[] = array(
+ 'realm' => 'foundation_view_unpublished_nodes',
+ 'gid' => 1,
+ 'grant_view' => 1,
+ 'grant_update' => 0,
+ 'grant_delete' => 0,
+ 'priority' => 0,
+ );
+ }
+
+ return $grants;
+}
+
+/**
+ * Implements hook_node_grants().
+ */
+function foundation_editorial_node_grants($account, $op) {
+ $grants = array();
+
+ // If user has the 'foundation view unpublished nodes' permission,
+ // give him the access to see unpublished nodes.
+ if ($op == 'view' && foundation_editorial_check_permissions('foundation view unpublished nodes', $account)) {
+ $grants['foundation_view_unpublished_nodes'] = array(1);
+ }
+
+ return $grants;
+}
+
+/**
* Implements hook_form_BASE_FORM_ID_alter().
*/
function foundation_editorial_form_node_form_alter(&$form, &$form_state) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment