Browse Source

added deleted object management

pull/386/head
Alan Stanley 12 years ago
parent
commit
ef695c5224
  1. 6
      includes/authtokens.inc
  2. 105
      includes/derivatives.inc
  3. 2
      includes/object_properties.form.inc
  4. 4
      includes/utilities.inc
  5. 112
      islandora.api.php
  6. 14
      islandora.drush.inc
  7. 1
      islandora.info
  8. 136
      islandora.module
  9. 8
      js/add_print.js
  10. 2
      tests/authtokens.test
  11. 296
      tests/derivatives.test
  12. 6
      tests/hooked_access.test
  13. 7
      tests/islandora_derivatives_test.info
  14. 202
      tests/islandora_derivatives_test.module
  15. 2
      tests/islandora_hooked_access_test.module
  16. 50
      tests/islandora_manage_permissions.test
  17. 18
      theme/theme.inc

6
includes/authtokens.inc

@ -10,7 +10,7 @@
// Token lifespan(seconds): after this duration the token expires.
// 5 minutes.
define('TOKEN_TIMEOUT', 300);
define('ISLANDORA_AUTHTOKEN_TOKEN_TIMEOUT', 300);
/**
* Request Islandora to construct an object/datastream authentication token.
@ -92,7 +92,7 @@ function islandora_validate_object_token($pid, $dsid, $token) {
->condition('pid', $pid, '=')
->condition('dsid', $dsid, '=')
->condition('time', $time, '<=')
->condition('time', $time - TOKEN_TIMEOUT, '>')
->condition('time', $time - ISLANDORA_AUTHTOKEN_TOKEN_TIMEOUT, '>')
->execute()
->fetchAll();
if ($result) {
@ -131,6 +131,6 @@ function islandora_validate_object_token($pid, $dsid, $token) {
function islandora_remove_expired_tokens() {
$time = time();
db_delete("islandora_authtokens")
->condition('time', $time - TOKEN_TIMEOUT, '<')
->condition('time', $time - ISLANDORA_AUTHTOKEN_TOKEN_TIMEOUT, '<')
->execute();
}

105
includes/derivatives.inc

@ -0,0 +1,105 @@
<?php
/**
* @file
* Defines functions used when constructing derivatives.
*/
/**
* Kicks off derivative functions based upon hooks and conditions.
*
* @param AbstractObject $object
* An AbstractObject representing a FedoraObject.
* @param array $options
* An array of parameters containing:
* - force: Bool denoting whether we are forcing the generation of
* derivatives.
* - source_dsid: (Optional) String of the datastream id we are generating
* from or NULL if it's the object itself.
* - destination_dsid: (Optional) String of the datastream id that is being
* created. To be used in the UI.
*
* @return array
* An array of messages describing the outcome of the derivative events.
* Each individual message array has the following structure:
* - success: Bool denoting whether the operation was successful.
* - messages: An array structure containing:
* - message: A string passed through t() describing the
* outcome of the operation.
* - message_sub: (Optional) Substitutions to be passed along to t() or
* watchdog.
* - type: A string denoting whether the output is to be
* drupal_set_messaged (dsm) or watchdogged (watchdog).
* - severity: (Optional) A severity level / status to be used when
* logging messages. Uses the defaults of drupal_set_message and
* watchdog if not defined.
*/
function islandora_do_derivatives(AbstractObject $object, array $options) {
$options += array(
'force' => FALSE,
);
$hooks = islandora_invoke_hook_list(ISLANDORA_DERVIATIVE_CREATION_HOOK, $object->models, array());
uasort($hooks, 'drupal_sort_weight');
$results = array();
if (array_key_exists('source_dsid', $options)) {
$hooks = array_filter($hooks, function($filter_hook) use($options) {
return array_key_exists('source_dsid', $filter_hook) &&
$filter_hook['source_dsid'] == $options['source_dsid'];
});
}
if (array_key_exists('destination_dsid', $options)) {
$hooks = array_filter($hooks, function($filter_hook) use($options) {
return array_key_exists('destination_dsid', $filter_hook) &&
$filter_hook['destination_dsid'] == $options['destination_dsid'];
});
}
foreach ($hooks as $hook) {
if (isset($hook['file'])) {
require_once $hook['file'];
}
foreach ($hook['function'] as $function) {
$logging = call_user_func($function, $object, $options['force']);
if (!empty($logging)) {
$results[] = $logging;
}
}
}
return $results;
}
/**
* Handles the logging of derivative messages.
*
* @param array $logging_results
* An array of messages describing the outcome of the derivative events.
* Each individual message array has the following structure:
* - success: Bool denoting whether the operation was successful.
* - messages: An array structure containing:
* - message: A string passed through t() describing the
* outcome of the operation.
* - message_sub: (Optional) Substitutions to be passed along to t() or
* watchdog.
* - type: A string denoting whether the output is to be
* drupal_set_messaged (dsm) or watchdogged (watchdog).
* - severity: (Optional) A severity level / status to be used when
* logging messages. Uses the defaults of drupal_set_message and
* watchdog if not defined.
*/
function islandora_derivative_logging(array $logging_results) {
foreach ($logging_results as $result) {
foreach ($result['messages'] as $message) {
if ($message['type'] === 'dsm') {
drupal_set_message(filter_xss(format_string($message['message'], isset($message['message_sub']) ? $message['message_sub'] : array())), isset($message['severity']) ? $message['severity'] : 'status');
}
else {
// We know what we are doing here. Passing through the translated
// message and the substitutions needed. We are using
// call_user_func until such time as the @ignore changes
// are merged into the standard release for Coder.
call_user_func('watchdog', $message['message'], isset($message['message_sub']) ? $message['message_sub'] : array(), isset($message['severity']) ? $message['severity'] : WATCHDOG_NOTICE);
}
}
}
}

2
includes/object_properties.form.inc

