Browse Source

Ensured that both namespace user permissions are checked

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

60
ObjectHelper.inc

@ -41,7 +41,7 @@ class ObjectHelper {
*/ */
function makeObject($pid, $dsID, $asAttachment = FALSE, $label = NULL, $filePath=FALSE, $version=NULL, $forceSoap = FALSE) { function makeObject($pid, $dsID, $asAttachment = FALSE, $label = NULL, $filePath=FALSE, $version=NULL, $forceSoap = FALSE) {
global $user; global $user;
module_load_include('inc','fedora_repository','ContentModel'); module_load_include('inc', 'fedora_repository', 'ContentModel');
if ($pid == NULL || $dsID == NULL) { if ($pid == NULL || $dsID == NULL) {
drupal_set_message(t("no pid or dsid given to create an object with"), 'error'); drupal_set_message(t("no pid or dsid given to create an object with"), 'error');
return ' '; return ' ';
@ -61,7 +61,7 @@ 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) { if (($cm = ContentModel::loadFromObject($pid)) == FALSE) {
drupal_set_message(t("You do not have access to objects without an Islandora Content Model."), 'error'); drupal_set_message(t("You do not have access to objects without an Islandora Content Model."), 'error');
drupal_access_denied(); drupal_access_denied();
@ -69,7 +69,7 @@ class ObjectHelper {
} }
$cmDatastreams = $cm->listDatastreams(); $cmDatastreams = $cm->listDatastreams();
if ( !((isset($user) && in_array('administrator',$user->roles)) || in_array($dsID,$cmDatastreams))) { 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_set_message(t("You do not have access to the specified datastream."), 'error');
drupal_access_denied(); drupal_access_denied();
return ' '; return ' ';
@ -81,7 +81,7 @@ class ObjectHelper {
if (isset($item->datastreams[$dsID])) { if (isset($item->datastreams[$dsID])) {
$mimeType=$item->datastreams[$dsID]['MIMEType']; $mimeType = $item->datastreams[$dsID]['MIMEType'];
if ($label == NULL) { if ($label == NULL) {
$label = $item->datastreams[$dsID]['label']; $label = $item->datastreams[$dsID]['label'];
} }
@ -94,7 +94,7 @@ class ObjectHelper {
if ((!isset($user)) || $user->uid == 0) { if ((!isset($user)) || $user->uid == 0) {
$fedoraUser = 'anonymous'; $fedoraUser = 'anonymous';
$fedoraPass = 'anonymous'; $fedoraPass = 'anonymous';
$contentSize= 0; $contentSize = 0;
} else { } else {
$fedoraUser = $user->name; $fedoraUser = $user->name;
$fedoraPass = $user->pass; $fedoraPass = $user->pass;
@ -166,10 +166,10 @@ class ObjectHelper {
header('Content-Disposition: attachment; filename="' . $suggestedFileName . '"'); header('Content-Disposition: attachment; filename="' . $suggestedFileName . '"');
} }
if ( (isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) { if ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) {
curl_exec($ch); curl_exec($ch);
} else { } else {
header('Location: '.$url); header('Location: ' . $url);
} }
} }
curl_close($ch); curl_close($ch);
@ -258,9 +258,9 @@ class ObjectHelper {
$item = new Fedora_Item($pid); $item = new Fedora_Item($pid);
if (user_access(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS)) { if (user_access(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS)) {
$allow=TRUE; $allow = TRUE;
if (module_exists('fedora_fesl')) { if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($pid,'write'); $allow = fedora_fesl_check_roles($pid, 'write');
} }
if ($allow) { if ($allow) {
$purgeImage = '<a title="purge datastream ' . $dataStreamValue->label . '" href="' . $base_url . '/fedora/repository/purgeStream/' . $purgeImage = '<a title="purge datastream ' . $dataStreamValue->label . '" href="' . $base_url . '/fedora/repository/purgeStream/' .
@ -274,11 +274,11 @@ class ObjectHelper {
// Add an icon to replace a datastream // 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. // @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)) { if (user_access(ObjectHelper :: $ADD_FEDORA_STREAMS)) {
$allow=TRUE; $allow = TRUE;
if (module_exists('fedora_fesl')) { if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($pid,'write'); $allow = fedora_fesl_check_roles($pid, 'write');
} }
if ($allow) { 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>';
@ -380,9 +380,9 @@ class ObjectHelper {
$baseUrl = base_path(); $baseUrl = base_path();
//$baseUrl=substr($baseUrl, 0, (strpos($baseUrl, "/")-1)); //$baseUrl=substr($baseUrl, 0, (strpos($baseUrl, "/")-1));
if (user_access(ObjectHelper :: $EDIT_FEDORA_METADATA)) { if (user_access(ObjectHelper :: $EDIT_FEDORA_METADATA)) {
$allow=TRUE; $allow = TRUE;
if (module_exists('fedora_fesl')) { if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($pid,'write'); $allow = fedora_fesl_check_roles($pid, 'write');
} }
if ($allow) { if ($allow) {
$output .= '<br /><a title = "' . t('Edit Meta Data') . '" href="' . $base_url . '/fedora/repository/' . 'editmetadata/' . $pid . '/' . $output .= '<br /><a title = "' . t('Edit Meta Data') . '" href="' . $base_url . '/fedora/repository/' . 'editmetadata/' . $pid . '/' .
@ -439,7 +439,7 @@ class ObjectHelper {
foreach ($object as $datastream) { foreach ($object as $datastream) {
foreach ($datastream as $datastreamValue) { 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 (variable_get('fedora_object_restrict_datastreams', FALSE) == FALSE || ((isset($user) && in_array('administrator', $user->roles)) || in_array($datastreamValue->ID, $cmDatastreams))) {
if ($datastreamValue->ID == 'OBJ') { if ($datastreamValue->ID == 'OBJ') {
$hasOBJStream = '1'; $hasOBJStream = '1';
$mainStreamLabel = $datastreamValue->label; $mainStreamLabel = $datastreamValue->label;
@ -456,9 +456,9 @@ class ObjectHelper {
$dataStreamBody .= "</table>\n"; $dataStreamBody .= "</table>\n";
//if they have access let them add a datastream //if they have access let them add a datastream
if (user_access(ObjectHelper :: $ADD_FEDORA_STREAMS)) { if (user_access(ObjectHelper :: $ADD_FEDORA_STREAMS)) {
$allow=TRUE; $allow = TRUE;
if (module_exists('fedora_fesl')) { if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($object_pid,'write'); $allow = fedora_fesl_check_roles($object_pid, 'write');
} }
if ($allow) { if ($allow) {
$dataStreamBody .= drupal_get_form('add_stream_form', $object_pid); $dataStreamBody .= drupal_get_form('add_stream_form', $object_pid);
@ -493,9 +493,9 @@ class ObjectHelper {
$content .= $dataStreamBody; $content .= $dataStreamBody;
if (user_access(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS)) { if (user_access(ObjectHelper :: $PURGE_FEDORA_OBJECTSANDSTREAMS)) {
$allow=TRUE; $allow = TRUE;
if (module_exists('fedora_fesl')) { if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($object_pid,'write'); $allow = fedora_fesl_check_roles($object_pid, 'write');
} }
if ($allow) { if ($allow) {
//$purgeObject = '<a title="' . t('Purge Object ') . $object_pid . '" href="' . base_path() . 'fedora/repository/purgeObject/' . //$purgeObject = '<a title="' . t('Purge Object ') . $object_pid . '" href="' . base_path() . 'fedora/repository/purgeObject/' .
@ -602,20 +602,21 @@ class ObjectHelper {
/* /*
* determines whether we can see the object or not * determines whether we can see the object or not
* checks PID namespace permissions, and user permissions
*/ */
function fedora_repository_access($op, $pid) { function fedora_repository_access($op, $pid) {
global $user; global $user;
$returnValue = FALSE; $returnValue = FALSE;
$isRestricted = variable_get('fedora_namespace_restriction_enforced',TRUE); $isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
if(!$isRestricted){ if (!$isRestricted) {
return TRUE; $returnValue = TRUE;
} }
if ($pid == NULL) { if ($pid == NULL) {
$pid = variable_get('fedora_repository_pid', 'islandora:top'); $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; $pos = NULL;
foreach ($nameSpaceAllowed as $nameSpace) { foreach ($nameSpaceAllowed as $nameSpace) {
$pos = stripos($pid, $nameSpace); $pos = stripos($pid, $nameSpace);
@ -729,9 +730,9 @@ class ObjectHelper {
$collectionPolicyExists = $objectHelper->getMimeType($pid, CollectionPolicy::getDefaultDSID()); $collectionPolicyExists = $objectHelper->getMimeType($pid, CollectionPolicy::getDefaultDSID());
if (user_access(ObjectHelper :: $INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) { if (user_access(ObjectHelper :: $INGEST_FEDORA_OBJECTS) && $collectionPolicyExists) {
if (!empty($collectionPolicyExists)) { if (!empty($collectionPolicyExists)) {
$allow=TRUE; $allow = TRUE;
if (module_exists('fedora_fesl')) { if (module_exists('fedora_fesl')) {
$allow= fedora_fesl_check_roles($pid,'write'); $allow = fedora_fesl_check_roles($pid, 'write');
} }
if ($allow) { 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 ') . $collectionName . ' '. $collection_pid . '" href="'. base_path() .
@ -740,8 +741,7 @@ class ObjectHelper {
'/images/ingest.png" alt="' . t('Add a New Object') . '" class="icon"></a>' . t(' Add to this Collection'); '/images/ingest.png" alt="' . t('Add a New Object') . '" class="icon"></a>' . t(' Add to this Collection');
} }
} }
} } else {
else {
$ingestObject = '&nbsp;'; $ingestObject = '&nbsp;';
} }
@ -1017,11 +1017,11 @@ class ObjectHelper {
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); $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; $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)); $result = preg_split('/[\r\n]+/', do_curl($url));
array_shift($result); // throw away first line array_shift($result); // throw away first line
$matches =str_getcsv(join("\n",$result)); $matches = str_getcsv(join("\n", $result));
if ($matches !== NULL) { if ($matches !== NULL) {
$parent = preg_replace('/^info:fedora\//','',$matches[0]); $parent = preg_replace('/^info:fedora\//', '', $matches[0]);
$breadcrumbs[] = l($matches[1], 'fedora/repository/' . $pid); $breadcrumbs[] = l($matches[1], 'fedora/repository/' . $pid);
if ($parent == variable_get('fedora_repository_pid', 'islandora:top')) { if ($parent == variable_get('fedora_repository_pid', 'islandora:top')) {
$breadcrumbs[] = l(t('Home'), ''); // l(t('Digital repository'), 'fedora/repository'); $breadcrumbs[] = l(t('Home'), ''); // l(t('Digital repository'), 'fedora/repository');

Loading…
Cancel
Save