Prechádzať zdrojové kódy

Removed the 'load tripal data' permission, and added support for loaders to use callbacks instead

Stephen Ficklin 6 rokov pred
rodič
commit
c59274f540

+ 26 - 0
tripal/includes/TripalImporter.inc

@@ -113,6 +113,32 @@ class TripalImporter {
    * value is empty then the path will be the default.
    */
   public static $menu_path = '';
+  
+  
+  /**
+   * If your importer requires more flexibility and advance features than
+   * the TripalImporter provies you can indicate a callback function. If set,
+   * the callback will be used to provide the importer interface to the
+   * end-user.  However, because this bypasses the class infrastructure the
+   * run() function will also not be available and your importer must be
+   * fully self-sufficient outside of this calss.  The benefit for using a
+   * TripalImporter desipte your loader being self-sufficient is that Tripal
+   * will treat your loader like all others providing a consistent location
+   * in the menu and set of permissions.
+   */
+  public static $callback = '';
+  
+  /**
+   * The name of the module that provides the callback function.
+   */
+  public static $callback_module = '';
+  
+  /**
+   * An include path for the callback function.  Use a relative path within
+   * this scope of this module
+   * (e.g. includes/loaders/tripal_chado_pub_importers).
+   */
+  public static $callback_path = '';
 
   // --------------------------------------------------------------------------
   //                  PRIVATE MEMBERS -- DO NOT EDIT or OVERRIDE

+ 20 - 17
tripal/tripal.module

@@ -323,15 +323,6 @@ function tripal_menu() {
     'type' => MENU_CALLBACK,
   );
 
-
-  $items['admin/tripal/loaders'] = array(
-    'title' => 'Data Loaders',
-    'description' => t('Tools facilitating data import.'),
-    'access arguments' => array('load tripal data'),
-    'type' => MENU_NORMAL_ITEM,
-    'weight' => 6
-  );
-
   // Add in the loaders
   $importers = tripal_get_importers();
   foreach ($importers as $class_name) {
@@ -339,18 +330,34 @@ function tripal_menu() {
     if (class_exists($class_name)) {
       $machine_name = $class_name::$machine_name;
       $menu_path = 'admin/tripal/loaders/' . $machine_name;
+      $callback = $class_name::$callback;
+      $callback_path = $class_name::$callback_path;
+      $callback_module = $class_name::$callback_module;
+      $page_args = [];
       if ($class_name::$menu_path) {
         $menu_path = $class_name::$menu_path;
       }
+      if (!$callback) {
+        $callback = 'drupal_get_form';
+        $page_args = ['tripal_get_importer_form', $class_name];
+      }      
+      if (!$callback_path) {
+        $callback_path = 'includes/tripal.importer.inc';
+      }
+      $file_path = drupal_get_path('module', 'tripal');
+      if ($callback_path and $callback_module) {
+        $file_path = drupal_get_path('module', $callback_module);
+      }      
+      
       $items[$menu_path] = array(
         'title' => $class_name::$name,
         'description' =>  $class_name::$description,
-        'page callback' => 'drupal_get_form',
-        'page arguments' => array('tripal_get_importer_form', $class_name),
+        'page callback' => $callback,
+        'page arguments' => $page_args,
         'access arguments' => array('use ' . $machine_name . ' importer'),
         'type' => MENU_NORMAL_ITEM,
-        'file' => 'includes/tripal.importer.inc',
-        'file path' => drupal_get_path('module', 'tripal'),
+        'file' => $callback_path,
+        'file path' => $file_path,
       );
     }
   }
@@ -695,10 +702,6 @@ function tripal_permission() {
       'description' => t('Allows the user to publish Tripal content for online access.'),
       'restrict access' => TRUE,
     ),
-    'load tripal data' => array(
-      'title' => t('Load data into the Tripal site'),
-      'description' => t('Allows the user to load data into the Tripal site using data loaders. Some data loaders may have their own specific permission as well.'),
-    ),
     'upload files' => array(
       'title' => t('Upload Files'),
       'description' => t('Allows the user to upload files using Tripal\'s HTML5 loader.'),

+ 132 - 0
tripal_chado/includes/TripalImporter/PubBulkImporter.inc

@@ -0,0 +1,132 @@
+<?php
+
+class PubBulkImporter extends TripalImporter {
+  /**
+   * The name of this loader.  This name will be presented to the site
+   * user.
+   */
+  public static $name = 'Chado Bulk Publication Importer';
+
+  /**
+   * The machine name for this loader. This name will be used to construct
+   * the URL for the loader.
+   */
+  public static $machine_name = 'chado_pub_bulk';
+
+  /**
+   * A brief description for this loader.  This description will be
+   * presented to the site user.
+   */
+  public static $description = 'Create and modify importers that can connect to and retreive publications from remote databases.';
+
+  /**
+   * An array containing the extensions of allowed file types.
+   */
+  public static $file_types = array();
+
+
+  /**
+   * Provides information to the user about the file upload.  Typically this
+   * may include a description of the file types allowed.
+   */
+  public static $upload_description = '';
+
+  /**
+   * The title that should appear above the upload button.
+   */
+  public static $upload_title = 'File Upload';
+
+  /**
+   * If the loader should require an analysis record.  To maintain provenance
+   * we should always indiate where the data we are uploading comes from.
+   * The method that Tripal attempts to use for this by associating upload files
+   * with an analysis record.  The analysis record provides the details for
+   * how the file was created or obtained. Set this to FALSE if the loader
+   * should not require an analysis when loading. if $use_analysis is set to
+   * true then the form values will have an 'analysis_id' key in the $form_state
+   * array on submitted forms.
+   */
+  public static $use_analysis = FALSE;
+
+  /**
+   * If the $use_analysis value is set above then this value indicates if the
+   * analysis should be required.
+   */
+  public static $require_analysis = FALSE;
+
+  /**
+   * Text that should appear on the button at the bottom of the importer
+   * form.
+   */
+  public static $button_text = 'Import from NCBI Taxonomy';
+
+  /**
+   * Indicates the methods that the file uploader will support.
+   */
+  public static $methods = array(
+    // Allow the user to upload a file to the server.
+    'file_upload' => FALSE,
+    // Allow the user to provide the path on the Tripal server for the file.
+    'file_local' => FALSE,
+    // Allow the user to provide a remote URL for the file.
+    'file_remote' => FALSE,
+  );
+
+  /**
+   * Indicates if the file must be provided.  An example when it may not be
+   * necessary to require that the user provide a file for uploading if the
+   * loader keeps track of previous files and makes those available for
+   * selection.
+   */
+  public static $file_required = FALSE;
+
+
+  /**
+   * The array of arguments used for this loader.  Each argument should
+   * be a separate array containing a machine_name, name, and description
+   * keys.  This information is used to build the help text for the loader.
+   */
+  public static $argument_list = array();
+
+
+  /**
+   * Indicates how many files are allowed to be uploaded.  By default this is
+   * set to allow only one file.  Change to any positive number. A value of
+   * zero indicates an unlimited number of uploaded files are allowed.
+   */
+  public static $cardinality = 0;
+  
+  /**
+   * Be default, all loaders are automaticlly added to the Admin >
+   * Tripal > Data Laders menu.  However, if this loader should be
+   * made available via a different menu path, then set it here.  If the
+   * value is empty then the path will be the default.
+   */
+  public static $menu_path = '';
+
+  /**
+   * If your importer requires more flexibility and advance features than
+   * the TripalImporter provies you can indicate a callback function. If set,
+   * the callback will be used to provide the importer interface to the
+   * end-user.  However, because this bypasses the class infrastructure the
+   * run() function will also not be available and your importer must be
+   * fully self-sufficient outside of this calss.  The benefit for using a
+   * TripalImporter desipte your loader being self-sufficient is that Tripal
+   * will treat your loader like all others providing a consistent location
+   * in the menu and set of permissions.
+   */
+  public static $callback = 'tripal_pub_importers_list';
+  
+  /**
+   * The name of the module that provides the callback function.
+   */
+  public static $callback_module = 'tripal_chado';
+  
+  /**
+   * An include path for the callback function.  Use a relative path within
+   * this scope of this module 
+   * (e.g. includes/loaders/tripal_chado_pub_importers).
+   */
+  public static $callback_path = 'includes/loaders/tripal_chado.pub_importers.inc';
+
+}

+ 11 - 12
tripal_chado/tripal_chado.module

@@ -386,13 +386,13 @@ function tripal_chado_menu() {
   //////////////////////////////////////////////////////////////////////////////
 
   $items['admin/tripal/loaders/pub'] = array(
-    'title' => t('Chado Publication Importers'),
+    'title' => t('Chado Bulk Publication Importer Callback'),
     'description' => t('Create and modify importers that can connect to and retreive publications from remote databases.'),
     'page callback' => 'tripal_pub_importers_list',
-    'access arguments' => array('load tripal data'),
+    'access arguments' => array('use chado_pub_bulk importer'),
     'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),
-    'type' => MENU_NORMAL_ITEM,
+    'type' => MENU_CALLBACK,
     'weight' => 0
   );
 
@@ -400,7 +400,7 @@ function tripal_chado_menu() {
     'title' => t('Add an Importer'),
     'description' => t('Add a new publication importer.'),
     'page callback' => 'tripal_pub_importer_setup_page',
-    'access arguments' => array('load tripal data'),
+    'access arguments' => array('use chado_pub_bulk importer'),
     'type ' => MENU_CALLBACK,
     'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),
@@ -408,7 +408,7 @@ function tripal_chado_menu() {
   $items['admin/tripal/loaders/pub/edit/%'] = array(
     'page callback' => 'tripal_pub_importer_setup_page',
     'page arguments' => array(5),
-    'access arguments' => array('load tripal data'),
+    'access arguments' => array('use chado_pub_bulk importer'),
     'type ' => MENU_CALLBACK,
     'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),
@@ -416,7 +416,7 @@ function tripal_chado_menu() {
   $items['admin/tripal/loaders/pub/raw/%'] = array(
     'page callback' => 'tripal_get_remote_pub_raw_page',
     'page arguments' => array(5),
-    'access arguments' => array('load tripal data'),
+    'access arguments' => array('use chado_pub_bulk importer'),
     'type ' => MENU_CALLBACK,
     'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),
@@ -425,7 +425,7 @@ function tripal_chado_menu() {
   // add a second link for the importer on the data loaders page
   $items['admin/tripal/loaders/pub/import'] = array(
     'page callback' => 'tripal_pub_importers_list',
-    'access arguments' => array('load tripal data'),
+    'access arguments' => array('use chado_pub_bulk importer'),
     'type' => MENU_CALLBACK,
     'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),
@@ -434,7 +434,7 @@ function tripal_chado_menu() {
   $items['admin/tripal/loaders/pub/submit/%'] = array(
     'page callback' => 'tripal_pub_importer_submit_job',
     'page arguments' => array(5),
-    'access arguments' => array('load tripal data'),
+    'access arguments' => array('use chado_pub_bulk importer'),
     'type ' => MENU_CALLBACK,
     'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),
@@ -443,7 +443,7 @@ function tripal_chado_menu() {
   $items['admin/tripal/loaders/pub/delete/%'] = array(
     'page callback' => 'tripal_pub_importer_delete',
     'page arguments' => array(5),
-    'access arguments' => array('load tripal data'),
+    'access arguments' => array('use chado_pub_bulk importer'),
     'type ' => MENU_CALLBACK,
     'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),
@@ -451,7 +451,7 @@ function tripal_chado_menu() {
   $items['admin/tripal/loaders/pub/changedb'] = array(
     'page callback' => 'tripal_pub_importer_setup_page_update_remotedb',
     'page arguments' => array(),
-    'access arguments' => array('load tripal data'),
+    'access arguments' => array('use chado_pub_bulk importer'),
     'type ' => MENU_CALLBACK,
     'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),
@@ -460,7 +460,7 @@ function tripal_chado_menu() {
   $items['admin/tripal/loaders/pub/criteria/%/%'] = array(
     'page callback' => 'tripal_pub_importer_setup_page_update_criteria',
     'page arguments' => array(5, 6),
-    'access arguments' => array('load tripal data'),
+    'access arguments' => array('use chado_pub_bulk importer'),
     'type ' => MENU_CALLBACK,
     'file' => 'includes/loaders/tripal_chado.pub_importers.inc',
     'file path' => drupal_get_path('module', 'tripal_chado'),
@@ -856,7 +856,6 @@ function tripal_chado_permission() {
       'title' => t('Administer Semantic Web and Chado Integration'),
       'description' => t('Allows the user to assign controlled vocabulary terms to tables and table columns in Chado.')
     ),
-
   );
 }