@ -80,7 +80,7 @@ function islandora_object_properties_form(array $form, array &$form_state, Abstr
),
'delete' => array(
'#type' => 'submit',
'#access' => islandora_object_access(FEDORA_PURGE, $object),
'#access' => islandora_object_access(ISLANDORA_PURGE, $object),
'#value' => t('Delete'),
'#submit' => array('islandora_object_properties_form_delete'),
'#limit_validation_errors' => array(array('pid')),

4
includes/utilities.inc

@ -391,10 +391,10 @@ function islandora_get_datastreams_requirements_from_models(array $models) {
* - "optional": A boolean indicating if the given stream is optional.
*/
function islandora_get_datastreams_requirements_from_content_model(AbstractObject $object) {
if (empty($object[DS_COMP_STREAM]) || !islandora_datastream_access(FEDORA_VIEW_OBJECTS, $object[DS_COMP_STREAM])) {
if (empty($object[ISLANDORA_DS_COMP_STREAM]) || !islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $object[ISLANDORA_DS_COMP_STREAM])) {
return array();
}
$xml = new SimpleXMLElement($object[DS_COMP_STREAM]->content);
$xml = new SimpleXMLElement($object[ISLANDORA_DS_COMP_STREAM]->content);
foreach ($xml->dsTypeModel as $ds) {
$dsid = (string) $ds['ID'];
$optional = strtolower((string) $ds['optional']);

112
islandora.api.php

@ -543,13 +543,115 @@ function hook_CMODEL_PID_islandora_datastream_access($op, $object, $user) {
}
/**
* Content model specific function to update related objects.
* Lets one add to the overview tab in object management.
*/
function hook_islandora_overview_object(AbstractObject $object) {
return drupal_render(drupal_get_form('some_form', $object));
}
/**
* Lets one add to the overview tab in object management.
*
* @param FedoraObject $object
* FedoraObject representing original object.
* Content model specific.
*/
function hook_CMODEL_PID_islandora_overview_object(AbstractObject $object) {
return drupal_render(drupal_get_form('some_form', $object));
}
/**
* Lets one alter the overview tab in object management.
*/
function hook_islandora_overview_object_alter(AbstractObject &$object, &$output) {
$output = $output . drupal_render(drupal_get_form('some_form', $object));
}
/**
* Lets one alter the overview tab in object management.
*
* Content model specific.
*/
function hook_CMODEL_PID_islandora_overview_object_alter(AbstractObject &$object, &$output) {
$output = $output . drupal_render(drupal_get_form('some_form', $object));
}
/*
* Defines derivative functions to be executed based on certain conditions.
*
* This hook fires when an object/datastream is ingested or a datastream is
* modified.
*
* @return array
* Array of pids representing objects associated with original object.
* An array containing an entry for each derivative to be created. Each entry
* is an array of parameters containing:
* - force: Bool denoting whether we are forcing the generation of
* derivatives.
* - source_dsid: (Optional) String of the datastream id we are generating
* from or NULL if it's the object itself.
* - destination_dsid: (Optional) String of the datastream id that is being
* created. To be used in the UI.
* - weight: A string denoting the weight of the function. This value is
* sorted upon to run functions in order.
* - function: An array of function(s) to be ran when constructing
* derivatives. Functions that are defined to be called for derivation
* creation must have the following structure:
* module_name_derivative_creation_function($object, $force = FALSE)
* These functions must return an array in the structure of:
* - success: Bool denoting whether the operation was successful.
* - messages: An array structure containing:
* - message: A string passed through t() describing the
* outcome of the operation.
* - message_sub: (Optional) Substitutions to be passed along to t() or
* watchdog.
* - type: A string denoting whether the output is to be
* drupal_set_messaged (dsm) or watchdogged (watchdog).
* - severity: (Optional) A severity level / status to be used when
* logging messages. Uses the defaults of drupal_set_message and
* watchdog if not defined.
* - file: A string denoting the path to the file where the function
* is being called from.
*/
function hook_islandora_derivative() {
return array(
array(
'source_dsid' => 'OBJ',
'destination_dsid' => 'DERIV',
'weight' => '0',
'function' => array(
'islandora_derivatives_test_create_deriv_datastream',
),
),
array(
'source_dsid' => 'SOMEWEIRDDATASTREAM',
'destination_dsid' => 'STANLEY',
'weight' => '-1',
'function' => array(
'islandora_derivatives_test_create_some_weird_datastream',
),
),
array(
'source_dsid' => NULL,
'destination_dsid' => 'NOSOURCE',
'weight' => '-3',
'function' => array(
'islandora_derivatives_test_create_nosource_datastream',
),
),
);
}
/**
* Content model specific version of hook_islandora_derivative().
*
* @see hook_islandora_derivative()
*/
function islandora_book_islandora_bookCModel_islandora_update_related_objects($object) {
function hook_CMODEL_PID_islandora_derivative() {
}
/**
* Retrieves PIDS of related objects for property updating.
*
* @param string $pid
*/
function islandora_update_related_objects_properties($pid){
}

14
islandora.drush.inc

@ -26,6 +26,10 @@ function islandora_drush_command() {
'drupal dependencies' => array(
'islandora',
),
'examples' => array(
'drush -u 1 ispiro --module=islandora' => dt('Install missing solution pack objects for the "islandora" module.'),
'drush -u 1 ispiro --module=islandora --force' => dt('Install all solution pack objects for the "islandora" module, purging any which currently exist.'),
),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_LOGIN,
);
$commands['islandora-solution-pack-uninstall-required-objects'] = array(
@ -36,13 +40,17 @@ function islandora_drush_command() {
'required' => TRUE,
),
'force' => array(
'description' => dt('Force reinstallation of the objects.'),
'description' => dt('Force uninstallation of the objects.'),
),
),
'aliases' => array('ispuro'),
'drupal dependencies' => array(
'islandora',
),
'examples' => array(
'drush -u 1 ispuro --module=islandora' => dt('Uninstall solution pack objects for the "islandora" module.'),
'drush -u 1 ispuro --module=islandora --force' => dt('Force uninstallation of all solution pack objects for the "islandora" module.'),
),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_LOGIN,
);
$commands['islandora-solution-pack-required-objects-status'] = array(
@ -56,6 +64,10 @@ function islandora_drush_command() {
'drupal dependencies' => array(
'islandora',
),
'examples' => array(
'drush -u 1 ispros' => dt('Get the status of all solution pack objects.'),
'drush -u 1 ispros --module=islandora' => dt('Get the status of solution pack objects for the "islandora" module.'),
),
'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_LOGIN,
);

1
islandora.info

@ -18,4 +18,5 @@ files[] = tests/ingest.test
files[] = tests/hooked_access.test
files[] = tests/islandora_manage_permissions.test
files[] = tests/datastream_versions.test
files[] = tests/derivatives.test
php = 5.3

136
islandora.module

@ -24,15 +24,15 @@
*/
// Common datastreams.
define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL');
define('ISLANDORA_DS_COMP_STREAM', 'DS-COMPOSITE-MODEL');
// Permissions.
define('FEDORA_VIEW_OBJECTS', 'view fedora repository objects');
define('FEDORA_METADATA_EDIT', 'edit fedora metadata');
define('FEDORA_ADD_DS', 'add fedora datastreams');
define('FEDORA_INGEST', 'ingest fedora objects');
define('FEDORA_PURGE', 'delete fedora objects and datastreams');
define('FEDORA_MANAGE_PROPERTIES', 'manage object properties');
define('ISLANDORA_VIEW_OBJECTS', 'view fedora repository objects');
define('ISLANDORA_METADATA_EDIT', 'edit fedora metadata');
define('ISLANDORA_ADD_DS', 'add fedora datastreams');
define('ISLANDORA_INGEST', 'ingest fedora objects');
define('ISLANDORA_PURGE', 'delete fedora objects and datastreams');
define('ISLANDORA_MANAGE_PROPERTIES', 'manage object properties');
define('ISLANDORA_VIEW_DATASTREAM_HISTORY', 'view old datastream versions');
define('ISLANDORA_MANAGE_DELETED_OBJECTS', 'manage deleted objects');
@ -55,10 +55,24 @@ define('ISLANDORA_DATASTREAM_INGESTED_HOOK', 'islandora_datastream_ingested');
define('ISLANDORA_DATASTREAM_MODIFIED_HOOK', 'islandora_datastream_modified');
define('ISLANDORA_DATASTREAM_PURGED_HOOK', 'islandora_datastream_purged');
define('ISLANDORA_INGEST_STEP_HOOK', 'islandora_ingest_steps');
define('ISLANDORA_DERVIATIVE_CREATION_HOOK', 'islandora_derivative');
// Autocomplete paths.
define('ISLANDORA_CONTENT_MODELS_AUTOCOMPLETE', 'islandora/autocomplete/content-models');
/**
* @deprecated Constants.
*/
// @codingStandardsIgnoreStart
define('DS_COMP_STREAM', ISLANDORA_DS_COMP_STREAM);
define('FEDORA_VIEW_OBJECTS', ISLANDORA_VIEW_OBJECTS);
define('FEDORA_METADATA_EDIT', ISLANDORA_METADATA_EDIT);
define('FEDORA_ADD_DS', ISLANDORA_ADD_DS);
define('FEDORA_INGEST', ISLANDORA_INGEST);
define('FEDORA_PURGE', ISLANDORA_PURGE);
define('FEDORA_MANAGE_PROPERTIES', ISLANDORA_MANAGE_PROPERTIES);
// @codingStandardsIgnoreEnd
/**
* Implements hook_menu().
*
@ -87,7 +101,7 @@ function islandora_menu() {
'title' => 'Solution packs',
'description' => 'Install content models and collections required by installed solution packs.',
'page callback' => 'islandora_solution_packs_admin',
'access arguments' => array(FEDORA_ADD_DS),
'access arguments' => array(ISLANDORA_ADD_DS),
'file' => 'includes/solution_packs.inc',
'type' => MENU_NORMAL_ITEM,
);
@ -95,7 +109,7 @@ function islandora_menu() {
'title' => 'Islandora Repository',
'page callback' => 'islandora_view_default_object',
'type' => MENU_NORMAL_ITEM,
'access arguments' => array(FEDORA_VIEW_OBJECTS),
'access arguments' => array(ISLANDORA_VIEW_OBJECTS),
);
$items['islandora/object/%islandora_object'] = array(
'title callback' => 'islandora_drupal_title',
@ -104,14 +118,14 @@ function islandora_menu() {
'page arguments' => array(2),
'type' => MENU_NORMAL_ITEM,
'access callback' => 'islandora_object_access_callback',
'access arguments' => array(FEDORA_VIEW_OBJECTS, 2),
'access arguments' => array(ISLANDORA_VIEW_OBJECTS, 2),
);
$items['islandora/object/%islandora_object/print'] = array(
'page callback' => 'islandora_printer_object',
'page arguments' => array(2),
'type' => MENU_NORMAL_ITEM,
'access callback' => 'islandora_object_access_callback',
'access arguments' => array(FEDORA_VIEW_OBJECTS, 2),
'access arguments' => array(ISLANDORA_VIEW_OBJECTS, 2),
);
$items['islandora/object/%islandora_object/view'] = array(
'title' => 'View',
@ -131,11 +145,11 @@ function islandora_menu() {
'access callback' => 'islandora_object_manage_access_callback',
'access arguments' => array(
array(
FEDORA_MANAGE_PROPERTIES,
FEDORA_METADATA_EDIT,
FEDORA_ADD_DS,
FEDORA_PURGE,
FEDORA_INGEST,
ISLANDORA_MANAGE_PROPERTIES,
ISLANDORA_METADATA_EDIT,
ISLANDORA_ADD_DS,
ISLANDORA_PURGE,
ISLANDORA_INGEST,
), 2),
);
@ -153,9 +167,9 @@ function islandora_menu() {
'access callback' => 'islandora_object_manage_access_callback',
'access arguments' => array(
array(
FEDORA_METADATA_EDIT,
FEDORA_ADD_DS,
FEDORA_PURGE,
ISLANDORA_METADATA_EDIT,
ISLANDORA_ADD_DS,
ISLANDORA_PURGE,
), 2),
'weight' => -10,
);
@ -167,7 +181,7 @@ function islandora_menu() {
'page arguments' => array('islandora_object_properties_form', 2),
'type' => MENU_LOCAL_TASK,
'access callback' => 'islandora_object_access_callback',
'access arguments' => array(FEDORA_MANAGE_PROPERTIES, 2),
'access arguments' => array(ISLANDORA_MANAGE_PROPERTIES, 2),
'weight' => -5,
);
$items['islandora/object/%islandora_object/delete'] = array(
@ -177,7 +191,7 @@ function islandora_menu() {
'page arguments' => array('islandora_delete_object_form', 2),
'type' => MENU_CALLBACK,
'access callback' => 'islandora_object_access_callback',
'access arguments' => array(FEDORA_PURGE, 2),
'access arguments' => array(ISLANDORA_PURGE, 2),
);
$items['islandora/object/%islandora_object/manage/datastreams/add'] = array(
'title' => 'Add a datastream',
@ -186,7 +200,7 @@ function islandora_menu() {
'page arguments' => array('islandora_add_datastream_form', 2),
'type' => MENU_LOCAL_ACTION,
'access callback' => 'islandora_object_access_callback',
'access arguments' => array(FEDORA_ADD_DS, 2),
'access arguments' => array(ISLANDORA_ADD_DS, 2),
);
$items['islandora/object/%islandora_object/manage/datastreams/add/autocomplete'] = array(
'file' => 'includes/add_datastream.form.inc',
@ -194,7 +208,7 @@ function islandora_menu() {
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access callback' => 'islandora_object_access_callback',
'access arguments' => array(FEDORA_ADD_DS, 2),
'access arguments' => array(ISLANDORA_ADD_DS, 2),
);
$items['islandora/object/%islandora_object/datastream/%islandora_datastream'] = array(
'title' => 'View datastream',
@ -203,7 +217,7 @@ function islandora_menu() {
'type' => MENU_CALLBACK,
'file' => 'includes/datastream.inc',
'access callback' => 'islandora_datastream_access',
'access arguments' => array(FEDORA_VIEW_OBJECTS, 4),
'access arguments' => array(ISLANDORA_VIEW_OBJECTS, 4),
'load arguments' => array(2),
);
// This menu item uses token authentication in islandora_tokened_object.
@ -211,7 +225,7 @@ function islandora_menu() {
'title' => 'View datastream',
'load arguments' => array('%map'),
'access callback' => 'islandora_object_datastream_tokened_access_callback',
'access arguments' => array(FEDORA_VIEW_OBJECTS, 2, 4),
'access arguments' => array(ISLANDORA_VIEW_OBJECTS, 2, 4),
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['islandora/object/%islandora_object/datastream/%islandora_datastream/download'] = array(
@ -221,7 +235,7 @@ function islandora_menu() {
'type' => MENU_CALLBACK,
'file' => 'includes/datastream.inc',
'access callback' => 'islandora_datastream_access',
'access arguments' => array(FEDORA_VIEW_OBJECTS, 4),
'access arguments' => array(ISLANDORA_VIEW_OBJECTS, 4),
'load arguments' => array(2),
);
$items['islandora/object/%islandora_object/datastream/%islandora_datastream/edit'] = array(
@ -231,7 +245,7 @@ function islandora_menu() {
'type' => MENU_CALLBACK,
'file' => 'includes/datastream.inc',
'access callback' => 'islandora_datastream_access',
'access arguments' => array(FEDORA_METADATA_EDIT, 4),
'access arguments' => array(ISLANDORA_METADATA_EDIT, 4),
'load arguments' => array(2),
);
$items['islandora/object/%islandora_object/datastream/%islandora_datastream/delete'] = array(
@ -241,7 +255,7 @@ function islandora_menu() {
'file' => 'includes/delete_datastream.form.inc',
'type' => MENU_CALLBACK,
'access callback' => 'islandora_datastream_access',
'access arguments' => array(FEDORA_PURGE, 4),
'access arguments' => array(ISLANDORA_PURGE, 4),
'load arguments' => array(2),
);
$items['islandora/object/%islandora_object/datastream/%islandora_datastream/version'] = array(
@ -261,7 +275,7 @@ function islandora_menu() {
'file' => 'includes/datastream.version.inc',
'type' => MENU_CALLBACK,
'access callback' => 'islandora_datastream_access',
'access arguments' => array(FEDORA_PURGE, 4),
'access arguments' => array(ISLANDORA_PURGE, 4),
'load arguments' => array(2),
);
$items['islandora/object/%islandora_object/datastream/%islandora_datastream/version/%/view'] = array(
@ -279,7 +293,7 @@ function islandora_menu() {
'page arguments' => array(2),
'type' => MENU_CALLBACK,
'access callback' => 'islandora_object_access',
'access arguments' => array(FEDORA_VIEW_OBJECTS, 2),
'access arguments' => array(ISLANDORA_VIEW_OBJECTS, 2),
'load arguments' => array(2),
);
$items[ISLANDORA_CONTENT_MODELS_AUTOCOMPLETE] = array(
@ -401,27 +415,27 @@ function islandora_theme() {
*/
function islandora_permission() {
return array(
FEDORA_VIEW_OBJECTS => array(
ISLANDORA_VIEW_OBJECTS => array(
'title' => t('View repository objects'),
'description' => t('View objects in the repository. Note: Fedora XACML security policies may override this permission.'),
),
FEDORA_ADD_DS => array(
ISLANDORA_ADD_DS => array(
'title' => t('Add datastreams to repository objects'),
'description' => t('Add datastreams to objects in the repository. Note: Fedora XACML security policies may override this position.'),
),
FEDORA_METADATA_EDIT => array(
ISLANDORA_METADATA_EDIT => array(
'title' => t('Edit metadata'),
'description' => t('Edit metadata for objects in the repository.'),
),
FEDORA_INGEST => array(
ISLANDORA_INGEST => array(
'title' => t('Create new repository objects'),
'description' => t('Create new objects in the repository.'),
),
FEDORA_PURGE => array(
ISLANDORA_PURGE => array(
'title' => t('Permanently remove objects from the repository'),
'description' => t('Permanently remove objects from the repository.'),
),
FEDORA_MANAGE_PROPERTIES => array(
ISLANDORA_MANAGE_PROPERTIES => array(
'title' => t('Manage object properties'),
'description' => t('Modify object labels, owner IDs, and states.'),
),
@ -803,7 +817,9 @@ function islandora_view_object(AbstractObject $object) {
drupal_add_js(array(
'islandora' => array(
'print_link' => '/islandora/object/' . $object->id . '/print')), array('type' => 'setting'));
'print_link' => 'islandora/object/' . $object->id . '/print')),
array('type' => 'setting'));
drupal_add_js($path . '/js/add_print.js');
drupal_set_title($object->label);
@ -1482,3 +1498,49 @@ function islandora_islandora_basic_collection_get_query_filters() {
return format_string('regex(str(?object), "info:fedora/(!namespaces):")', array('!namespaces' => $namespace_sparql));
}
}
/**
* Implements hook_islandora_object_ingested().
*
* On object ingestion we call the case of source_dsid being NULL only as
* the islandora_islandora_datastream_ingested hook will handle the cases
* where specific values of source_dsid can occur.
*/
function islandora_islandora_object_ingested(AbstractObject $object) {
module_load_include('inc', 'islandora', 'includes/derivatives');
$logging_results = islandora_do_derivatives($object, array(
'source_dsid' => NULL,
));
islandora_derivative_logging($logging_results);
}
/**
* Implements hook_islandora_datastream_ingested().
*
* When a datastream is ingested we filter the derivatives on source_dsid being
* equal to the current ingested datastream's id.
*/
function islandora_islandora_datastream_ingested(AbstractObject $object, AbstractDatastream $datastream) {
module_load_include('inc', 'islandora', 'includes/derivatives');
$logging_results = islandora_do_derivatives($object, array(
'source_dsid' => $datastream->id,
));
islandora_derivative_logging($logging_results);
}
/**
* Implements hook_islandora_datastream_modified().
*
* When a datastream is modified we filter the derivatives on source_dsid being
* equal to the current ingested datastream's id. Force is set to TRUE such that
* existing derivatives will be updated to reflect the change in the source.
*/
function islandora_islandora_datastream_modified(AbstractObject $object, AbstractDatastream $datastream) {
module_load_include('inc', 'islandora', 'includes/derivatives');
$logging_results = islandora_do_derivatives($object, array(
'source_dsid' => $datastream->id,
'force' => TRUE,
));
islandora_derivative_logging($logging_results);
}

8
js/add_print.js

@ -8,11 +8,11 @@
*/
(function ($) {
$(document).ready(function() {
$('.tabs .primary').append('<img id="print_btn" title="Print" src="/' + Drupal.settings.islandora.print_img + '"></img>');
$('.tabs .primary').append('<img id="print_btn" title="Print" src="' + Drupal.settings.basePath + Drupal.settings.islandora.print_img + '"></img>');
$('#print_btn').css("cursor","pointer");
$('#print_btn').click(function() {
window.location=Drupal.settings.islandora.print_link;
window.location=Drupal.settings.basePath + Drupal.settings.islandora.print_link;
});
});
})(jQuery);
})(jQuery);

2
tests/authtokens.test

@ -74,7 +74,7 @@ class IslandoraAuthtokensTestCase extends IslandoraWebTestCase {
$this->drupalGet("islandora/object/{$newpid}/datastream/JP2/view");
$this->assertResponse(403, 'Page not found as anonymous');
$account = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS));
$account = $this->drupalCreateUser(array(ISLANDORA_VIEW_OBJECTS));
$this->drupalLogin($account);
$this->drupalGet("islandora/object/{$newpid}/datastream/JP2/view");

296
tests/derivatives.test

@ -0,0 +1,296 @@
<?php
/**
* @file
* Tests to see if the hooks get called when appropriate.
*
* In the test module 'islandora_derivatives_test' there are implementations
* of hooks being tested. These implementations modifies the session, and
* that's how we test if the hook gets called.
*
* To make sense of these tests reference islandora_derivatives_test.module.
*/
class IslandoraDerivativesTestCase extends IslandoraWebTestCase {
/**
* Gets info to display to describe this test.
*
* @see IslandoraWebTestCase::getInfo()
*/
public static function getInfo() {
return array(
'name' => 'Islandora Derivative Generation',
'description' => 'Ensure that the derivative generation hooks return appropriate results.',
'group' => 'Islandora',
);
}
/**
* Creates an admin user and a connection to a fedora repository.
*
* @see IslandoraWebTestCase::setUp()
*/
public function setUp() {
parent::setUp(
array(
'islandora_derivatives_test',
)
);
$url = variable_get('islandora_base_url', 'http://localhost:8080/fedora');
$this->connection = new RepositoryConnection($url, $this->admin->name, $this->admin->pass);
$this->connection->reuseConnection = TRUE;
$this->api = new FedoraApi($this->connection);
$this->cache = new SimpleCache();
$this->repository = new FedoraRepository($this->api, $this->cache);
$this->pid = $this->randomName() . ":" . $this->randomName();
}
/**
* Free any objects/resources created for this test.
*
* @see IslandoraWebTestCase::tearDown()
*/
public function tearDown() {
$tuque = islandora_get_tuque_connection();
parent::tearDown();
}
/**
* Tests that the islandora_islandora_object_ingested hook gets fired.
*/
public function testDerivativeOnIngest() {
global $_islandora_derivative_test_ingest_method;
$_islandora_derivative_test_ingest_method = 'modifyDatastream';
$tuque = islandora_get_tuque_connection();
$object = $tuque->repository->constructObject($this->pid);
$object->models = array(
'some:cmodel',
);
$dsid = 'OBJ';
$ds = $object->constructDatastream($dsid);
$ds->label = 'Test';
$ds->content = 'test';
$object->ingestDatastream($ds);
$tuque->repository->ingestObject($object);
$this->assertDatastreams($object, array(
'RELS-EXT',
'DC',
'OBJ',
'DERIV',
'NOSOURCE',
));
$this->assertEqual('ingestDatastream', $_islandora_derivative_test_ingest_method, 'The expected ingest method is "ingestDatastream", got "' . $_islandora_derivative_test_ingest_method . '".');
$this->assertEqual('test some string', $object['DERIV']->content, 'The expected content of the DERIV datastream is "test some string", got "' . $object['DERIV']->content . '".');
$this->assertEqual('NOSOURCE', $object['NOSOURCE']->content, 'The expected content of the NOSOURCE datastream is "NOSOURCE", got "' . $object['NOSOURCE']->content . '".');
}
/**
* Tests the ingest method when when forcing on existing datastreams.
*/
public function testDerivativeOnForceExistingDatastream() {
global $_islandora_derivative_test_ingest_method;
$_islandora_derivative_test_ingest_method = 'ingestDatastream';
$object = $this->constructBaseObject();
$object = $this->constructDERIVDatastream($object);
$this->constructNOSOURCEDatastream($object);
$islandora_object = islandora_object_load($this->pid);
islandora_do_derivatives($islandora_object, array(
'force' => TRUE,
));
$this->assertEqual('modifyDatastream', $_islandora_derivative_test_ingest_method, 'The expected ingest method is "modifyDatastream", got "' . $_islandora_derivative_test_ingest_method . '".');
$this->assertEqual('FORCEFULLY APPENDING CONTENT TO test', $islandora_object['DERIV']->content, 'The expected content of the DERIV datastream is "FORCEFULLY APPENDING CONTENT TO test", got "' . $islandora_object['DERIV']->content . '".');
}
/**
* Tests the ingest method when forcing on non-existing datastreams.
*/
public function testDerivativeOnForceNonExistingDatastream() {
global $_islandora_derivative_test_ingest_method;
$_islandora_derivative_test_ingest_method = 'modifyDatastream';
$this->constructBaseObject();
$object = islandora_object_load($this->pid);
islandora_do_derivatives($object, array(
'force' => TRUE,
));
$this->assertEqual('ingestDatastream', $_islandora_derivative_test_ingest_method, 'The expected ingest method is "ingestDatastream", got "' . $_islandora_derivative_test_ingest_method . '".');
$this->assertEqual('test some string', $object['DERIV']->content, 'The expected content of the DERIV datastream is "test some string", got "' . $object['DERIV']->content . '".');
}
/**
* Tests the islandora_datastream_modified hook when there are existing DSes.
*/
public function testDerivativeOnModifyExistingDatastream() {
global $_islandora_derivative_test_ingest_method;
$_islandora_derivative_test_ingest_method = 'ingestDatastream';
$object = $this->constructBaseObject();
$this->constructDERIVDatastream($object);
// Need to do this as Tuque caches.
$connection = islandora_get_tuque_connection();
$connection->cache->resetCache();
$islandora_object = islandora_object_load($this->pid);
$changed_content = 'islandora beast';
$islandora_object['OBJ']->content = $changed_content;
$this->assertEqual('modifyDatastream', $_islandora_derivative_test_ingest_method, 'The expected ingest method is "modifyDatastream", got "' . $_islandora_derivative_test_ingest_method . '".');
$this->assertEqual('FORCEFULLY APPENDING CONTENT TO ' . $changed_content, $islandora_object['DERIV']->content, 'The expected content of the DERIV datastream is "FORCEFULLY APPENDING CONTENT TO islandora beast", got "' . $islandora_object['DERIV']->content . '".');
}
/**
* Tests islandora_datastream_modified hook when there are no existing DSes.
*/
public function testDerivativeOnModifyNonExistingDatastream() {
global $_islandora_derivative_test_ingest_method;
$_islandora_derivative_test_ingest_method = 'modifyDatastream';
$this->constructBaseObject();
// Need to do this as Tuque caches.
$connection = islandora_get_tuque_connection();
$connection->cache->resetCache();
$islandora_object = islandora_object_load($this->pid);
$changed_content = 'islandora beast';
$islandora_object['OBJ']->content = $changed_content;
$this->assertEqual('ingestDatastream', $_islandora_derivative_test_ingest_method, 'The expected ingest method is "ingestDatastream", got "' . $_islandora_derivative_test_ingest_method . '".');
$this->assertEqual($changed_content . ' some string', $islandora_object['DERIV']->content, 'The expected content of the DERIV datastream is "islandora beast string", got "' . $islandora_object['DERIV']->content . '".');
}
/**
* Tests derivative hook filtering based upon source_dsid.
*/
public function testDerivativeFilteringOnSourceDSID() {
global $_islandora_derivative_test_derivative_functions;
$_islandora_derivative_test_derivative_functions = array();
$this->constructBaseObject();
$object = islandora_object_load($this->pid);
islandora_do_derivatives($object, array(
'source_dsid' => 'OBJ',
));
$this->assertEqual(1, count($_islandora_derivative_test_derivative_functions), 'Expected 1 derivative function for the source_dsid of "OBJ", got ' . count($_islandora_derivative_test_derivative_functions) . '.');
$called_function = (string) reset($_islandora_derivative_test_derivative_functions);
$this->assertEqual('islandora_derivatives_test_create_deriv_datastream', $called_function, 'Expected derivative function is "islandora_derivatives_test_create_deriv_datastream", got "' . $called_function . '".');
// Reset the derivative functions array as we are going to use it again.
$_islandora_derivative_test_derivative_functions = array();
islandora_do_derivatives($object, array(
'source_dsid' => 'SOMEWEIRDDATASTREAM',
));
$this->assertEqual(1, count($_islandora_derivative_test_derivative_functions), 'Expected 1 derivative function for the source_dsid of "SOMEWEIRDDATASTREAM", got ' . count($_islandora_derivative_test_derivative_functions) . '.');
$called_function = (string) reset($_islandora_derivative_test_derivative_functions);
$this->assertEqual('islandora_derivatives_test_create_some_weird_datastream', $called_function, 'Expected derivative function is "islandora_derivatives_test_create_some_weird_datastream", got "' . $called_function . '".');
}
/**
* Tests that only functions were the source_dsid is NULL are fired.
*/
public function testNULLSourceDSID() {
global $_islandora_derivative_test_derivative_functions;
$_islandora_derivative_test_derivative_functions = array();
$this->constructBaseObject();
$object = islandora_object_load($this->pid);
islandora_do_derivatives($object, array(
'source_dsid' => NULL,
));
$this->assertDatastreams($object, array(
'DC',
'RELS-EXT',
'OBJ',
'NOSOURCE',
));
$this->assertEqual(1, count($_islandora_derivative_test_derivative_functions), 'Expected 1 derivative function for the source_dsid of "NULL", got ' . count($_islandora_derivative_test_derivative_functions) . '.');
$called_function = (string) reset($_islandora_derivative_test_derivative_functions);
$this->assertEqual('islandora_derivatives_test_create_nosource_datastream', $called_function, 'Expected derivative function is "islandora_derivatives_test_create_nosource_datastream", got "' . $called_function . '".');
$this->assertEqual('NOSOURCE', $object['NOSOURCE']->content, 'The expected content of the NOSOURCE datastream is "NOSOURCE", got "' . $object['NOSOURCE']->content . '".');
}
/**
* Tests that when no source_dsid all derivative functions are called.
*/
public function testNoSourceDSIDNoForce() {
global $_islandora_derivative_test_derivative_functions;
$_islandora_derivative_test_derivative_functions = array();
$this->constructBaseObject();
$object = islandora_object_load($this->pid);
islandora_do_derivatives($object, array());
$this->assertDatastreams($object, array(
'DC',
'RELS-EXT',
'OBJ',
'DERIV',
'NOSOURCE',
));
$this->assertEqual(3, count($_islandora_derivative_test_derivative_functions), 'Expected 3 derivative functions when there is no source_dsid, got ' . count($_islandora_derivative_test_derivative_functions) . '.');
}
/**
* Tests that when no source_dsid all derivative functions are called.
*/
public function testNoSourceDSIDForce() {
global $_islandora_derivative_test_derivative_functions;
$_islandora_derivative_test_derivative_functions = array();
$this->constructBaseObject();
$object = islandora_object_load($this->pid);
islandora_do_derivatives($object, array(
'force' => TRUE,
));
$this->assertDatastreams($object, array(
'DC',
'RELS-EXT',
'OBJ',
'DERIV',
'NOSOURCE',
));
$this->assertEqual(3, count($_islandora_derivative_test_derivative_functions), 'Expected 3 derivative functions when there is no source_dsid, got ' . count($_islandora_derivative_test_derivative_functions) . '.');
}
/**
* Helper function that will construct a base object.
*/
public function constructBaseObject() {
$object = $this->repository->constructObject($this->pid);
$object->models = array(
'some:cmodel',
);
$dsid = 'OBJ';
$ds = $object->constructDatastream($dsid);
$ds->label = 'Test';
$ds->content = 'test';
$object->ingestDatastream($ds);
$this->repository->ingestObject($object);
return $object;
}
/**
* Helper function to construct the DERIV datastream without firing hooks.
*
* @param AbstractObject $object
* An AbstractObject representing a FedoraObject.
*
* @return AbstractObject
* The modified AbstractObject.
*/
public function constructDERIVDatastream(AbstractObject $object) {
$dsid = 'DERIV';
$ds = $object->constructDatastream($dsid);
$ds->label = 'Test';
$ds->content = 'test some string';
$object->ingestDatastream($ds);
return $object;
}
/**
* Helper function to construct the NOSOURCE datastream without firing hooks.
*
* @param AbstractObject $object
* An AbstractObject representing a FedoraObject.
*
* @return AbstractObject
* The modified AbstractObject.
*/
public function constructNOSOURCEDatastream(AbstractObject $object) {
$dsid = 'NOSOURCE';
$ds = $object->constructDatastream($dsid);
$ds->label = 'Test';
$ds->content = 'NOSOURCE';
$object->ingestDatastream($ds);
return $object;
}
}

6
tests/hooked_access.test

@ -37,9 +37,9 @@ class IslandoraHookedAccessTestCase extends IslandoraWebTestCase {
$this->objects = array(
'test:testAccessHook',
);
$this->op = FEDORA_VIEW_OBJECTS;
$this->other_op = FEDORA_INGEST;
$this->denied_op = FEDORA_PURGE;
$this->op = ISLANDORA_VIEW_OBJECTS;
$this->other_op = ISLANDORA_INGEST;
$this->denied_op = ISLANDORA_PURGE;
$this->purgeTestObjects();
$this->dsid = 'asdf';
$this->createTestObjects();

7
tests/islandora_derivatives_test.info

@ -0,0 +1,7 @@
name = Islandora Derivatives Generation testing
description = Tests derivative generation hooks. Do not enable.
core = 7.x
package = Testing
hidden = TRUE
files[] = islandora_derivatives_test.module
dependencies[] = islandora

202
tests/islandora_derivatives_test.module

@ -0,0 +1,202 @@
<?php
/**
* @file
* Tests for derivative generation.
*/
/**
* Implements hook_islandora_CMODEL_PID_derivative().
*/
function islandora_derivatives_test_some_cmodel_islandora_derivative() {
return array(
array(
'source_dsid' => 'OBJ',
'destination_dsid' => 'DERIV',
'weight' => '0',
'function' => array(
'islandora_derivatives_test_create_deriv_datastream',
),
),
array(
'source_dsid' => 'SOMEWEIRDDATASTREAM',
'destination_dsid' => 'STANLEY',
'weight' => '-1',
'function' => array(
'islandora_derivatives_test_create_some_weird_datastream',
),
),
array(
'source_dsid' => NULL,
'destination_dsid' => 'NOSOURCE',
'weight' => '-3',
'function' => array(
'islandora_derivatives_test_create_nosource_datastream',
),
),
);
}
/**
* Creates the DERIV datastream for use in testing.
*
* @param AbstractObject $object
* An AbstractObject representing a Fedora object.
* @param bool $force
* Whether or not derivative generation is to be forced.
* @return array
* An array detailing the success of the operation.
*
* @see hook_islandora_derivative()
*/
function islandora_derivatives_test_create_deriv_datastream(AbstractObject $object, $force = FALSE) {
global $_islandora_derivative_test_derivative_functions;
$_islandora_derivative_test_derivative_functions[] = 'islandora_derivatives_test_create_deriv_datastream';
$return = '';
if (!isset($object['DERIV']) || (isset($object['DERIV']) && $force === TRUE)) {
if ($force !== TRUE || !isset($object['DERIV'])) {
$deriv_string = $object['OBJ']->content . ' some string';
}
else {
$deriv_string = "FORCEFULLY APPENDING CONTENT TO " . $object['OBJ']->content;
}
$added_successfully = islandora_derivatives_test_add_datastream($object, 'DERIV', $deriv_string);
if ($added_successfully !== TRUE) {
$return = islandora_derivatives_test_failed_adding($added_successfully);
}
else {
$return = array(
'success' => TRUE,
'messages' => array(
array(
'message' => t('The DERIV datastream was added successfully for @pid!'),
'message_sub' => array('@pid' => $object->id),
'type' => 'dsm',
),
),
);
}
return $return;
}
}
/**
* Stub function that used only for datastream filtering counts.
*
* @param AbstractObject $object
* An AbstractObject representing a Fedora object.
* @param bool $force
* Whether the derivatives are being forcefully generated or not.
*/
function islandora_derivatives_test_create_some_weird_datastream(AbstractObject $object, $force = FALSE) {
global $_islandora_derivative_test_derivative_functions;
// Add to the global that we got to this function.
$_islandora_derivative_test_derivative_functions[] = 'islandora_derivatives_test_create_some_weird_datastream';
}
/**
* Creates the NOSOURCE datastream for use in testing.
*
* @param AbstractObject $object
* An AbstractObject representing a Fedora object.
* @param bool $force
* Whether or not derivative generation is to be forced.
* @return array
* An array detailing the success of the operation.
*
* @see hook_islandora_derivative()
*/
function islandora_derivatives_test_create_nosource_datastream(AbstractObject $object, $force = FALSE) {
global $_islandora_derivative_test_derivative_functions;
$_islandora_derivative_test_derivative_functions[] = 'islandora_derivatives_test_create_nosource_datastream';
$return = '';
if (!isset($object['NOSOURCE']) || (isset($object['NOSOURCE']) && $force === TRUE)) {
if ($force !== TRUE || !isset($object['NOSOURCE'])) {
$deriv_string = 'NOSOURCE';
}
else {
$deriv_string = "FORCEFULLY APPENDING CONTENT TO " . $object['NOSOURCE']->content;
}
$added_successfully = islandora_derivatives_test_add_datastream($object, 'NOSOURCE', $deriv_string);
if ($added_successfully !== TRUE) {
$return = islandora_derivatives_test_failed_adding($added_successfully);
}
else {
$return = array(
'success' => TRUE,
'messages' => array(
array(
'message' => t('The DERIV datastream was added successfully for @pid!'),
'message_sub' => array('@pid' => $object->id),
'type' => 'dsm',
),
),
);
}
return $return;
}
}
/**
* Helper function that adds/modifies the datastream to the object in testing.
*
* @param AbstractObject $object
* An AbstractObject representing a Fedora object.
* @param string $dsid
* The datastream id for which we are adding/modifying.
* @param string $deriv_string
* The content of the datastream we are adding.
*
* @return bool|string
* A bool if the operation was successfully, the error message otherwise.
*/
function islandora_derivatives_test_add_datastream(AbstractObject $object, $dsid, $deriv_string) {
global $_islandora_derivative_test_ingest_method;
try {
$ingest = !isset($object[$dsid]);
if ($ingest) {
$ds = $object->constructDatastream($dsid, 'M');
$ds->label = $dsid;
}
else {
$ds = $object[$dsid];
}
$ds->content = $deriv_string;
if ($ingest) {
$_islandora_derivative_test_ingest_method = 'ingestDatastream';
$object->ingestDatastream($ds);
}
else {
$_islandora_derivative_test_ingest_method = 'modifyDatastream';
}
return TRUE;
}
catch (exception $e) {
$message = $e->getMessage();
return $message;
}
}
/**
* Returns a message if we failed to add a derivative.
*
* @see hook_islandora_derivative()
*
* @param string $message
* The error message to be returned back.
*
* @return array
* An array describing the outcome of our failure.
*/
function islandora_derivatives_test_failed_adding($message) {
return array(
'success' => FALSE,
'messages' => array(
array(
'message' => $message,
'type' => 'watchdog',
'severity' => WATCHDOG_ERROR,
),
),
);
}

2
tests/islandora_hooked_access_test.module

@ -9,7 +9,7 @@
* Implements hook_islandora_object_access().
*/
function islandora_hooked_access_test_islandora_object_access($op, $object, $user) {
if ($op == FEDORA_PURGE) {
if ($op == ISLANDORA_PURGE) {
return FALSE;
}
if (isset($_SESSION['islandora_hooked_access_test']) && $_SESSION['islandora_hooked_access_test'] === func_get_args()) {

50
tests/islandora_manage_permissions.test

@ -33,16 +33,16 @@ class IslandoraPermissionsTestCase extends IslandoraWebTestCase {
* Test manage permissions.
*/
public function testManagePermissions() {
// Test permission FEDORA_VIEW_OBJECTS.
// Test permission ISLANDORA_VIEW_OBJECTS.
// Create a user with permission.
$user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS));
$user = $this->drupalCreateUser(array(ISLANDORA_VIEW_OBJECTS));
// Log the user in.
$this->drupalLogin($user);
$this->clickLink(t('Islandora Repository'));
$this->assertNoLink('Manage', 'Manage tab is not on current page.');
// Test permission FEDORA_VIEW_OBJECTS, FEDORA_MANAGE_PROPERTIES.
$user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_MANAGE_PROPERTIES));
// Test permission ISLANDORA_VIEW_OBJECTS, ISLANDORA_MANAGE_PROPERTIES.
$user = $this->drupalCreateUser(array(ISLANDORA_VIEW_OBJECTS, ISLANDORA_MANAGE_PROPERTIES));
$this->drupalLogin($user);
$this->clickLink(t('Islandora Repository'));
$this->assertLink('Manage', 0, 'Manage tab is on current page.');
@ -51,8 +51,8 @@ class IslandoraPermissionsTestCase extends IslandoraWebTestCase {
$this->assertNoLink('Datastreams', 'Datastreams tab is not on current page.');
$this->assertNoLink('Collection', 'Collection tab is not on current page.');
// Test permission FEDORA_VIEW_OBJECTS, FEDORA_ADD_DS.
$user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_ADD_DS));
// Test permission ISLANDORA_VIEW_OBJECTS, ISLANDORA_ADD_DS.
$user = $this->drupalCreateUser(array(ISLANDORA_VIEW_OBJECTS, ISLANDORA_ADD_DS));
$this->drupalLogin($user);
$this->clickLink(t('Islandora Repository'));
$this->assertLink('Manage', 0, 'Manage tab is on current page.');
@ -61,8 +61,8 @@ class IslandoraPermissionsTestCase extends IslandoraWebTestCase {
$this->assertNoLink('Properties', 'Properties tab is not on current page.');
$this->assertNoLink('Collection', 'Collection tab is not on current page.');
// Test permission FEDORA_VIEW_OBJECTS, FEDORA_METADATA_EDIT.
$user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_METADATA_EDIT));
// Test permission ISLANDORA_VIEW_OBJECTS, ISLANDORA_METADATA_EDIT.
$user = $this->drupalCreateUser(array(ISLANDORA_VIEW_OBJECTS, ISLANDORA_METADATA_EDIT));
$this->drupalLogin($user);
$this->clickLink(t('Islandora Repository'));
$this->assertLink('Manage', 0, 'Manage tab is on current page.');
@ -71,8 +71,8 @@ class IslandoraPermissionsTestCase extends IslandoraWebTestCase {
$this->assertNoLink('Properties', 'Properties tab is not on current page.');
$this->assertNoLink('Collection', 'Collection tab is not on current page.');
// Test permission FEDORA_VIEW_OBJECTS, FEDORA_PURGE.
$user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE));
// Test permission ISLANDORA_VIEW_OBJECTS, ISLANDORA_PURGE.
$user = $this->drupalCreateUser(array(ISLANDORA_VIEW_OBJECTS, ISLANDORA_PURGE));
$this->drupalLogin($user);
$this->clickLink(t('Islandora Repository'));
$this->assertLink('Manage', 0, 'Manage tab is on current page.');
@ -98,39 +98,39 @@ class IslandoraPermissionsTestCase extends IslandoraWebTestCase {
$ret = islandora_user_access($object, array());
$this->assertFalse($ret, 'User access denied when no permissions are provided.');
// Test access with matching permission.
$user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS));
$ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS), array(), TRUE, $user);
$user = $this->drupalCreateUser(array(ISLANDORA_VIEW_OBJECTS));
$ret = islandora_user_access($object, array(ISLANDORA_VIEW_OBJECTS), array(), TRUE, $user);
$this->assertTrue($ret, 'User access granted when permissions match.');
// Test access with matching permission but access any is FALSE.
$user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS));
$ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE), array(), FALSE, $user);
$user = $this->drupalCreateUser(array(ISLANDORA_VIEW_OBJECTS));
$ret = islandora_user_access($object, array(ISLANDORA_VIEW_OBJECTS, ISLANDORA_PURGE), array(), FALSE, $user);
$this->assertFalse($ret, 'User access denied for matching permission but with access any set to FALSE.');
// Test access with non-matching permission.
$user = $this->drupalCreateUser(array(FEDORA_PURGE));
$ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS), array(), TRUE, $user);
$user = $this->drupalCreateUser(array(ISLANDORA_PURGE));
$ret = islandora_user_access($object, array(ISLANDORA_VIEW_OBJECTS), array(), TRUE, $user);
$this->assertFalse($ret, 'User access denied when permissions did not match.');
// Test access with both permissions and content model.
$user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS));
$user = $this->drupalCreateUser(array(ISLANDORA_VIEW_OBJECTS));
$model = $object->models;
$model = reset($model);
$ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS), array($model), TRUE, $user);
$ret = islandora_user_access($object, array(ISLANDORA_VIEW_OBJECTS), array($model), TRUE, $user);
$this->assertTrue($ret, 'User access granted for matching permission and model.');
// Test access with matching permissions and non-matching content model.
$user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS));
$ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS), array('islandora:obviouslyNotACModel'), TRUE, $user);
$user = $this->drupalCreateUser(array(ISLANDORA_VIEW_OBJECTS));
$ret = islandora_user_access($object, array(ISLANDORA_VIEW_OBJECTS), array('islandora:obviouslyNotACModel'), TRUE, $user);
$this->assertFalse($ret, 'User access denied for matching permission and non-matching model.');
// Test access with all matching permissions and one matching model but
// access any is FALSE.
$user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE));
$user = $this->drupalCreateUser(array(ISLANDORA_VIEW_OBJECTS, ISLANDORA_PURGE));
$model = $object->models;
$model = reset($model);
$ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE), array($model, 'islandora:obviouslyNotACModel'), FALSE, $user);
$ret = islandora_user_access($object, array(ISLANDORA_VIEW_OBJECTS, ISLANDORA_PURGE), array($model, 'islandora:obviouslyNotACModel'), FALSE, $user);
$this->assertFalse($ret, 'User access denied for all matching permissions and one matching model but with access any set to FALSE.');
$ret = islandora_user_access($object, array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE), array($model), FALSE, $user);
$ret = islandora_user_access($object, array(ISLANDORA_VIEW_OBJECTS, ISLANDORA_PURGE), array($model), FALSE, $user);
$this->assertTrue($ret, 'User access granted for all matching permissions and matching models with access any set to FALSE.');
// Test passing in a Datastream.
$user = $this->drupalCreateUser(array(FEDORA_VIEW_OBJECTS, FEDORA_PURGE));
$ret = islandora_user_access($object['DC'], array(FEDORA_VIEW_OBJECTS), array(), TRUE, $user);
$user = $this->drupalCreateUser(array(ISLANDORA_VIEW_OBJECTS, ISLANDORA_PURGE));
$ret = islandora_user_access($object['DC'], array(ISLANDORA_VIEW_OBJECTS), array(), TRUE, $user);
$this->assertTrue($ret, 'User access granted for matching permissions, with a datastream given instead of an object.');
}
}

