Browse Source

Ensured that both namespace user permissions are checked

pull/105/head
Alan Stanley 14 years ago
parent
commit
ce049c0730
  1. 242
      ObjectHelper.inc

242
ObjectHelper.inc

@ -32,7 +32,7 @@ class ObjectHelper {
//$this->fedoraPass = $connectionHelper->getPassword();
}
/**
/**
* Grabs a stream from fedora sets the mimetype and returns it. $dsID is the
* datastream id. If $forceSoap is set, the function will always buffer the datastream from fedora. Otherwise, it will
* try and use a redirect if possible.
@ -41,7 +41,7 @@ class ObjectHelper {
*/
function makeObject($pid, $dsID, $asAttachment = FALSE, $label = NULL, $filePath=FALSE, $version=NULL, $forceSoap = FALSE) {
global $user;
module_load_include('inc','fedora_repository','ContentModel');
module_load_include('inc', 'fedora_repository', 'ContentModel');
if ($pid == NULL || $dsID == NULL) {
drupal_set_message(t("no pid or dsid given to create an object with"), 'error');
return ' ';
@ -61,18 +61,18 @@ class ObjectHelper {
}
if (variable_get('fedora_object_restrict_datastreams', FALSE) == TRUE ) {
if (variable_get('fedora_object_restrict_datastreams', FALSE) == TRUE) {
if (($cm = ContentModel::loadFromObject($pid)) == FALSE) {
drupal_set_message(t("You do not have access to objects without an Islandora Content Model."), 'error');
drupal_access_denied();
return ' ';
drupal_set_message(t("You do not have access to objects without an Islandora Content Model."), 'error');
drupal_access_denied();
return ' ';
}
$cmDatastreams = $cm->listDatastreams();
if ( !((isset($user) && in_array('administrator',$user->roles)) || in_array($dsID,$cmDatastreams))) {
drupal_set_message(t("You do not have access to the specified datastream."), 'error');
drupal_access_denied();
return ' ';
if (!((isset($user) && in_array('administrator', $user->roles)) || in_array($dsID, $cmDatastreams))) {
drupal_set_message(t("You do not have access to the specified datastream."), 'error');
drupal_access_denied();
return ' ';
}
}
@ -81,9 +81,9 @@ class ObjectHelper {
if (isset($item->datastreams[$dsID])) {
$mimeType=$item->datastreams[$dsID]['MIMEType'];
$mimeType = $item->datastreams[$dsID]['MIMEType'];
if ($label == NULL) {
$label = $item->datastreams[$dsID]['label'];
$label = $item->datastreams[$dsID]['label'];
}
} else {
drupal_not_found();
@ -94,7 +94,7 @@ class ObjectHelper {
if ((!isset($user)) || $user->uid == 0) {
$fedoraUser = 'anonymous';
$fedoraPass = 'anonymous';
$contentSize= 0;
$contentSize = 0;
} else {
$fedoraUser = $user->name;
$fedoraPass = $user->pass;
@ -102,7 +102,7 @@ class ObjectHelper {
$contentSize = $dataStreamInfo->datastream->size;
}
if (function_exists("curl_init")) {
if (function_exists("curl_init")) {
if (!isset($mimeType)) {
$pid = variable_get('fedora_default_display_pid', 'demo:10');
$dsID = variable_get('fedora_default_display_dsid', 'TN');
@ -137,10 +137,10 @@ class ObjectHelper {
fclose($fp);
} else {
header("Content-type: $mimeType");
if ($contentSize > 0) {
header("Content-length: $contentSize");
}
header("Content-type: $mimeType");
if ($contentSize > 0) {
header("Content-length: $contentSize");
}
if ($asAttachment) {
$suggestedFileName = "$label";
@ -166,11 +166,11 @@ class ObjectHelper {
header('Content-Disposition: attachment; filename="' . $suggestedFileName . '"');
}
if ( (isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) {
curl_exec($ch);
} else {
header('Location: '.$url);
}
if ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) {
curl_exec($ch);
} else {
header('Location: ' . $url);
}
}
curl_close($ch);
} else {
@ -258,14 +258,14 @@ class ObjectHelper {
$item = new Fedora_Item($pid);
if (user_access(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS)) {
$allow=TRUE;
$allow = TRUE;
if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($pid,'write');
$allow = fedora_fesl_check_roles($pid, 'write');
}
if ($allow) {
$purgeImage = '<a title="purge datastream ' . $dataStreamValue->label . '" href="' . $base_url . '/fedora/repository/purgeStream/' .
$pid . '/' . $dataStreamValue->ID . '/' . $dataStreamValue->label . '"><img src="' . $base_url . '/' . $path .
'/images/purge.gif" alt="purge datastream" /></a>';
$purgeImage = '<a title="purge datastream ' . $dataStreamValue->label . '" href="' . $base_url . '/fedora/repository/purgeStream/' .
$pid . '/' . $dataStreamValue->ID . '/' . $dataStreamValue->label . '"><img src="' . $base_url . '/' . $path .
'/images/purge.gif" alt="purge datastream" /></a>';
}
} else {
$purgeImage = '&nbsp;';
@ -274,14 +274,14 @@ class ObjectHelper {
// Add an icon to replace a datastream
// @TODO Note: using l(theme_image(..), ...); for these image links (and other links) may remove the need to have clean urls enabled.
$replaceImage= '&nbsp;';
$replaceImage = '&nbsp;';
if (user_access(ObjectHelper :: $ADD_FEDORA_STREAMS)) {
$allow=TRUE;
$allow = TRUE;
if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($pid,'write');
$allow = fedora_fesl_check_roles($pid, 'write');
}
if ($allow) {
$replaceImage = '<a title="' . t("Replace datastream") . " " . $dataStreamValue->label . '" href="' . $base_url . '/fedora/repository/replaceStream/' . $pid . '/' . $dataStreamValue->ID . '/' . $dataStreamValue->label . '"><img src="' . $base_url . '/' . $path . '/images/replace.png" alt="replace datastream" /></a>';
$replaceImage = '<a title="' . t("Replace datastream") . " " . $dataStreamValue->label . '" href="' . $base_url . '/fedora/repository/replaceStream/' . $pid . '/' . $dataStreamValue->ID . '/' . $dataStreamValue->label . '"><img src="' . $base_url . '/' . $path . '/images/replace.png" alt="replace datastream" /></a>';
}
}
@ -292,7 +292,7 @@ class ObjectHelper {
$mimeType = $dataStreamValue->MIMEType;
$view = '<a href="' . $base_url . '/fedora/repository/' . drupal_urlencode($pid) . '/' . $id . '/' . drupal_urlencode($label) .
'" target="_blank" >' . t('View') . '</a>';
'" target="_blank" >' . t('View') . '</a>';
$action = "$base_url/fedora/repository/object_download/" . drupal_urlencode($pid) . '/' . $id . '/' . drupal_urlencode(preg_replace('/\//i', '${1}_', $label)); // Necessary to handle the case of Datastream labels that contain slashes. Ugh.
$downloadVersion = '<form method="GET" action="' . $action . '"><input type="submit" value="' . t('Download') . '"></form>';
if (user_access(ObjectHelper :: $EDIT_FEDORA_METADATA)) {
@ -331,25 +331,25 @@ class ObjectHelper {
$dsId = 'QDC';
$params = array(
'pid' => "$pid",
'dsID' => "$dsId",
'asOfDateTime' => ""
'pid' => "$pid",
'dsID' => "$dsId",
'asOfDateTime' => ""
);
try {
$object = $client->__soapCAll('getDatastreamDissemination', array(
'parameters' => $params
));
'parameters' => $params
));
} catch (Exception $e) {
try { //probably no QDC so we will try for the DC stream.
$dsId = 'DC';
$params = array(
'pid' => "$pid",
'dsID' => "$dsId",
'asOfDateTime' => ""
'pid' => "$pid",
'dsID' => "$dsId",
'asOfDateTime' => ""
);
$object = $client->__soapCAll('getDatastreamDissemination', array(
'parameters' => $params
));
'parameters' => $params
));
} catch (exception $e2) {
drupal_set_message($e2->getMessage(), 'error');
return;
@ -380,13 +380,13 @@ class ObjectHelper {
$baseUrl = base_path();
//$baseUrl=substr($baseUrl, 0, (strpos($baseUrl, "/")-1));
if (user_access(ObjectHelper :: $EDIT_FEDORA_METADATA)) {
$allow=TRUE;
$allow = TRUE;
if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($pid,'write');
$allow = fedora_fesl_check_roles($pid, 'write');
}
if ($allow) {
$output .= '<br /><a title = "' . t('Edit Meta Data') . '" href="' . $base_url . '/fedora/repository/' . 'editmetadata/' . $pid . '/' .
$dsId . '"><img src="' . $base_url . '/' . $path . '/images/edit.gif" alt="' . t('Edit Meta Data') . '" /></a>';
$output .= '<br /><a title = "' . t('Edit Meta Data') . '" href="' . $base_url . '/fedora/repository/' . 'editmetadata/' . $pid . '/' .
$dsId . '"><img src="' . $base_url . '/' . $path . '/images/edit.gif" alt="' . t('Edit Meta Data') . '" /></a>';
}
}
return $output;
@ -431,7 +431,7 @@ class ObjectHelper {
$cmDatastreams = array();
if (variable_get('fedora_object_restrict_datastreams', FALSE) == TRUE && ($cm = ContentModel::loadFromObject($object_pid)) !== FALSE) {
$cmDatastreams = $cm->listDatastreams();
$cmDatastreams = $cm->listDatastreams();
}
$dataStreamBody .= $this->get_parent_objects_asHTML($object_pid);
@ -439,36 +439,36 @@ class ObjectHelper {
foreach ($object as $datastream) {
foreach ($datastream as $datastreamValue) {
if (variable_get('fedora_object_restrict_datastreams', FALSE) == FALSE || ((isset($user) && in_array('administrator',$user->roles)) || in_array($datastreamValue->ID,$cmDatastreams))) {
if ($datastreamValue->ID == 'OBJ') {
$hasOBJStream = '1';
$mainStreamLabel = $datastreamValue->label;
$mainStreamLabel = str_replace("_", " ", $mainStreamLabel);
}
if ($datastreamValue->ID == 'TN') {
$hasTNStream = TRUE;
}
//create the links to each datastream
$dataStreamBody .= $this->create_link_for_ds($object_pid, $datastreamValue); //"<tr><td><b>$key :</b></td><td>$value</td></tr>\n";
}
if (variable_get('fedora_object_restrict_datastreams', FALSE) == FALSE || ((isset($user) && in_array('administrator', $user->roles)) || in_array($datastreamValue->ID, $cmDatastreams))) {
if ($datastreamValue->ID == 'OBJ') {
$hasOBJStream = '1';
$mainStreamLabel = $datastreamValue->label;
$mainStreamLabel = str_replace("_", " ", $mainStreamLabel);
}
if ($datastreamValue->ID == 'TN') {
$hasTNStream = TRUE;
}
//create the links to each datastream
$dataStreamBody .= $this->create_link_for_ds($object_pid, $datastreamValue); //"<tr><td><b>$key :</b></td><td>$value</td></tr>\n";
}
}
}
$dataStreamBody .= "</table>\n";
//if they have access let them add a datastream
if (user_access(ObjectHelper :: $ADD_FEDORA_STREAMS)) {
$allow=TRUE;
if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($object_pid,'write');
}
if ($allow) {
$dataStreamBody .= drupal_get_form('add_stream_form', $object_pid);
}
$allow = TRUE;
if (module_exists('fedora_fesl')) {
$allow = fedora_fesl_check_roles($object_pid, 'write');
}
if ($allow) {
$dataStreamBody .= drupal_get_form('add_stream_form', $object_pid);
}
}
$fieldset = array(
'#title' => t("!text", array('!text' => $availableDataStreamsText)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => $dataStreamBody
'#title' => t("!text", array('!text' => $availableDataStreamsText)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => $dataStreamBody
);
$dataStreamBody = '<div class = "fedora_detailed_list">' . theme('fieldset', $fieldset) . '</div>';
}
@ -493,15 +493,15 @@ class ObjectHelper {
$content .= $dataStreamBody;
if (user_access(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS)) {
$allow=TRUE;
if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($object_pid,'write');
}
if ($allow) {
//$purgeObject = '<a title="' . t('Purge Object ') . $object_pid . '" href="' . base_path() . 'fedora/repository/purgeObject/' .
//$object_pid . '"><img src="' . $base_url . '/' . $path . '/images/purge_big.png" alt="' . t('Purge Object') . '" class="icon">' . t('Purge Object') . '</a>';
$purgeObject = drupal_get_form('fedora_repository_purge_object_form', $object_pid, check_plain(substr(request_uri(), strlen(base_path()))));
}
$allow = TRUE;
if (module_exists('fedora_fesl')) {
$allow = fedora_fesl_check_roles($object_pid, 'write');
}
if ($allow) {
//$purgeObject = '<a title="' . t('Purge Object ') . $object_pid . '" href="' . base_path() . 'fedora/repository/purgeObject/' .
//$object_pid . '"><img src="' . $base_url . '/' . $path . '/images/purge_big.png" alt="' . t('Purge Object') . '" class="icon">' . t('Purge Object') . '</a>';
$purgeObject = drupal_get_form('fedora_repository_purge_object_form', $object_pid, check_plain(substr(request_uri(), strlen(base_path()))));
}
} else {
$purgeObject = '&nbsp;';
}
@ -540,9 +540,9 @@ class ObjectHelper {
try {
$client = $soapHelper->getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'));
$params = array(
'pid' => "$pid",
'dsID' => "$dsid",
'asOfDateTime' => ""
'pid' => "$pid",
'dsID' => "$dsid",
'asOfDateTime' => ""
);
if (!isset($client)) {
@ -602,20 +602,21 @@ class ObjectHelper {
/*
* determines whether we can see the object or not
* checks PID namespace permissions, and user permissions
*/
function fedora_repository_access($op, $pid) {
global $user;
$returnValue = FALSE;
$isRestricted = variable_get('fedora_namespace_restriction_enforced',TRUE);
if(!$isRestricted){
return TRUE;
$isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
if (!$isRestricted) {
$returnValue = TRUE;
}
if ($pid == NULL) {
$pid = variable_get('fedora_repository_pid', 'islandora:top');
}
$nameSpaceAllowed = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: '));
$nameSpaceAllowed = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: '));
$pos = NULL;
foreach ($nameSpaceAllowed as $nameSpace) {
$pos = stripos($pid, $nameSpace);
@ -729,19 +730,18 @@ class ObjectHelper {
$collectionPolicyExists = $objectHelper->getMimeType($pid, CollectionPolicy::getDefaultDSID());
if (user_access(ObjectHelper :: $INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) {
if (!empty($collectionPolicyExists)) {
$allow=TRUE;
if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($pid,'write');
}
if ($allow) {
// $ingestObject = '<a title="'. t('Ingest a New object into ') . $collectionName . ' '. $collection_pid . '" href="'. base_path() .
$ingestObject = '<a title="' . t('Ingest a New object into !collection_name PID !collection_pid', array('!collection_name' => $collectionName, '!collection_pid' => $collection_pid)) . '" href="' . base_path() .
'fedora/ingestObject/' . $collection_pid . '/' . $collectionName . '"><img src="' . $base_url . '/' . $path .
'/images/ingest.png" alt="' . t('Add a New Object') . '" class="icon"></a>' . t(' Add to this Collection');
}
}
}
else {
$allow = TRUE;
if (module_exists('fedora_fesl')) {
$allow = fedora_fesl_check_roles($pid, 'write');
}
if ($allow) {
// $ingestObject = '<a title="'. t('Ingest a New object into ') . $collectionName . ' '. $collection_pid . '" href="'. base_path() .
$ingestObject = '<a title="' . t('Ingest a New object into !collection_name PID !collection_pid', array('!collection_name' => $collectionName, '!collection_pid' => $collection_pid)) . '" href="' . base_path() .
'fedora/ingestObject/' . $collection_pid . '/' . $collectionName . '"><img src="' . $base_url . '/' . $path .
'/images/ingest.png" alt="' . t('Add a New Object') . '" class="icon"></a>' . t(' Add to this Collection');
}
}
} else {
$ingestObject = '&nbsp;';
}
@ -751,20 +751,20 @@ class ObjectHelper {
$objectListOut = '';
if (isset($objectList)) {
$object_list_fieldset = array(
'#title' => t('Items in this collection'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#value' => (isset($objectList) ? $objectList : ''), //collection list
'#title' => t('Items in this collection'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#value' => (isset($objectList) ? $objectList : ''), //collection list
);
$objectListOut = theme('fieldset', $object_list_fieldset);
}
} else {
//$collectionName='';
$collection_fieldset = array(
'#title' => "",
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#value' => $datastreams,
'#title' => "",
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#value' => $datastreams,
);
$objectListOut = ''; //no collection objects to show so don't show field set
}
@ -805,10 +805,10 @@ class ObjectHelper {
$metaDataText = t('Description');
$body = $this->getQDC($pid);
$fieldset = array(
'#title' => t("!metaDataText", array('!metaDataText' => $metaDataText)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => $body
'#title' => t("!metaDataText", array('!metaDataText' => $metaDataText)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => $body
);
$output .= theme('fieldset', $fieldset);
}
@ -949,10 +949,10 @@ class ObjectHelper {
// Get pid, title and description for children of object $pid
$query_string = 'select $o $title from <#ri> ' .
// $query_string = 'select $o $title $desc from <#ri> '.
'where $s <info:fedora/fedora-system:def/relations-external#hasMember> $o ' .
'and $o <dc:title> $title ' .
'where $s <info:fedora/fedora-system:def/relations-external#hasMember> $o ' .
'and $o <dc:title> $title ' .
// 'and $o <dc:description> $desc '.
'and ( ';
'and ( ';
foreach ($pids as $pid) {
$query_string .= '$s <mulgara:is> <info:fedora/' . $pid . '> or ';
@ -1017,11 +1017,11 @@ class ObjectHelper {
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= "?type=tuples&flush=TRUE&format=CSV&limit=1&offset=0&lang=itql&stream=on&query=" . $query_string;
$result = preg_split('/[\r\n]+/',do_curl($url));
array_shift($result); // throw away first line
$matches =str_getcsv(join("\n",$result));
$result = preg_split('/[\r\n]+/', do_curl($url));
array_shift($result); // throw away first line
$matches = str_getcsv(join("\n", $result));
if ($matches !== NULL) {
$parent = preg_replace('/^info:fedora\//','',$matches[0]);
$parent = preg_replace('/^info:fedora\//', '', $matches[0]);
$breadcrumbs[] = l($matches[1], 'fedora/repository/' . $pid);
if ($parent == variable_get('fedora_repository_pid', 'islandora:top')) {
$breadcrumbs[] = l(t('Home'), ''); // l(t('Digital repository'), 'fedora/repository');
@ -1033,9 +1033,9 @@ class ObjectHelper {
function warnIfMisconfigured($app) {
$messMap = array(
'Kakadu' => 'Full installation instructions for Kakadu can be found
'Kakadu' => 'Full installation instructions for Kakadu can be found
<a href=http://www.kakadusoftware.com/index.php?option=com_content&task=view&id=27&Itemid=23>Here</a>',
'ImageMagick' => 'Check the path settings in the configuration of your <b>imageapi</b> module.<br/>
'ImageMagick' => 'Check the path settings in the configuration of your <b>imageapi</b> module.<br/>
Further details can be found <a href=http://www.imagemagick.org/script/install-source.php>Here</a>',
);

Loading…
Cancel
Save