Skip to content

Commit

Permalink
Issue #3369035: Notification entity conditions can not rely on other …
Browse files Browse the repository at this point in the history
…template configuration

Entity conditions are executed in ActivityLoggerFactory::createMessages
before some of the other checks are evaluated. This can cause an entity
condition that may only be usable on specific bundles to be called on
other data.

We re-order the checks so that we check for matching properties first
and only at the end execute the more expensive entity condition plugins.
This also makes it easier to move the conditions into a database query
when we move into a different configuration structure in the future.
  • Loading branch information
Kingdutch committed Jun 23, 2023
1 parent 97f6174 commit 6cb327a
Showing 1 changed file with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,40 +168,46 @@ public function getMessageTypes($action, EntityBase $entity) {

// Check all enabled messages.
foreach ($message_storage->loadByProperties(['status' => '1']) as $key => $messagetype) {
$mt_entity_bundles = $messagetype->getThirdPartySetting('activity_logger', 'activity_bundle_entities', NULL);
$mt_entity_bundles = $messagetype->getThirdPartySetting('activity_logger', 'activity_bundle_entities', []);
$mt_action = $messagetype->getThirdPartySetting('activity_logger', 'activity_action', NULL);
$mt_context = $messagetype->getThirdPartySetting('activity_logger', 'activity_context', NULL);
$mt_destinations = $messagetype->getThirdPartySetting('activity_logger', 'activity_destinations', NULL);
$mt_entity_condition = $messagetype->getThirdPartySetting('activity_logger', 'activity_entity_condition', NULL);

if (!empty($mt_entity_condition)
if ($mt_action !== $action) {
continue;
}

$entity_bundle_name = $entity->getEntityTypeId() . '-' . $entity->bundle();
if (!in_array($entity_bundle_name, $mt_entity_bundles, TRUE)) {
continue;
}

if (!$this->activityContextManager->hasDefinition($mt_context)) {
continue;
}

if (
!empty($mt_entity_condition)
&& $this->activityEntityConditionManager->hasDefinition($mt_entity_condition)
&& !$this->activityEntityConditionManager
->createInstance($mt_entity_condition)
->isValidEntityCondition($entity)
) {
$entity_condition_plugin = $this->activityEntityConditionManager->createInstance($mt_entity_condition);
$entity_condition = $entity_condition_plugin->isValidEntityCondition($entity);
}
else {
$entity_condition = TRUE;
continue;
}

if ($this->activityContextManager->hasDefinition($mt_context)) {
$context_plugin = $this->activityContextManager->createInstance($mt_context);

$entity_bundle_name = $entity->getEntityTypeId() . '-' . $entity->bundle();
if (in_array($entity_bundle_name, $mt_entity_bundles)
&& $context_plugin->isValidEntity($entity)
&& $entity_condition
&& $action === $mt_action
) {
$messagetypes[$key] = [
'messagetype' => $messagetype,
'bundle' => $entity_bundle_name,
'destinations' => $mt_destinations,
'context' => $mt_context,
];
}
$context_plugin = $this->activityContextManager->createInstance($mt_context);
if ($context_plugin->isValidEntity($entity)) {
$messagetypes[$key] = [
'messagetype' => $messagetype,
'bundle' => $entity_bundle_name,
'destinations' => $mt_destinations,
'context' => $mt_context,
];
}
}

// Return the message types that belong to the requested action.
return $messagetypes;
}
Expand Down

0 comments on commit 6cb327a

Please sign in to comment.