From 74755f8074e1658ece9ee45dde2e34502e348929 Mon Sep 17 00:00:00 2001 From: Lucas van Schaik Date: Fri, 17 Feb 2023 16:56:42 +0100 Subject: [PATCH 1/9] Implement solution for drupal issues 3089660 and 3045666 --- src/IslandoraContextManager.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/IslandoraContextManager.php b/src/IslandoraContextManager.php index 801e3253..9a318a5b 100644 --- a/src/IslandoraContextManager.php +++ b/src/IslandoraContextManager.php @@ -48,7 +48,11 @@ class IslandoraContextManager extends ContextManager { $conditions = $context->getConditions(); // Apply context to any context aware conditions. - $this->applyContexts($conditions, $provided); + // Abort if the application of contexts has been unsuccessful + // similarly to BlockAccessControlHandler::checkAccess(). + if (!$this->applyContexts($conditions, $provided)) { + return FALSE; + } // Set the logic to use when validating the conditions. $logic = $context->requiresAllConditions() @@ -76,6 +80,7 @@ class IslandoraContextManager extends ContextManager { * TRUE if conditions pass */ protected function applyContexts(ConditionPluginCollection &$conditions, array $provided = []) { + $passed = FALSE; foreach ($conditions as $condition) { if ($condition instanceof ContextAwarePluginInterface) { try { @@ -86,14 +91,15 @@ class IslandoraContextManager extends ContextManager { $contexts = $provided; } $this->contextHandler->applyContextMapping($condition, $contexts); + $passed = TRUE; } catch (ContextException $e) { - return FALSE; + continue; } } } - return TRUE; + return $passed; } } From 87f475d81c0bca3793c9f3bdc6cf8def4f31ef6b Mon Sep 17 00:00:00 2001 From: Lucas van Schaik Date: Fri, 17 Feb 2023 16:57:50 +0100 Subject: [PATCH 2/9] Check if action is appropriate for entity before executing --- src/PresetReaction/PresetReaction.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/PresetReaction/PresetReaction.php b/src/PresetReaction/PresetReaction.php index 98aa6946..e516eb24 100644 --- a/src/PresetReaction/PresetReaction.php +++ b/src/PresetReaction/PresetReaction.php @@ -56,7 +56,10 @@ class PresetReaction extends ContextReactionPluginBase implements ContainerFacto $action_ids = $config['actions']; foreach ($action_ids as $action_id) { $action = $this->actionStorage->load($action_id); - $action->execute([$entity]); + // Make sure that the action is appropriate for the entity. + if ($entity->getEntityTypeId() === $action->getType()) { + $action->execute([$entity]); + } } } From 4250109c6345c771cab0a5287cd83a4ebadbd93d Mon Sep 17 00:00:00 2001 From: Lucas van Schaik Date: Mon, 20 Feb 2023 21:25:48 +0100 Subject: [PATCH 3/9] Check if conditions exist before applying contexts to them --- src/IslandoraContextManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IslandoraContextManager.php b/src/IslandoraContextManager.php index 9a318a5b..b3aec19c 100644 --- a/src/IslandoraContextManager.php +++ b/src/IslandoraContextManager.php @@ -50,7 +50,7 @@ class IslandoraContextManager extends ContextManager { // Apply context to any context aware conditions. // Abort if the application of contexts has been unsuccessful // similarly to BlockAccessControlHandler::checkAccess(). - if (!$this->applyContexts($conditions, $provided)) { + if (count($conditions) > 0 && !$this->applyContexts($conditions, $provided)) { return FALSE; } From a409d402aa53a7640ca12f8ce2209ccdf605b89a Mon Sep 17 00:00:00 2001 From: Lucas van Schaik Date: Mon, 20 Feb 2023 21:26:18 +0100 Subject: [PATCH 4/9] Make sure that the action is appropriate: either system or with same entity type --- src/PresetReaction/PresetReaction.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PresetReaction/PresetReaction.php b/src/PresetReaction/PresetReaction.php index e516eb24..532606fc 100644 --- a/src/PresetReaction/PresetReaction.php +++ b/src/PresetReaction/PresetReaction.php @@ -56,8 +56,8 @@ class PresetReaction extends ContextReactionPluginBase implements ContainerFacto $action_ids = $config['actions']; foreach ($action_ids as $action_id) { $action = $this->actionStorage->load($action_id); - // Make sure that the action is appropriate for the entity. - if ($entity->getEntityTypeId() === $action->getType()) { + // Make sure that the action is appropriate: either system or with same entity type. + if ($action->getType() === 'system' || $entity->getEntityTypeId() === $action->getType()) { $action->execute([$entity]); } } From aba5052308f994d47527e7daddd75854313060b9 Mon Sep 17 00:00:00 2001 From: Lucas van Schaik Date: Tue, 21 Feb 2023 08:06:00 +0100 Subject: [PATCH 5/9] Comment too long --- src/PresetReaction/PresetReaction.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PresetReaction/PresetReaction.php b/src/PresetReaction/PresetReaction.php index 532606fc..18a771dc 100644 --- a/src/PresetReaction/PresetReaction.php +++ b/src/PresetReaction/PresetReaction.php @@ -56,7 +56,8 @@ class PresetReaction extends ContextReactionPluginBase implements ContainerFacto $action_ids = $config['actions']; foreach ($action_ids as $action_id) { $action = $this->actionStorage->load($action_id); - // Make sure that the action is appropriate: either system or with same entity type. + // Make sure that the action is appropriate: + // either system action or with same type as the entity type. if ($action->getType() === 'system' || $entity->getEntityTypeId() === $action->getType()) { $action->execute([$entity]); } From b89da473f12f60a863c87bd49278fac91cfee749 Mon Sep 17 00:00:00 2001 From: Lucas van Schaik Date: Tue, 28 Feb 2023 10:09:18 +0100 Subject: [PATCH 6/9] Be consistent with context module, issue 3177007 --- src/IslandoraContextManager.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/IslandoraContextManager.php b/src/IslandoraContextManager.php index b3aec19c..11de1fde 100644 --- a/src/IslandoraContextManager.php +++ b/src/IslandoraContextManager.php @@ -50,7 +50,7 @@ class IslandoraContextManager extends ContextManager { // Apply context to any context aware conditions. // Abort if the application of contexts has been unsuccessful // similarly to BlockAccessControlHandler::checkAccess(). - if (count($conditions) > 0 && !$this->applyContexts($conditions, $provided)) { + if (!$this->applyContexts($conditions, $provided)) { return FALSE; } @@ -80,6 +80,12 @@ class IslandoraContextManager extends ContextManager { * TRUE if conditions pass */ protected function applyContexts(ConditionPluginCollection &$conditions, array $provided = []) { + + // If no contexts to check, the return should be TRUE. + // For example, empty is the same as sitewide condition. + if (count($conditions) === 0) { + return TRUE; + } $passed = FALSE; foreach ($conditions as $condition) { if ($condition instanceof ContextAwarePluginInterface) { From ee425d2c1fe82d8c25a8a1eeebae1ead01ae0cb1 Mon Sep 17 00:00:00 2001 From: Lucas van Schaik Date: Tue, 14 Mar 2023 11:16:48 +0100 Subject: [PATCH 7/9] Revert "Comment too long" This reverts commit aba5052308f994d47527e7daddd75854313060b9. --- src/PresetReaction/PresetReaction.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/PresetReaction/PresetReaction.php b/src/PresetReaction/PresetReaction.php index 18a771dc..532606fc 100644 --- a/src/PresetReaction/PresetReaction.php +++ b/src/PresetReaction/PresetReaction.php @@ -56,8 +56,7 @@ class PresetReaction extends ContextReactionPluginBase implements ContainerFacto $action_ids = $config['actions']; foreach ($action_ids as $action_id) { $action = $this->actionStorage->load($action_id); - // Make sure that the action is appropriate: - // either system action or with same type as the entity type. + // Make sure that the action is appropriate: either system or with same entity type. if ($action->getType() === 'system' || $entity->getEntityTypeId() === $action->getType()) { $action->execute([$entity]); } From 233a65d8714ecd4ba59d0b7b3f26c6c54136b991 Mon Sep 17 00:00:00 2001 From: Lucas van Schaik Date: Tue, 14 Mar 2023 11:18:22 +0100 Subject: [PATCH 8/9] Revert "Make sure that the action is appropriate: either system or with same entity type" This reverts commit a409d402aa53a7640ca12f8ce2209ccdf605b89a. --- src/PresetReaction/PresetReaction.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PresetReaction/PresetReaction.php b/src/PresetReaction/PresetReaction.php index 532606fc..e516eb24 100644 --- a/src/PresetReaction/PresetReaction.php +++ b/src/PresetReaction/PresetReaction.php @@ -56,8 +56,8 @@ class PresetReaction extends ContextReactionPluginBase implements ContainerFacto $action_ids = $config['actions']; foreach ($action_ids as $action_id) { $action = $this->actionStorage->load($action_id); - // Make sure that the action is appropriate: either system or with same entity type. - if ($action->getType() === 'system' || $entity->getEntityTypeId() === $action->getType()) { + // Make sure that the action is appropriate for the entity. + if ($entity->getEntityTypeId() === $action->getType()) { $action->execute([$entity]); } } From d041ec3bf55e5c32e5ac348da7d947d36365b038 Mon Sep 17 00:00:00 2001 From: Lucas van Schaik Date: Tue, 14 Mar 2023 11:18:30 +0100 Subject: [PATCH 9/9] Revert "Check if action is appropriate for entity before executing" This reverts commit 87f475d81c0bca3793c9f3bdc6cf8def4f31ef6b. --- src/PresetReaction/PresetReaction.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/PresetReaction/PresetReaction.php b/src/PresetReaction/PresetReaction.php index e516eb24..98aa6946 100644 --- a/src/PresetReaction/PresetReaction.php +++ b/src/PresetReaction/PresetReaction.php @@ -56,10 +56,7 @@ class PresetReaction extends ContextReactionPluginBase implements ContainerFacto $action_ids = $config['actions']; foreach ($action_ids as $action_id) { $action = $this->actionStorage->load($action_id); - // Make sure that the action is appropriate for the entity. - if ($entity->getEntityTypeId() === $action->getType()) { - $action->execute([$entity]); - } + $action->execute([$entity]); } }