diff options
author | webchick <webchick@24967.no-reply.drupal.org> | 2011-06-29 18:09:21 -0700 |
---|---|---|
committer | webchick <webchick@24967.no-reply.drupal.org> | 2011-06-29 18:09:21 -0700 |
commit | 8094e14c515f8e8a29eb152eadb9e1b635434535 (patch) | |
tree | 4d352988ce7b80c663f15cf0bece39aadd37d9eb /modules/node/tests | |
parent | fad397b1f131fe10674d29bd4d49ba404c1cd070 (diff) | |
download | brdo-8094e14c515f8e8a29eb152eadb9e1b635434535.tar.gz brdo-8094e14c515f8e8a29eb152eadb9e1b635434535.tar.bz2 |
Drupal 7.3
Diffstat (limited to 'modules/node/tests')
-rw-r--r-- | modules/node/tests/node_access_test.install | 84 | ||||
-rw-r--r-- | modules/node/tests/node_access_test.module | 90 |
2 files changed, 166 insertions, 8 deletions
diff --git a/modules/node/tests/node_access_test.install b/modules/node/tests/node_access_test.install new file mode 100644 index 000000000..3535ab199 --- /dev/null +++ b/modules/node/tests/node_access_test.install @@ -0,0 +1,84 @@ +<?php + +/** + * @file + * Install, update and uninstall functions for the node_access_test module. + */ + +/** + * Implements hook_schema(). + */ +function node_access_test_schema() { + $schema['node_access_test'] = array( + 'description' => 'The base table for node_access_test.', + 'fields' => array( + 'nid' => array( + 'description' => 'The {node}.nid this record affects.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'private' => array( + 'description' => 'Boolean indicating whether the node is private (visible to administrator) or not (visible to non-administrators).', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'indexes' => array( + 'nid' => array('nid'), + ), + 'primary key' => array('nid'), + 'foreign keys' => array( + 'versioned_node' => array( + 'table' => 'node', + 'columns' => array('nid' => 'nid'), + ), + ), + ); + + return $schema; +} +<?php + +/** + * @file + * Install, update and uninstall functions for the node_access_test module. + */ + +/** + * Implements hook_schema(). + */ +function node_access_test_schema() { + $schema['node_access_test'] = array( + 'description' => 'The base table for node_access_test.', + 'fields' => array( + 'nid' => array( + 'description' => 'The {node}.nid this record affects.', + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + ), + 'private' => array( + 'description' => 'Boolean indicating whether the node is private (visible to administrator) or not (visible to non-administrators).', + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'indexes' => array( + 'nid' => array('nid'), + ), + 'primary key' => array('nid'), + 'foreign keys' => array( + 'versioned_node' => array( + 'table' => 'node', + 'columns' => array('nid' => 'nid'), + ), + ), + ); + + return $schema; +}
\ No newline at end of file diff --git a/modules/node/tests/node_access_test.module b/modules/node/tests/node_access_test.module index 3004e0c90..91c117a6f 100644 --- a/modules/node/tests/node_access_test.module +++ b/modules/node/tests/node_access_test.module @@ -12,8 +12,10 @@ */ function node_access_test_node_grants($account, $op) { $grants = array(); + // First grant a grant to the author for own content. + $grants['node_access_test_author'] = array($account->uid); if ($op == 'view' && user_access('node test view', $account)) { - $grants['node_access_test'] = array(888); + $grants['node_access_test'] = array(8888); } if ($op == 'view' && $account->uid == variable_get('node_test_node_access_all_uid', 0)) { $grants['node_access_all'] = array(0); @@ -26,14 +28,27 @@ function node_access_test_node_grants($account, $op) { */ function node_access_test_node_access_records($node) { $grants = array(); - $grants[] = array( - 'realm' => 'node_access_test', - 'gid' => 888, - 'grant_view' => 1, - 'grant_update' => 0, - 'grant_delete' => 0, - 'priority' => 999, + // For NodeAccessBaseTableTestCase, only set records for private nodes. + if (!variable_get('node_access_test_private') || $node->private) { + $grants[] = array( + 'realm' => 'node_access_test', + 'gid' => 8888, + 'grant_view' => 1, + 'grant_update' => 0, + 'grant_delete' => 0, + 'priority' => 0, ); + // For the author realm, the GID is equivalent to a UID, which + // means there are many many groups of just 1 user. + $grants[] = array( + 'realm' => 'node_access_test_author', + 'gid' => $node->uid, + 'grant_view' => 1, + 'grant_update' => 1, + 'grant_delete' => 1, + 'priority' => 0, + ); + } return $grants; } @@ -142,3 +157,62 @@ function node_access_entity_test_page() { return $output; } + +/** + * Implements hook_form_node_form_alter(). + */ +function node_access_test_form_node_form_alter(&$form, $form_state) { + // Only show this checkbox for NodeAccessBaseTableTestCase. + if (variable_get('node_access_test_private')) { + $form['private'] = array( + '#type' => 'checkbox', + '#title' => t('Private'), + '#description' => t('Check here if this content should be set private and only shown to privileged users.'), + '#default_value' => isset($form['#node']->private) ? $form['#node']->private : FALSE, + ); + } +} + +/** + * Implements hook_node_load(). + */ +function node_access_test_node_load($nodes, $types) { + $result = db_query('SELECT nid, private FROM {node_access_test} WHERE nid IN(:nids)', array(':nids' => array_keys($nodes))); + foreach ($result as $record) { + $nodes[$record->nid]->private = $record->private; + } +} + +/** + * Implements hook_node_delete(). + */ + +function node_access_test_node_delete($node) { + db_delete('node_access_test')->condition('nid', $node->nid)->execute(); +} + +/** + * Implements hook_node_insert(). + */ +function node_access_test_node_insert($node) { + _node_access_test_node_write($node); +} + +/** + * Implements hook_nodeapi_update(). + */ +function node_access_test_node_update($node) { + _node_access_test_node_write($node); +} + +/** + * Helper for node insert/update. + */ +function _node_access_test_node_write($node) { + if (isset($node->private)) { + db_merge('node_access_test') + ->key(array('nid' => $node->nid)) + ->fields(array('private' => (int) $node->private)) + ->execute(); + } +} |