Multinode Access Patch

Primary tabs

Multinode Access Patch

 

Groups audience: 
- Private group -

Comments

4

Patch to add Multinode Access UI to node.module. Patch is named:

node.module.multinode.patch

Upgrading the patch to 6.x. Here are the functions where updating needs to take place:

  • node_menu($may_cache)
  • node_access($op, $node = NULL)
  • _node_access_where_sql
  • node_access_grants
  • node_access_view_all_nodes()
  • node_access_grants_sql
  • node_multinode($theme = NULL)
  • theme_node_multinode($form)
  • node_multinode_submit($form_id, $form_values)

Here are the details:

  • node_menu($may_cache)

    $items['admin/content/multinode'] = array(
    'title' => t('Multinode user interface'),
    'description' => t('Interface for configuring multiple node access.'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('node_multinode'),
    'access arguments' => user_access('administer nodes'),
    'type' => MENU_NORMAL_ITEM
    );

  • node_access($op, $node = NULL)

    if ($op != 'create' && $node->nid && $node->status) {
    $grants_sql = node_access_grants_sql($op, NULL, $user->uid, $node->status);
    // If the return value is FALSE, then the node status is unpublished and
    // none of the grants requested an access check be run. In which case,
    // we should fall through to the final 'if' statement.
    if ($grants_sql !== FALSE) {
    if (!empty($grants_sql)) {
    $grants_sql .= ' AND';
    }
    $sql = "SELECT COUNT(*) FROM {node_access} WHERE (nid = 0 OR nid = %d) $grants_sql grant_$op >= 1";
    $result = db_query($sql, $node->nid);
    return (db_result($result));
    }
    }

  • _node_access_where_sql

    $grants_sql = node_access_grants_sql('view', $node_access_alias, $account->uid);

    Note that in original patch this was:

    $grants_sql = node_access_grants_sql('view', $node_access_alias, $uid);

    Apparently, in 6.x the $account object is used. But, our code is still expecting only the $accunt->uid.

  • node_access_grants($op, $account = NULL)

    Nothing to change. Although this now requires $account object instead of $account->uid (in Drupal 5.x)
  • node_access_view_all_nodes()

    $grants_sql = node_access_grants_sql('view');

  • node_access_grants_sql

    This is our own custom code, although I do need to modify in order to get the $account object for calling node_access_grants(). Previously, I only needed the $account->uid.

    $rules = node_access_grants($op, $account);

  • node_multinode($theme = NULL)

    This is our own custom code, although I do need to modify in order to get the $account object for calling node_access_grants(). Previously, I only needed the $account->uid.

    $mrules = node_access_grants($op, $account);

  • theme_node_multinode($form)
  • node_multinode_submit($form_id, $form_values)

    This has to change to:

    node_multinode_submit($form, $form_state)

    as per Drupal 6.x upgrade.

    So, this code:

    foreach ($form_values as $block) {

    becomes this:

    foreach ($form_state['values'] as $block) {

Need to modify system.install module to install multinode_access table.

This patch is called: system.install.multinode.patch.

system.install functions modified:

  • system_schema()
  • system_update_6048()

Code details:

  • system_schema()
    Added schema for multinode_access table:

    $schema['multinode_access'] = array(
    'description' => t('Table to record multinode access configurations for modules.'),
    'fields' => array(
    'realm' => array(
    'type' => 'varchar',
    'length' => 30,
    'description' => t('Realm.'),
    ),
    'groupname' => array(
    'type' => 'varchar',
    'length' => 10,
    'description' => t('Group tag.'),
    ),
    'logic' => array(
    'type' => 'varchar',
    'length' => 5,
    'description' => t('Logic to use.'),
    ),
    'weight' => array(
    'type' => 'varchar',
    'length' => 5,
    'description' => t('Order in which this module is to be processed.'),
    ),

    'checkstatus' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),

    'module' => array(
    'type' => 'varchar',
    'length' => 60,
    'description' => t('Name of module.'),
    ),
    ),
    );

  • system_update_6048()

    Create multinode_access table. Not sure what number should go in function name.

    db_create_table($ret, 'multinode_access', $schema['multinode_access']);

  1. Copied modified system.install to test.scbbs.com.
  2. System automatically let me know that system.module update 6048 needed to be ran.
  3. Ran it. Got error " user warning: Table 'multinode_access' already exists query:". Of course. Table was created by OG User Roles!
  4. Uploaded modified node.module to test.scbbs.com.
  5. Now getting this error:

    warning: Invalid argument supplied for foreach() in /var/www/html/websites/drupal/test/includes/menu.inc on line 258

    Must be from menu settings or the $account issue.

  6. Running php tests. theme_node_multinode() just doesn't seem to apply.
  7. Posted issue here: http://drupal.org/node/279254
  8. Resolved: I needed to clear the menu cache: admin->site configuration->performance

It was suggested that I test 6.x multinode access with 6.x tac_lite.module which is current head version: http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/tac_lite/

  1. Created Test Vocabulary and Test Term 1. Test Term 1 requires "Group Contributor" role to view.
  2. Created user test02. Put test02 into Test Group 01 as "Group Member" (but not "Group Contributor").
  3. Just noticed that test01 is not a "Group Contributor" either.
  4. Logged in as test02, and can see Test Page in Test Group 01: http://test.scbbs.com/node/8
  5. Gave Test Page in Test Group 01 the Test Term 1 vocabulary. User test02 can still see it.
  6. Went to Multinode user interface and ANDed tac_lite realm.
  7. User test02 gets Get "Acess Denied" on node/8, but also now can't see any group data. Uh-oh.
  8. We need tac_lite to create grants for nodes it doesn't care about. This was originally discussed here for OG: http://drupal.org/node/234087.
  9. Posted issue here: http://drupal.org/node/196922#comment-911480
  10. Received suggestion. Created tac_lite_multinode.module: http://www.scbbs.com/node/382#comment-843 and installed. This module logically should grant tac_lite "view" access to all nodes that tac_lite doesn't care about. This way, when we AND tac_lite realm, users will see nodes that they otherwise should see that don't have tac_lite terms.
  11. Went to Multinode user interface and ANDed tac_lite realm.
  12. Anonymous user can see Test Group 01 and Public Test Page for Test Group 01.
  13. Logged in as user test02. This user can see everything except Test Page in Test Group 01: http://test.scbbs.com/node/8
  14. Made user test01 a "Group Contributor". Logged in as this user. He can see Test Page in Test Group 01 (Group Contributors Only): http://test.scbbs.com/node/8 as expected.
  15. Have tested with anonymous and authenticated group members. Need to test with authenticated user who is not a member of group.
  16. Removing user test01 from Test Group 01. He can now only see Public Test Page for Test Group 01: http://test.scbbs.com/node/6. This is as it should be.

Initial testing seems to be OK. Needed tac_lite_multinode.module for tac_lite node grants to work correctly.