You are here

function pmproject_node_grants in Drupal PM (Project Management) 7

Implements hook_node_grants().

File

pmproject/pmproject.module, line 861

Code

function pmproject_node_grants($account, $op) {
  if (module_exists('pmperson')) {
    _pmperson_user_load($account);
    if (!empty($account->pmteam) and is_array($account->pmteam)) {
      $assigned_nids = $account->pmteam;
    }
    if (isset($account->pmperson_nid) and !empty($account->pmperson_nid)) {
      $assigned_nids[] = $account->pmperson_nid;
    }
  }
  $grants = array();
  switch ($op) {
    case 'view':
      if (user_access('Project Management Project: view all', $account)) {
        $grants['pmproject_view_all'] = array(
          0,
        );
      }
      if (user_access('Project Management Project: view own', $account)) {
        $grants['pmproject_view_own'] = array(
          $account->uid,
        );
      }
      if (user_access('Project Management Project: view of user organization', $account)) {
        $grants['pmproject_view_if_user_organization'] = array(
          $account->pmorganization_nid,
        );
      }
      if (isset($account->pmperson_nid)) {
        if (user_access('Project Management Project: view if project manager', $account)) {
          $grants['pmproject_view_if_manager'] = array(
            $account->pmperson_nid,
          );
        }
        if (user_access('Project Management Project: view if assigned to project', $account)) {
          $grants['pmproject_view_if_assigned'] = $assigned_nids;
        }
      }
      break;
    case 'update':
      if (user_access('Project Management Project: edit all', $account)) {
        $grants['pmproject_update_all'] = array(
          0,
        );
      }
      if (user_access('Project Management Project: edit own', $account)) {
        $grants['pmproject_update_own'] = array(
          $account->uid,
        );
      }
      if (user_access('Project Management Project: edit of user organization', $account)) {
        $grants['pmproject_update_if_user_organization'] = array(
          $account->pmorganization_nid,
        );
      }
      if (isset($account->pmperson_nid)) {
        if (user_access('Project Management Project: edit if project manager', $account)) {
          $grants['pmproject_update_if_manager'] = array(
            $account->pmperson_nid,
          );
        }
        if (user_access('Project Management Project: edit if assigned to project', $account)) {
          $grants['pmproject_update_if_assigned'] = $assigned_nids;
        }
      }
      break;
    case 'delete':
      if (user_access('Project Management Project: delete all', $account)) {
        $grants['pmproject_delete_all'] = array(
          0,
        );
      }
      if (user_access('Project Management Project: delete own', $account)) {
        $grants['pmproject_delete_own'] = array(
          $account->uid,
        );
      }
      if (user_access('Project Management Project: delete of user organization', $account)) {
        $grants['pmproject_delete_if_user_organization'] = array(
          $account->pmorganization_nid,
        );
      }
      if (isset($account->pmperson_nid)) {
        if (user_access('Project Management Project: delete if project manager', $account)) {
          $grants['pmproject_delete_if_manager'] = array(
            $account->pmperson_nid,
          );
        }
        if (user_access('Project Management Project: delete if assigned to project', $account)) {
          $grants['pmproject_delete_if_assigned'] = $assigned_nids;
        }
      }
      break;
  }
  return $grants;
}