18
theme/theme.inc

@ -115,7 +115,7 @@ function islandora_preprocess_islandora_default(&$variables) {
$download_path = islandora_datastream_get_url($ds, 'download');
$datastreams[$id]['id'] = $id;
$datastreams[$id]['label'] = $label;
$datastreams[$id]['label_link'] = islandora_datastream_access(FEDORA_VIEW_OBJECTS, $ds) ?
$datastreams[$id]['label_link'] = islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $ds) ?
l($label, $download_path) :
$label;
$datastreams[$id]['download_url'] = $download_path;
@ -130,14 +130,14 @@ function islandora_preprocess_islandora_default(&$variables) {
}
$variables['datastreams'] = $datastreams;
// Objects in fcrepo4 don't always contain a DC datastream.
if (isset($islandora_object['DC']) && islandora_datastream_access(FEDORA_VIEW_OBJECTS, $islandora_object['DC'])) {
if (isset($islandora_object['DC']) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['DC'])) {
$dc_object = DublinCore::importFromXMLString($islandora_object['DC']->content);
$dc_array = $dc_object->asArray();
}
$variables['dc_array'] = isset($dc_array) ? $dc_array : array();
$variables['islandora_dublin_core'] = isset($dc_object) ? $dc_object : NULL;
$variables['islandora_object_label'] = $islandora_object->label;
if (isset($islandora_object['TN']) && islandora_datastream_access(FEDORA_VIEW_OBJECTS, $islandora_object['TN'])) {
if (isset($islandora_object['TN']) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $islandora_object['TN'])) {
$variables['islandora_thumbnail_url'] = url("islandora/object/{$islandora_object->id}/datastream/TN/view");
}
}
@ -219,11 +219,11 @@ function islandora_preprocess_islandora_objects(array &$variables) {
$o = islandora_object_load($o);
$url = "islandora/object/{$o->id}";
$link_options = array('html' => TRUE, 'attributes' => array('title' => $o->label));
$img = islandora_datastream_access(FEDORA_VIEW_OBJECTS, $o['TN']) ?
$img = islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $o['TN']) ?
theme('image', array('path' => url("$url/datastream/TN/view"), 'attributes' => array())) :
'';
$description = NULL;
if (isset($o['DC']) && islandora_datastream_access(FEDORA_VIEW_OBJECTS, $o['DC'])) {
if (isset($o['DC']) && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $o['DC'])) {
$dc = DublinCore::importFromXMLString($o['DC']->content);
if ($dc) {
$dc = $dc->asArray();
@ -260,7 +260,7 @@ function theme_islandora_datastream_download_link(array $vars) {
module_load_include('inc', 'islandora', 'includes/utilities');
$label = t('download');
return islandora_datastream_access(FEDORA_VIEW_OBJECTS, $datastream) ?
return islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $datastream) ?
l($label, islandora_datastream_get_url($datastream, 'download')) :
'';
}
@ -289,7 +289,7 @@ function theme_islandora_datastream_view_link(array $vars) {
}
if ($vars['version'] === NULL) {
$perm = FEDORA_VIEW_OBJECTS;
$perm = ISLANDORA_VIEW_OBJECTS;
}
else {
$perm = ISLANDORA_VIEW_DATASTREAM_HISTORY;
@ -319,7 +319,7 @@ function theme_islandora_datastream_delete_link(array $vars) {
$datastreams = module_invoke_all('islandora_undeletable_datastreams', $datastream->parent->models);
$can_delete = !in_array($datastream->id, $datastreams) && islandora_datastream_access(FEDORA_PURGE, $datastream);
$can_delete = !in_array($datastream->id, $datastreams) && islandora_datastream_access(ISLANDORA_PURGE, $datastream);
if ($vars['version'] !== NULL) {
if (count($datastream) == 1) {
@ -354,7 +354,7 @@ function theme_islandora_datastream_edit_link(array $vars) {
$edit_registry = module_invoke_all('islandora_edit_datastream_registry', $datastream->parent, $datastream);
$can_edit = count($edit_registry) > 0 && islandora_datastream_access(FEDORA_METADATA_EDIT, $datastream);
$can_edit = count($edit_registry) > 0 && islandora_datastream_access(ISLANDORA_METADATA_EDIT, $datastream);
return $can_edit ?
l(t('edit'), "islandora/object/{$datastream->parent->id}/datastream/{$datastream->id}/edit") :

Loading…
Cancel
Save