Browse Source

Allows namespace lockdown from settings.php

pull/105/head
Alan Stanley 14 years ago
parent
commit
026d16222a
  1. 6
      ObjectHelper.inc
  2. 28
      api/fedora_item.inc
  3. 54
      fedora_repository.module
  4. 115
      formClass.inc

6
ObjectHelper.inc

@ -611,7 +611,7 @@ class ObjectHelper {
$returnValue = FALSE;
$isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
if (!$isRestricted) {
$returnValue = TRUE;
$namespaceAccess = TRUE;
}
if ($pid == NULL) {
$pid = variable_get('fedora_repository_pid', 'islandora:top');
@ -621,10 +621,10 @@ class ObjectHelper {
foreach ($nameSpaceAllowed as $nameSpace) {
$pos = stripos($pid, $nameSpace);
if ($pos === 0) {
$returnValue = TRUE;
$namespaceAccess = TRUE;
}
}
if ($returnValue) {
if ($namespaceAccess) {
$user_access = user_access($op);
if ($user_access == NULL) {
return FALSE;

28
api/fedora_item.inc

@ -6,15 +6,14 @@ define ('RELS_EXT_URI', 'info:fedora/fedora-system:def/relations-external#');
define("FEDORA_MODEL_URI", 'info:fedora/fedora-system:def/model#');
class Fedora_Item {
public $pid = NULL; // The $pid of the fedora object represented by an instance of this class.
public $objectProfile = NULL;
private $datastreams_list = NULL; // A SimpleXML object to store a list of this item's datastreams
public $datastreams = NULL;
private static $connection_helper = NULL;
private static $instantiated_pids = array();
/**
* Create an object to represent an item in the Fedora repository.
* Throws a SOAPException if the PID is not in the repository.
@ -32,7 +31,8 @@ class Fedora_Item {
$this->objectProfile = & Fedora_Item::$instantiated_pids[$pid]->objectProfile;
$this->datastreams = & Fedora_Item::$instantiated_pids[$pid]->datastreams;
$this->datastreams_list = & Fedora_Item::$instantiated_pids[$pid]->datastreams_list;
} else {
}
else {
if (empty(self::$connection_helper)) {
self::$connection_helper = new ConnectionHelper();
}
@ -42,7 +42,8 @@ class Fedora_Item {
if (!empty($raw_objprofile)) {
$this->objectProfile = $raw_objprofile->objectProfile;
$this->datastreams = $this->get_datastreams_list_as_array();
} else {
}
else {
$this->objectProfile = '';
$this->datastreams = array();
}
@ -365,6 +366,7 @@ class Fedora_Item {
//}
return $this->datastreams_list;
}
/**
* * DatastreamControlGroup controlGroup - String restricted to the values of "X", "M", "R", or "E" (InlineXML,Managed Content,Redirect, or External Referenced).
* String ID - The datastream ID (64 characters max).
@ -394,7 +396,6 @@ class Fedora_Item {
);
return $this->soap_call('getDatastream', $params);
}
/**
@ -472,8 +473,7 @@ class Fedora_Item {
$relationships = array();
try {
$relsext = $this->get_datastream_dissemination('RELS-EXT');
}
catch (exception $e) {
} catch (exception $e) {
drupal_set_message("Error retrieving RELS-EXT of object $pid", 'error');
return $relationships;
}
@ -602,8 +602,8 @@ class Fedora_Item {
try {
self::ingest_from_FOXML_file($path . '/' . $file);
}
catch (exception $e) {
} catch (exception $e) {
}
}
// Close
@ -685,13 +685,13 @@ class Fedora_Item {
watchdog(t("FEDORA_REPOSITORY"), t("Error trying to get SOAP client connection."));
return NULL;
}
}
catch (exception $e) {
} catch (exception $e) {
if (!$quiet) {
if (preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/', $e->getMessage())) {
drupal_set_message(t('Error: Insufficient permissions to call SOAP function !fn.', array('!fn' => $function_name)), 'error');
} else {
}
else {
drupal_set_message(t("Error trying to call SOAP function $function_name. Check watchdog logs for more information."), 'error');
}
@ -711,8 +711,7 @@ class Fedora_Item {
watchdog(t("FEDORA_REPOSITORY"), t("Error trying to get SOAP client connection."));
return NULL;
}
}
catch (exception $e) {
} catch (exception $e) {
if (!$quiet) {
watchdog(t("FEDORA_REPOSITORY"), t("Error trying to call SOAP function !fn: !e", array('!fn' => $function_name, '!e' => $e)), NULL, WATCHDOG_ERROR);
@ -723,7 +722,6 @@ class Fedora_Item {
return $result;
}
/**
* Creates the minimal FOXML for a new Fedora object, which is then passed to
* ingest_from_FOXML to be added to the repository.

54
fedora_repository.module

@ -101,7 +101,8 @@ function fedora_repository_ingest_object($collection_pid=NULL, $collection_label
if (!validPid($collection_pid)) {
if (validPid(urldecode($collection_pid))) {
$collection_pid = urldecode($collection_pid);
} else {
}
else {
drupal_set_message(t("This collection PID $collection_pid is not valid"), 'error');
return ' ';
}
@ -205,7 +206,8 @@ function fedora_repository_ingest_form_validate($form, &$form_state) {
implode(' ', $allowedMimeTypes)));
file_delete($file);
return;
} elseif (!$cm->execIngestRules($file, $dformat)) {
}
elseif (!$cm->execIngestRules($file, $dformat)) {
drupal_set_message(t('Error following Content Model Rules'), 'error');
foreach (ContentModel::$errors as $err) {
drupal_set_message($err, 'error');
@ -262,7 +264,8 @@ function fedora_repository_purge_object_form(&$form_state, $pid, $referrer) {
//$form['#redirect'] = $referrer;
return $form;
} else {
}
else {
// ALSO do $form definition here. Your final submit handler (after user clicks Yes, I Confirm) will only see $form_state info defined here. Form you create here passed as param1 to confirm_form
return confirm_form($form, 'Confirm Purge Object', $referrer, 'Are you sure you want to delete this object? This action cannot be undone.', 'Delete', 'Cancel'); //Had better luck leaving off last param 'name'
@ -407,7 +410,8 @@ function fedora_repository_purge_object_form_submit($form, &$form_state) {
if (!isset($form_state['storage']['confirm'])) {
$form_state['storage']['confirm'] = TRUE; // this will cause the form to be rebuilt, entering the confirm part of the form
$form_state['rebuild'] = TRUE; // along with this
} else {
}
else {
// this is where you do your processing after they have pressed the confirm button
$params = array(
"pid" => $pid,
@ -422,7 +426,8 @@ function fedora_repository_purge_object_form_submit($form, &$form_state) {
} catch (exception $e) {
if (preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/', $e->getMessage())) {
drupal_set_message(t('Error: Insufficient permissions to purge object.'), 'error');
} else {
}
else {
drupal_set_message(t($e->getMessage()), 'error');
}
return;
@ -432,7 +437,8 @@ function fedora_repository_purge_object_form_submit($form, &$form_state) {
}
if (!empty($form_state['values']['referrer'])) {
$form_state['redirect'] = $form_state['values']['referrer'];
} else {
}
else {
$form_state['redirect'] = "fedora/repository/$collectionPid/";
}
}
@ -936,7 +942,8 @@ function fedora_repository_search($op = 'search', $keys = NULL) {
$searchQuery = NULL;
if (isset($type) && strcmp($type, ':')) {
$searchQuery = $type . ':' . $keys;
} else {
}
else {
$searchQuery = $keys;
}
//$searchQuery.=" AND (PID:vre OR PID:vre:ref OR PID:demo OR PID:changeme)";
@ -994,7 +1001,8 @@ function fedora_repository_search_page($resultData) {
$xsl = new DomDocument();
if ($isRestricted) {
$xsl->load($path . '/xsl/results.xsl');
} else {
}
else {
$xsl->load($path . '/xsl/unfilteredresults.xsl');
}
@ -1008,7 +1016,8 @@ function fedora_repository_search_page($resultData) {
'colspan' => 2
)
);
} else {
}
else {
$xsl = $proc->importStylesheet($xsl);
$newdom = $proc->transformToDoc($input);
@ -1267,7 +1276,8 @@ function fedora_repository_demo_objects_form() {
if (empty($demo_objects[$available_demo]->objectProfile)) {
//The demo objects collection does not exist in the repository, display a button to ingest them.
$form['install_demos']['demo_collections']['#options'][$available_demo] = $available_demo_desc;
} else {
}
else {
array_push($existing_demos, $demo_objects[$available_demo]);
}
}
@ -1279,10 +1289,12 @@ function fedora_repository_demo_objects_form() {
$datastreams_list = $smiley_stuff->get_datastreams_list_as_array();
if (empty($datastreams_list['COLLECTION_VIEW'])) {
$form['install_demos']['demo_collections']['#options']['demo:SmileyStuff'] = 'Add Islandora Collection View to Fedora Smiley Stuff Collection';
} else {
}
else {
$demo_objects['demo:SmileyStuff'] = $smiley_stuff;
}
} else {
}
else {
$form['install_demos']['smileynote'] = array(
'#value' => '<p>If you install the ' . l('fedora demo objects', 'https://wiki.duraspace.org/display/FCR30/Demonstration+Objects') . ' Islandora can display them as a collection.</p>'
);
@ -1531,7 +1543,8 @@ function fedora_repository_basket_form($form_state, $pids) {
$form['pid'] = array();
$form['title'] = array();
$form['desc'] = array();
} else {
}
else {
return;
}
@ -1589,7 +1602,8 @@ function theme_fedora_repository_basket_form($form) {
drupal_render($form['desc'][$key]),
);
}
} else {
}
else {
$rows[] = array(array('data' => t('Your basket is empty.'), 'colspan' => '4'));
}
@ -1627,7 +1641,8 @@ function fedora_repository_basket_form_submit($form, &$form_state) {
if ($form_state['values']['op'] == $form_state['values']['submit_all']) {
$msg = t("All objects exported to staging area");
$pids = _fedora_repository_get_basket_pids();
} elseif ($form_state['values']['op'] == $form_state['values']['submit']) {
}
elseif ($form_state['values']['op'] == $form_state['values']['submit']) {
$msg = t("Selected objects exported to staging area");
$pids = array_filter($form_state['values']['remove']);
}
@ -1662,7 +1677,8 @@ function fedora_repository_basket_form_submit($form, &$form_state) {
drupal_set_message($msg, $success ? 'info' : 'error');
//_fedora_repository_empty_basket();
} else {
}
else {
drupal_set_message(t("No objects selected or basket empty"), 'error');
}
@ -1712,7 +1728,8 @@ function fedora_repository_add_to_basket($pid, $warn = TRUE, $searchResultsFlag
if (!isset($_SESSION['basket'])) {
$_SESSION['basket'] = array();
$_SESSION['basket']['unprocessed'] = array($pid => $pid);
} else {
}
else {
$_SESSION['basket']['unprocessed'][$pid] = $pid;
}
@ -1764,7 +1781,8 @@ function fedora_repository_display_schema($file) {
$path = drupal_get_path('module', 'fedora_repository');
if (strtolower(substr($file, -3)) == 'xsd' && file_exists($path . '/' . $file)) {
drupal_goto($path . '/' . $file);
} else {
}
else {
drupal_goto();
}
return;

115
formClass.inc

@ -4,9 +4,6 @@
/*
* Created on Jan 22, 2008
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class formClass {
@ -28,10 +25,8 @@ class formClass {
'description' => t('Enter the Fedora Collection information here'),
'page callback' => 'drupal_get_form',
'page arguments' => array('fedora_repository_admin'),
//'access' => user_access('access administration pages'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
// 'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/settings/fedora_repository/collection'] = array(
'title' => t('Collection list'),
@ -54,9 +49,7 @@ class formClass {
'page callback' => 'fedora_repository_display_schema',
'page arguments' => array('islandoracm.xsd'),
'type' => MENU_CALLBACK,
// 'page arguments'=>array(1),
'access arguments' => array('view fedora collection'),
// 'access' => TRUE
);
$items['collection_policy.xsd'] = array(
@ -64,30 +57,25 @@ class formClass {
'page callback' => 'fedora_repository_display_schema',
'page arguments' => array('collection_policy.xsd'),
'type' => MENU_CALLBACK,
// 'page arguments'=>array(1),
'access arguments' => array('view fedora collection'),
// 'access' => TRUE
);
$items['fedora'] = array(
// 'title' => t('Digital repository'),
'page callback' => 'repository_page',
'type' => MENU_CALLBACK,
// 'page arguments'=>array(1),
'access arguments' => array('view fedora collection'),
// 'access' => TRUE
);
$repository_title = variable_get('fedora_repository_title', 'Digital repository');
if (trim($repository_title) != '') {
$respository_title = t($repository_title);
} else {
}
else {
$repository_title = NULL;
}
$items['fedora/repository'] = array(
'title' => $repository_title,
'page callback' => 'repository_page',
'type' => MENU_NORMAL_ITEM,
// 'page arguments'=>array(1),
'access arguments' => array('view fedora collection'),
// 'access' => TRUE
);
@ -202,23 +190,6 @@ class formClass {
'access arguments' => array('view fedora collection'),
);
/*
$items['fedora/item'] = array (
'title' => t('Repository Item'),
'access arguments' => array('view fedora collection'),
'page callback' => 'fedora_repository_item',
'type' => MENU_NORMAL_ITEM,
);
$item['feodra/item/view'] = array (
'title' => t('View Repository Item'),
'access arguments' => array('view fedora collection'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
*/
// $items = array_merge($items,$irItems);
return $items;
}
@ -297,7 +268,6 @@ class formClass {
'#description' => t('The URL to use for SOAP connections'),
'#required' => TRUE,
'#weight' => 0,
// '#suffix' => '<p>'. (fedora_available() ? '<img src="'. url('misc/watchdog-ok.png') . '"/>'. t('Successfully connected to Fedora server at ') : '<img src="'. url('misc/watchdog-error.png') . '"/> '. t('Unable to connect to Fedora server at ')) . variable_get('fedora_soap_url', '') . '</p>',
'#suffix' => '<p>' . (fedora_available() ? '<img src="' . url('misc/watchdog-ok.png') . '"/>' . t('Successfully connected to Fedora server at !fedora_soap_url', array('!fedora_soap_url' => variable_get('fedora_soap_url', ''))) : '<img src="' . url('misc/watchdog-error.png') . '"/> ' . t('Unable to connect to Fedora server at !fedora_soap_url</p>', array('!fedora_soap_url' => variable_get('fedora_soap_url', '')))),
);
$form['fedora_base_url'] = array(
@ -325,12 +295,12 @@ class formClass {
'#weight' => 0
);
// will allow admin user to remove namepsace restrictions if not explicitly disallowed in settings.php
if (variable_get('allow_open_namespace', TRUE)) {
$form['fedora_namespace'] = array(
'#type' => 'fieldset',
);
$form['fedora_namespace']['fedora_namespace_restriction_enforced'] = array(
'#weight' => -1,
'#type' => 'radios',
@ -348,24 +318,18 @@ class formClass {
'#title' => t('PID namespaces allowed in this Drupal install'),
'#default_value' => variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: '),
'#description' => t('A space separated list PID namespaces that users are permitted to access from this Drupal installation. <br /> This could be more than a simple namespace ie demo:mydemos.'),
'#weight' => 0
);
/*
$form['fedora_admin_user'] = array(
}
else {
$form['fedora_pids_allowed'] = array(
'#type' => 'textfield',
'#title' => t('A user with the Drupal role administrator'),
'#default_value' => variable_get('fedora_admin_user', 'admin'),
'#description' => t('A user with the administrator role. This is the user the Islandora module will use when admin access is needed for a task, such as creating a collection object for a new user.'),
'#required' => TRUE, '#weight' => 0
);
$form['fedora_searchterms_location'] = array(
'#type' => 'file',
'#title' => 'SearchTerms.xml file location',
'#title' => t('PID namespaces allowed in this Drupal install'),
'#default_value' => variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: '),
'#description' => t('A space separated list PID namespaces that users are permitted to access from this Drupal installation. <br /> This could be more than a simple namespace ie demo:mydemos.'),
'#weight' => 0
);
*/
}
$form['fedora_repository_title'] = array(
'#type' => 'textfield',
'#title' => t('Fedora Repository Title'),
@ -373,7 +337,6 @@ class formClass {
'#description' => t('The title displayed when viewing collections and objects in /fedora/repository. Leave blank to display no title. Note that the menus must be rebuilt after changing this variable.'),
);
$form['fedora_object_display_title'] = array(
'#type' => 'select',
'#title' => t('Display Object Title Behaviour'),
@ -382,8 +345,6 @@ class formClass {
'#description' => t('Determines when to display the object (or collection) title when viewing an object/collection page.'),
);
$form['fedora_object_display_description'] = array(
'#type' => 'select',
'#title' => t('Display Object Description Behaviour'),
@ -407,7 +368,6 @@ class formClass {
'#description' => t('Determines when to display the list of objects when viewing a collection page.'),
);
//Export functionality
$form['module']['export_area'] = array(
'#type' => 'textfield',
@ -553,7 +513,6 @@ class formClass {
'#options' => $modelsForForm,
//'#description' => t('Content models available in this collection. A content model defines what is allowed in a collection and what to do with a file when it is uploaded (An example may creating a thumbnail from an image.).')
'#description' => t('Content models define datastream composition, relationships between this and other content models, and the mandatory behaviors associated with each digital object.<br /> Additional information may be found <a href="https://wiki.duraspace.org/display/FEDORACREATE/Content+Models+Overview">here.</a> ')
);
break;
@ -658,15 +617,6 @@ class formClass {
'#type' => 'hidden',
'#value' => "$pid"
);
/*
$form['stream_location'] = array (
'#title' => 'File Location',
'#required' => 'TRUE',
'#description' => 'The path to the file for the new datastream',
//'#prefix' => '<a onclick="window.open(\'?q=imce/browse\', \'_imce_fedora_\', \'width=640, height=600, resizable=1\')" href="#">Upload File</a>',
'#type' => 'hidden'
);
*/
$form['stream_label'] = array(
'#title' => 'Datastream Label',
@ -674,13 +624,7 @@ class formClass {
'#description' => t('A Human readable label'),
'#type' => 'textfield'
);
// $form['delete_file'] = array (
// '#title' => 'Remove File After Ingest',
// '#description' => 'Remove the file from the drupal file system after ingest into the Digital Repository.',
// '#type' => 'hidden',
// '#default_value' => 'remove_file',
// '#options' => $options
// );
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['add-stream-file-location'] = array(
'#type' => 'file',
@ -792,7 +736,7 @@ class formClass {
}
}
}
// $form['#redirect'] = "fedora/repository/$pid/";
$form['pid'] = array(
'#type' => 'hidden',
'#value' => "$pid"
@ -845,34 +789,5 @@ class formClass {
return $form;
}
/*
function createReplaceDataStreamForm($pid, $dsId, &$form_state) {
$form = array();
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['file'] = array(
'#type' => 'file',
'#title' => t('Upload Document'),
'#description' => t('The file to upload.')
);
$form['pid'] = array(
'#type' => 'value',
'#value' => $pid,
);
$form['dsId'] = array(
'#type' => 'value',
'#value' => $dsId,
);
$form['submit']=array(
'#type' => 'submit',
'#value'=>t('Replace Datastream')
);
return $form;
}
*/
}

Loading…
Cancel
Save