From 95a6d076b911bb45b49ae3940521ec1dce4d6f45 Mon Sep 17 00:00:00 2001 From: Rosie Le Faive Date: Mon, 2 Oct 2017 18:28:13 -0300 Subject: [PATCH 1/3] ISLANDORA-2073 block datastreams for inactive or deleted. --- islandora.api.php | 10 ++++++++-- islandora.module | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/islandora.api.php b/islandora.api.php index e553a894..6bc641b4 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -562,8 +562,14 @@ function hook_cmodel_pid_islandora_ingest_steps_alter(array &$steps, array &$for * the given object, or NULL to indicate that we are making no assertion * about the outcome. Can also be an array containing multiple * TRUE/FALSE/NULLs, due to how hooks work. + * + * If denying an action (such as ISLANDORA_VIEW_OBJECTS) on an object, + * it will not be automatically denied for the individual datastreams. + * Operations on datastreams must be explicitly denied in + * hook_islandora_datastream_access(). + * */ -function hook_islandora_object_access($op, $object, $user) { +function hook_islandora_object_access($op, AbstractObject $object, $user) { switch ($op) { case 'create stuff': return TRUE; @@ -602,7 +608,7 @@ function hook_cmodel_pid_islandora_object_access($op, $object, $user) { * about the outcome. Can also be an array containing multiple * TRUE/FALSE/NULLs, due to how hooks work. */ -function hook_islandora_datastream_access($op, $object, $user) { +function hook_islandora_datastream_access($op, AbstractObject $object, $user) { switch ($op) { case 'create stuff': return TRUE; diff --git a/islandora.module b/islandora.module index 29899c1b..97b75937 100644 --- a/islandora.module +++ b/islandora.module @@ -1965,6 +1965,10 @@ function islandora_islandora_datastream_access($op, AbstractDatastream $datastre module_load_include('inc', 'islandora', 'includes/utilities'); $result = islandora_namespace_accessible($datastream->parent->id) && user_access($op, $user); + if (($datastream->parent->state != 'A') && variable_get('islandora_deny_inactive_and_deleted', FALSE)) { + $result = ($result && user_access(ISLANDORA_ACCESS_INACTIVE_AND_DELETED_OBJECTS, $user)); + } + if ($result && $op == ISLANDORA_REGENERATE_DERIVATIVES) { module_load_include('inc', 'islandora', 'includes/derivatives'); $applicable_hook = FALSE; From 0f0e84ed357b5c272761c8ecac16bf4329115f23 Mon Sep 17 00:00:00 2001 From: Rosie Le Faive Date: Tue, 3 Oct 2017 16:16:53 -0300 Subject: [PATCH 2/3] Remove copypasta and fix .api. --- islandora.api.php | 8 ++++---- islandora.module | 7 +------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/islandora.api.php b/islandora.api.php index 6bc641b4..db1b6b0b 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -597,8 +597,8 @@ function hook_cmodel_pid_islandora_object_access($op, $object, $user) { * @param string $op * A string define an operation to check. Should be defined via * hook_permission(). - * @param AbstractDatastream $object - * An object to check the operation on. + * @param AbstractDatastream $datastream + * A datastream to check the operation on. * @param object $user * A loaded user object, as the global $user variable might contain. * @@ -608,7 +608,7 @@ function hook_cmodel_pid_islandora_object_access($op, $object, $user) { * about the outcome. Can also be an array containing multiple * TRUE/FALSE/NULLs, due to how hooks work. */ -function hook_islandora_datastream_access($op, AbstractObject $object, $user) { +function hook_islandora_datastream_access($op, AbstractDatastream $datastream, $user) { switch ($op) { case 'create stuff': return TRUE; @@ -626,7 +626,7 @@ function hook_islandora_datastream_access($op, AbstractObject $object, $user) { * * @see hook_islandora_datastream_access() */ -function hook_cmodel_pid_islandora_datastream_access($op, $object, $user) { +function hook_cmodel_pid_islandora_datastream_access($op, $datastream, $user) { } diff --git a/islandora.module b/islandora.module index 97b75937..4f168ba7 100644 --- a/islandora.module +++ b/islandora.module @@ -1962,12 +1962,7 @@ function islandora_islandora_metadata_display_info() { * Implements hook_islandora_datastream_access(). */ function islandora_islandora_datastream_access($op, AbstractDatastream $datastream, $user) { - module_load_include('inc', 'islandora', 'includes/utilities'); - $result = islandora_namespace_accessible($datastream->parent->id) && user_access($op, $user); - - if (($datastream->parent->state != 'A') && variable_get('islandora_deny_inactive_and_deleted', FALSE)) { - $result = ($result && user_access(ISLANDORA_ACCESS_INACTIVE_AND_DELETED_OBJECTS, $user)); - } + $result = islandora_islandora_object_access($op, $datastream->parent, $user); if ($result && $op == ISLANDORA_REGENERATE_DERIVATIVES) { module_load_include('inc', 'islandora', 'includes/derivatives'); From 81affe9ee4784134727fe96aa3c76f5dee6462ae Mon Sep 17 00:00:00 2001 From: Rosie Le Faive Date: Thu, 12 Oct 2017 17:31:15 -0300 Subject: [PATCH 3/3] Don't forget utilities.inc. --- islandora.module | 1 + 1 file changed, 1 insertion(+) diff --git a/islandora.module b/islandora.module index 4f168ba7..287103eb 100644 --- a/islandora.module +++ b/islandora.module @@ -1966,6 +1966,7 @@ function islandora_islandora_datastream_access($op, AbstractDatastream $datastre if ($result && $op == ISLANDORA_REGENERATE_DERIVATIVES) { module_load_include('inc', 'islandora', 'includes/derivatives'); + module_load_include('inc', 'islandora', 'includes/utilities'); $applicable_hook = FALSE; $object = $datastream->parent; $hooks = islandora_invoke_hook_list(ISLANDORA_DERIVATIVE_CREATION_HOOK, $object->models, array($object));