You are here

function pmtask_node_access_records in Drupal PM (Project Management) 7

Implements hook_node_access_records().

File

pmtask/pmtask.module, line 821

Code

function pmtask_node_access_records($node) {
  if (empty($node->status)) {

    // Lets Drupal take care of permission to unpublished nodes.
    return array();
  }
  $type = is_string($node) ? $node : $node->type;
  $grants = array();
  if ($type == 'pmtask') {

    // Project Management Task: view all
    $grants[] = array(
      'realm' => 'pmtask_view_all',
      'gid' => 0,
      'grant_view' => 1,
      'grant_update' => 0,
      'grant_delete' => 0,
      'priority' => 0,
    );

    // Project Management Task: view own
    $grants[] = array(
      'realm' => 'pmtask_view_own',
      'gid' => $node->uid,
      'grant_view' => 1,
      'grant_update' => 0,
      'grant_delete' => 0,
      'priority' => 0,
    );

    // Project Management Task: view of user organization
    if (isset($node->organization_nid) && !empty($node->organization_nid)) {
      $grants[] = array(
        'realm' => 'pmtask_view_if_user_organization',
        'gid' => $node->organization_nid,
        'grant_view' => 1,
        'grant_update' => 0,
        'grant_delete' => 0,
        'priority' => 0,
      );
    }

    // Project Management Task: view if assigned to task
    if (isset($node->assigned_nid) && !empty($node->assigned_nid)) {
      $grants[] = array(
        'realm' => 'pmtask_view_if_assigned',
        'gid' => $node->assigned_nid,
        'grant_view' => 1,
        'grant_update' => 0,
        'grant_delete' => 0,
        'priority' => 0,
      );
    }

    // Project Management Task: edit all
    $grants[] = array(
      'realm' => 'pmtask_update_all',
      'gid' => 0,
      'grant_view' => 0,
      'grant_update' => 1,
      'grant_delete' => 0,
      'priority' => 0,
    );

    // Project Management Task: edit own
    $grants[] = array(
      'realm' => 'pmtask_update_own',
      'gid' => $node->uid,
      'grant_view' => 0,
      'grant_update' => 1,
      'grant_delete' => 0,
      'priority' => 0,
    );

    // Project Management Task: edit of user organization
    if (isset($node->organization_nid) && !empty($node->organization_nid)) {
      $grants[] = array(
        'realm' => 'pmtask_update_if_user_organization',
        'gid' => $node->organization_nid,
        'grant_view' => 0,
        'grant_update' => 1,
        'grant_delete' => 0,
        'priority' => 0,
      );
    }

    // Project Management Task: edit if assigned to task
    if (isset($node->assigned_nid) && !empty($node->assigned_nid)) {
      $grants[] = array(
        'realm' => 'pmtask_update_if_assigned',
        'gid' => $node->assigned_nid,
        'grant_view' => 0,
        'grant_update' => 1,
        'grant_delete' => 0,
        'priority' => 0,
      );
    }

    // Project Management Task: delete all
    $grants[] = array(
      'realm' => 'pmtask_delete_all',
      'gid' => 0,
      'grant_view' => 0,
      'grant_update' => 0,
      'grant_delete' => 1,
      'priority' => 0,
    );

    // Project Management Task: delete own
    $grants[] = array(
      'realm' => 'pmtask_delete_own',
      'gid' => $node->uid,
      'grant_view' => 0,
      'grant_update' => 0,
      'grant_delete' => 1,
      'priority' => 0,
    );

    // Project Management Task: delete of user organization
    if (isset($node->organization_nid) && !empty($node->organization_nid)) {
      $grants[] = array(
        'realm' => 'pmtask_delete_if_user_organization',
        'gid' => $node->organization_nid,
        'grant_view' => 0,
        'grant_update' => 0,
        'grant_delete' => 1,
        'priority' => 0,
      );
    }

    // Project Management Task: delete if assigned to task
    if (isset($node->assigned_nid) && !empty($node->assigned_nid)) {
      $grants[] = array(
        'realm' => 'pmtask_delete_if_assigned',
        'gid' => $node->assigned_nid,
        'grant_view' => 0,
        'grant_update' => 0,
        'grant_delete' => 1,
        'priority' => 0,
      );
    }
  }
  return $grants;
}