new: [workflow:baseModule] Added diagnostic support and support of arbitrary URL for webhook module

pull/8574/head
Sami Mokaddem 2022-09-08 15:42:11 +02:00
parent 5ce142ed0f
commit f479cc858a
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
4 changed files with 42 additions and 1 deletions

View File

@ -785,6 +785,11 @@ class Workflow extends AppModel
];
}
}
if ($moduleType == 'modules_action') {
$moduleClass = $this->getModuleClassByType('action', $module['id']);
$diagnostic = $moduleClass->diagnostic();
$modules[$moduleType][$i]['notifications'] = array_merge_recursive($modules[$moduleType][$i]['notifications'], $diagnostic);
}
}
}
return $modules;

View File

@ -209,6 +209,23 @@ class WorkflowBaseModule
}
return $items;
}
protected function addNotification(array $errors, string $severity, string $text, string $description='', array $details=[], bool $showInSidebar=false, bool $showInNode=false): array
{
$errors[$severity][] = [
'text' => $text,
'description' => $description,
'details' => $details,
'__show_in_sidebar' => $showInSidebar,
'__show_in_node' => $showInNode,
];
return $errors;
}
public function diagnostic(): array
{
return [];
}
}
class WorkflowBaseTriggerModule extends WorkflowBaseModule

View File

@ -48,6 +48,25 @@ class Module_webhook extends WorkflowBaseActionModule
];
}
public function diagnostic(): array
{
$errors = array_merge(parent::diagnostic(), []);
if (empty(Configure::read('Security.rest_client_enable_arbitrary_urls'))) {
$errors = $this->addNotification(
$errors,
'error',
__('`rest_client_enable_arbitrary_urls` is turned off.'),
__('The module will not send any request as long as `Security.rest_client_enable_arbitrary_urls` is not turned on.'),
[
__('This is a security measure to ensure a site-admin do not send arbitrary request to internal services')
],
true,
true
);
}
return $errors;
}
public function exec(array $node, WorkflowRoamingData $roamingData, array &$errors = []): bool
{
parent::exec($node, $roamingData, $errors);

View File

@ -28,7 +28,7 @@ $classFromSeverity = [
<?php foreach (array_keys($classFromSeverity) as $severity) : ?>
<?php
$visibleNotifications = array_filter($block['notifications'][$severity], function ($notification) {
return $notification['__show_in_sidebar'];
return !empty($notification['__show_in_sidebar']);
});
?>
<?php if (!empty($visibleNotifications)) : ?>