You are here

function filedepot_node_access in filedepot 7

Implementation of hook_node_access().

File

./filedepot.module, line 510
filedepot.module Filedepot: File Management Module developed by Nextide www.nextide.ca Full featured document managment module with a desktop application feel. Integrated Organic Group, Role and User permissions to secure folders, automated…

Code

function filedepot_node_access($node, $op) {

  // By default don't effect the access permissions unless this node is a filedepot_folder
  $ret = NODE_ACCESS_IGNORE;
  if (!is_object($node) || (!isset($node->nid) or !isset($node->type) or $node->type != 'filedepot_folder')) {
    return $ret;
  }

  // We have a filedepot_folder node, so DENY access by default unless user has permission
  $ret = NODE_ACCESS_DENY;
  $res = db_query("SELECT cid FROM {filedepot_categories} WHERE nid=:nid", array(
    ':nid' => $node->nid,
  ));
  if (!$res) {
    return NODE_ACCESS_DENY;
  }
  $cid = $res
    ->fetchField();
  if ($cid > 0) {
    $filedepot = filedepot_filedepot();
    module_load_include('php', 'filedepot', 'lib-common');
    switch ($op) {
      case 'view':
        if ($filedepot
          ->checkPermission($cid, 'view')) {
          $ret = NODE_ACCESS_ALLOW;
        }
        break;
      case 'update':
        if ($filedepot
          ->checkPermission($cid, 'admin')) {
          $ret = NODE_ACCESS_ALLOW;
        }
        break;
      case 'delete':
        if ($filedepot
          ->checkPermission($cid, 'admin')) {
          $ret = NODE_ACCESS_ALLOW;
        }
        break;
      case 'create':
        $parent = filedepot_getTopLevelParent($cid);
        if ($parent == 0) {
          if (user_access('administer filedepot')) {
            $ret = NODE_ACCESS_ALLOW;
          }
        }
        else {
          if ($filedepot
            ->checkPermission($cid, 'admin')) {
            $ret = NODE_ACCESS_ALLOW;
          }
        }
    }
  }
  return $ret;
}