Browse Source

Fixed problem with hook_node_access functions denying all pages

Stephen Ficklin 11 years ago
parent
commit
283f42f54c

+ 24 - 17
tripal_analysis/includes/tripal_analysis.chado_node.inc

@@ -570,28 +570,35 @@ function chado_analysis_load($nodes) {
  */
 function chado_analysis_node_access($node, $op, $account) {
 
-  if ($op == 'create') {
-    if (!user_access('create chado_analysis content', $account)) {
-      return FALSE;
-    }
-    return TRUE;
+  $node_type = $node;
+  if (is_object($node)) {
+    $node_type = $node->type;
   }
-  if ($op == 'update') {
-    if (!user_access('edit chado_analysis content', $account)) {
-      return FALSE;
+  
+  if($node_type == 'chado_analysis') {
+    if ($op == 'create') {
+      if (!user_access('create chado_analysis content', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+      return NODE_ACCESS_ALLOW;
     }
-  }
-  if ($op == 'delete') {
-    if (!user_access('delete chado_analysis content', $account)) {
-      return FALSE;
+    if ($op == 'update') {
+      if (!user_access('edit chado_analysis content', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
-  }
-  if ($op == 'view') {
-    if (!user_access('access chado_analysis content', $account)) {
-      return FALSE;
+    if ($op == 'delete') {
+      if (!user_access('delete chado_analysis content', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+    }
+    if ($op == 'view') {
+      if (!user_access('access chado_analysis content', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
+    return NODE_ACCESS_IGNORE;
   }
-  return NULL;
 }
 
 /**

+ 24 - 20
tripal_bulk_loader/includes/tripal_bulk_loader.chado_node.inc

@@ -333,29 +333,33 @@ function tripal_bulk_loader_update($node) {
  * @ingroup tripal_bulk_loader
  */
 function tripal_bulk_loader_node_access($node, $op, $account) {
-  if ($op == 'create') {
-    if (!user_access('create tripal_bulk_loader', $account)) {
-      return NODE_ACCESS_DENY;
-    }
-    return NODE_ACCESS_ALLOW;
+  $node_type = $node;
+  if (is_object($node)) {
+    $node_type = $node->type;
   }
-  if ($op == 'update') {
-    if (!user_access('edit tripal_bulk_loader', $account)) {
-      return NODE_ACCESS_DENY;
+  
+  if($node_type == 'tripal_bulk_loader') {
+    if ($op == 'create') {
+      if (!user_access('create tripal_bulk_loader', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+      return NODE_ACCESS_ALLOW;
     }
-    return NODE_ACCESS_ALLOW;
-  }
-  if ($op == 'delete') {
-    if (!user_access('delete tripal_bulk_loader', $account)) {
-      return NODE_ACCESS_DENY;
+    if ($op == 'update') {
+      if (!user_access('edit tripal_bulk_loader', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
-    return NODE_ACCESS_ALLOW;
-  }
-  if ($op == 'view') {
-    if (!user_access('access tripal_bulk_loader', $account)) {
-      return NODE_ACCESS_DENY;
+    if ($op == 'delete') {
+      if (!user_access('delete tripal_bulk_loader', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+    }
+    if ($op == 'view') {
+      if (!user_access('access tripal_bulk_loader', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
-    return NODE_ACCESS_ALLOW;
+    return NODE_ACCESS_IGNORE;
   }
-  return NODE_ACCESS_IGNORE;
 }

+ 26 - 18
tripal_contact/includes/tripal_contact.chado_node.inc

@@ -308,29 +308,37 @@ function chado_contact_validate($node, $form, &$form_state) {
  * @ingroup tripal_contact
  */
 function chado_contact_node_access($node, $op, $account ) {
-  if ($op == 'create') {
-    if (!user_access('create chado_contact content', $account)) {
-      return FALSE;
-    }
-    return TRUE;
+  
+  $node_type = $node;
+  if (is_object($node)) {
+    $node_type = $node->type;
   }
-
-  if ($op == 'update') {
-    if (!user_access('edit chado_contact content', $account)) {
-      return FALSE;
+  
+  if($node_type == 'chado_contact') {
+    if ($op == 'create') {
+      if (!user_access('create chado_contact content', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+      return NODE_ACCESS_ALLOW;
     }
-  }
-  if ($op == 'delete') {
-    if (!user_access('delete chado_contact content', $account)) {
-      return FALSE;
+  
+    if ($op == 'update') {
+      if (!user_access('edit chado_contact content', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
-  }
-  if ($op == 'view') {
-    if (!user_access('access chado_contact content', $account)) {
-      return FALSE;
+    if ($op == 'delete') {
+      if (!user_access('delete chado_contact content', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+    }
+    if ($op == 'view') {
+      if (!user_access('access chado_contact content', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
   }
-  return NULL;
+  return NODE_ACCESS_IGNORE;
 }
 
 

+ 1 - 1
tripal_core/api/tripal_core.tripal.api.inc

@@ -132,7 +132,7 @@ function tripal_set_message($message, $importance = TRIPAL_INFO, $options = arra
 
   // Only show the message to the administrator user (uid=1)
   // thus if the current user is not the administrator then return nothing
-  if ($user->uid > 1) {
+  if (!user_access('administer tripal')) {
     return '';
   }
 

+ 24 - 17
tripal_example/includes/tripal_example.chado_node.inc

@@ -61,28 +61,35 @@ function tripal_example_node_info() {
  * by other modules.
  */
 function chado_example_node_access($node, $op, $account) {
-  if ($op == 'create') {
-    if (!user_access('create chado_example content', $account)) {
-      return FALSE;
-    }
-    return TRUE;
+  $node_type = $node;
+  if (is_object($node)) {
+    $node_type = $node->type;
   }
-  if ($op == 'update') {
-    if (!user_access('edit chado_example content', $account)) {
-      return FALSE;
+  
+  if($node_type == 'chado_example') {
+    if ($op == 'create') {
+      if (!user_access('create chado_example content', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+      return NODE_ACCESS_ALLOW;
     }
-  }
-  if ($op == 'delete') {
-    if (!user_access('delete chado_example content', $account)) {
-      return FALSE;
+    if ($op == 'update') {
+      if (!user_access('edit chado_example content', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
-  }
-  if ($op == 'view') {
-    if (!user_access('access chado_example content', $account)) {
-      return FALSE;
+    if ($op == 'delete') {
+      if (!user_access('delete chado_example content', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+    }
+    if ($op == 'view') {
+      if (!user_access('access chado_example content', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
   }
-  return NULL;
+  return NODE_ACCESS_IGNORE;
 }
 
 /**

+ 25 - 18
tripal_feature/includes/tripal_feature.chado_node.inc

@@ -344,29 +344,36 @@ function chado_feature_validate($node, $form, &$form_state) {
  * @ingroup tripal_feature
  */
 function chado_feature_node_access($node, $op, $account) {
-  if ($op == 'create') {
-    if (!user_access('create chado_feature content', $account)) {
-      return FALSE;
+  $node_type = $node;
+  if (is_object($node)) {
+    $node_type = $node->type;
+  }
+  
+  if($node_type == 'chado_feature') {
+    if ($op == 'create') {
+      if (!user_access('create chado_feature content', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+      return NODE_ACCESS_ALLOW;
     }
-    return TRUE;
-  }
-
-  if ($op == 'update') {
-    if (!user_access('edit chado_feature content', $account)) {
-      return FALSE;
+  
+    if ($op == 'update') {
+      if (!user_access('edit chado_feature content', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
-  }
-  if ($op == 'delete') {
-    if (!user_access('delete chado_feature content', $account)) {
-      return FALSE;
+    if ($op == 'delete') {
+      if (!user_access('delete chado_feature content', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
-  }
-  if ($op == 'view') {
-    if (!user_access('access chado_feature content', $account)) {
-      return FALSE;
+    if ($op == 'view') {
+      if (!user_access('access chado_feature content', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
   }
-  return NULL;
+  return NODE_ACCESS_IGNORE;
 }
 
 /**

+ 23 - 23
tripal_featuremap/includes/tripal_featuremap.chado_node.inc

@@ -221,35 +221,35 @@ function chado_featuremap_validate($node, $form, &$form_state) {
  * @ingroup tripal_featuremap
  */
 function chado_featuremap_node_access($node, $op, $account) {
-  if ($op == 'create') {
-    if (!user_access('create chado_featuremap content', $account)) {
-      return FALSE;
-    }
-    return TRUE;
+  $node_type = $node;
+  if (is_object($node)) {
+    $node_type = $node->type;
   }
-
-  if ($op == 'update') {
-    if (!user_access('edit any chado_featuremap content', $account) &&
-    !user_access('edit own chado_featuremap content', $account)) {
-      return FALSE;
+  
+  if($node_type == 'chado_featuremap') {
+    if ($op == 'create') {
+      if (!user_access('create chado_featuremap', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+      return NODE_ACCESS_ALLOW;
     }
-    if (user_access('edit own chado_featuremap content', $account) &&
-    $account->uid != $node->uid) {
-      return FALSE;
+    if ($op == 'update') {
+      if (!user_access('edit chado_featuremap', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
-  }
-
-  if ($op == 'delete') {
-    if (!user_access('delete any chado_featuremap content', $account) &&
-    !user_access('delete own chado_featuremap content', $account)) {
-      return FALSE;
+    if ($op == 'delete') {
+      if (!user_access('delete chado_featuremap', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
-    if (user_access('delete own chado_featuremap content', $account) &&
-    $account->uid != $node->uid) {
-      return FALSE;
+    if ($op == 'view') {
+      if (!user_access('access chado_featuremap', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
+    return NODE_ACCESS_IGNORE;
   }
-  return NULL;
 }
 
 /**

+ 24 - 17
tripal_library/includes/tripal_library.chado_node.inc

@@ -441,28 +441,35 @@ function chado_library_delete(&$node) {
  * @ingroup tripal_library
  */
 function chado_library_node_access($node, $op, $account) {
-  if ($op == 'create') {
-    if (!user_access('create chado_library content', $account)) {
-      return FALSE;
-    }
-    return TRUE;
+  $node_type = $node;
+  if (is_object($node)) {
+    $node_type = $node->type;
   }
-  if ($op == 'update') {
-    if (!user_access('edit chado_library content', $account)) {
-      return FALSE;
+  
+  if($node_type == 'chado_library') {
+    if ($op == 'create') {
+      if (!user_access('create chado_library', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+      return NODE_ACCESS_ALLOW;
     }
-  }
-  if ($op == 'delete') {
-    if (!user_access('delete chado_library content', $account)) {
-      return FALSE;
+    if ($op == 'update') {
+      if (!user_access('edit chado_library', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
-  }
-  if ($op == 'view') {
-    if (!user_access('access chado_library content', $account)) {
-      return FALSE;
+    if ($op == 'delete') {
+      if (!user_access('delete chado_library', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+    }
+    if ($op == 'view') {
+      if (!user_access('access chado_library', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
+    return NODE_ACCESS_IGNORE;
   }
-  return NULL;
 }
 
 /**

+ 24 - 17
tripal_organism/includes/tripal_organism.chado_node.inc

@@ -62,28 +62,35 @@ function tripal_organism_node_info() {
  * @ingroup tripal_organism
  */
 function chado_organism_node_access($node, $op, $account) {
-  if ($op == 'create') {
-    if (!user_access('create chado_organism content', $account)) {
-      return FALSE;
-    }
-    return TRUE;
+  $node_type = $node;
+  if (is_object($node)) {
+    $node_type = $node->type;
   }
-  if ($op == 'update') {
-    if (!user_access('edit chado_organism content', $account)) {
-      return FALSE;
+  
+  if($node_type == 'chado_organism') {
+    if ($op == 'create') {
+      if (!user_access('create chado_organism', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+      return NODE_ACCESS_ALLOW;
     }
-  }
-  if ($op == 'delete') {
-    if (!user_access('delete chado_organism content', $account)) {
-      return FALSE;
+    if ($op == 'update') {
+      if (!user_access('edit chado_organism', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
-  }
-  if ($op == 'view') {
-    if (!user_access('access chado_organism content', $account)) {
-      return FALSE;
+    if ($op == 'delete') {
+      if (!user_access('delete chado_organism', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+    }
+    if ($op == 'view') {
+      if (!user_access('access chado_organism', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
+    return NODE_ACCESS_IGNORE;
   }
-  return NULL;
 }
 
 /**

+ 24 - 17
tripal_project/includes/tripal_project.chado_node.inc

@@ -427,28 +427,35 @@ function chado_project_load($nodes) {
  */
 function chado_project_node_access($node, $op, $account) {
 
-  if ($op == 'create') {
-    if (!user_access('create chado_projects content', $account)) {
-      return FALSE;
-    }
-    return TRUE;
+  $node_type = $node;
+  if (is_object($node)) {
+    $node_type = $node->type;
   }
-  if ($op == 'update') {
-    if (!user_access('edit chado_projects content', $account)) {
-      return FALSE;
+  
+  if($node_type == 'chado_project') {
+    if ($op == 'create') {
+      if (!user_access('create chado_project', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+      return NODE_ACCESS_ALLOW;
     }
-  }
-  if ($op == 'delete') {
-    if (!user_access('delete chado_projects content', $account)) {
-      return FALSE;
+    if ($op == 'update') {
+      if (!user_access('edit chado_project', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
-  }
-  if ($op == 'view') {
-    if (!user_access('access chado_projects content', $account)) {
-      return FALSE;
+    if ($op == 'delete') {
+      if (!user_access('delete chado_project', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+    }
+    if ($op == 'view') {
+      if (!user_access('access chado_project', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
+    return NODE_ACCESS_IGNORE;
   }
-  return NULL;
 }
 
 /**

+ 24 - 18
tripal_pub/includes/tripal_pub.chado_node.inc

@@ -528,29 +528,35 @@ function chado_pub_validate_check_duplicate($title, $pyear, $series_name, $cvter
  * @ingroup tripal_pub
  */
 function chado_pub_node_access($node, $op, $account) {
-  if ($op == 'create') {
-    if (!user_access('create chado_pub content', $account)) {
-      return FALSE;
-    }
-    return TRUE;
+  $node_type = $node;
+  if (is_object($node)) {
+    $node_type = $node->type;
   }
-
-  if ($op == 'update') {
-    if (!user_access('edit chado_pub content', $account)) {
-      return FALSE;
+  
+  if($node_type == 'chado_pub') {
+    if ($op == 'create') {
+      if (!user_access('create chado_pub', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+      return NODE_ACCESS_ALLOW;
     }
-  }
-  if ($op == 'delete') {
-    if (!user_access('delete chado_pub content', $account)) {
-      return FALSE;
+    if ($op == 'update') {
+      if (!user_access('edit chado_pub', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
-  }
-  if ($op == 'view') {
-    if (!user_access('access chado_pub content', $account)) {
-      return FALSE;
+    if ($op == 'delete') {
+      if (!user_access('delete chado_pub', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+    }
+    if ($op == 'view') {
+      if (!user_access('access chado_pub', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
+    return NODE_ACCESS_IGNORE;
   }
-  return NULL;
 }
 
 /**

+ 24 - 17
tripal_stock/tripal_stock.module

@@ -178,28 +178,35 @@ function tripal_stock_permission() {
  * @ingroup tripal_stock
  */
 function chado_stock_node_access($node, $op, $account) {
-  if ($op == 'create') {
-    if (!user_access('create chado_stock content', $account)) {
-      return FALSE;
-    }
-    return TRUE;
+  $node_type = $node;
+  if (is_object($node)) {
+    $node_type = $node->type;
   }
-  if ($op == 'update') {
-    if (!user_access('edit chado_stock content', $account)) {
-      return FALSE;
+  
+  if($node_type == 'chado_stock') {
+    if ($op == 'create') {
+      if (!user_access('create chado_stock', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+      return NODE_ACCESS_ALLOW;
     }
-  }
-  if ($op == 'delete') {
-    if (!user_access('delete chado_stock content', $account)) {
-      return FALSE;
+    if ($op == 'update') {
+      if (!user_access('edit chado_stock', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
-  }
-  if ($op == 'view') {
-    if (!user_access('access chado_stock content', $account)) {
-      return FALSE;
+    if ($op == 'delete') {
+      if (!user_access('delete chado_stock', $account)) {
+        return NODE_ACCESS_DENY;
+      }
+    }
+    if ($op == 'view') {
+      if (!user_access('access chado_stock', $account)) {
+        return NODE_ACCESS_DENY;
+      }
     }
+    return NODE_ACCESS_IGNORE;
   }
-  return NULL;
 }
 
 /**