Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
f04ed05
feat: add alternative b and publish to deploy-process
devmiguelangel Nov 24, 2026
154fea6
feat: enhance DeployScript to support script executor validation and …
devmiguelangel Nov 24, 2026
135d400
feat: add process notification settings and enhance process update fu…
devmiguelangel Nov 24, 2026
976da9a
feat: implement group creation and process inventory tools with enhan…
devmiguelangel Nov 24, 2026
a640c4c
feat: enhance screen validation to include info notes for small nativ…
devmiguelangel Nov 24, 2026
11a0d15
feat: add functionality to include empty inspector metadata in screen…
devmiguelangel Nov 24, 2026
d36b57b
feat: refactor saveDeployedProcess method to improve readability and …
devmiguelangel Nov 25, 2026
805d2bb
feat: implement authorization checks for script executor binding in D…
devmiguelangel Nov 25, 2026
7953756
refactor: streamline executor binding denial logic in DeployScript fo…
devmiguelangel Nov 26, 2026
65bda70
refactor: introduce rejection handling for deploy requests in DeployS…
devmiguelangel Nov 26, 2026
0c9f19c
feat: enforce two-factor authentication policy during group creation …
devmiguelangel Nov 26, 2026
093d190
Merge remote-tracking branch 'origin/feature/FOUR-34328' into FOUR-34373
devmiguelangel Nov 26, 2026
a762104
feat: implement case title sanitization and enhance process inventory…
devmiguelangel Nov 26, 2026
ac488c4
refactor: remove unused publishedPluginScriptWebPath method from Scre…
devmiguelangel Nov 27, 2026
12a7ff7
fix: handle empty git repository scenario in PluginManager and update…
devmiguelangel Nov 27, 2026
4044352
fix: improve error handling for empty git repositories in PluginManager
devmiguelangel Nov 27, 2026
45434a8
test: add clone-origin-test plugin directory to PluginManagerTest
devmiguelangel Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ProcessMaker/Exception/PluginInstallException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ProcessMaker\Exception;

use ProcessMaker\Managers\PluginManager;
use RuntimeException;

class PluginInstallException extends RuntimeException
Expand Down Expand Up @@ -45,4 +46,9 @@ public static function failedToCopyFile(string $srcPath, string $destPath): self
{
return new self("Failed to copy file: {$srcPath} to {$destPath}");
}
}

public static function emptyRepository(): self
{
return new self(PluginManager::EMPTY_REPOSITORY_MESSAGE);
}
}
85 changes: 65 additions & 20 deletions ProcessMaker/Http/Controllers/Api/DeployProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
use ProcessMaker\Exception\MissingBpmnReferenceException;
use ProcessMaker\Http\Controllers\Api\Concerns\AppliesDeployVersionName;
use ProcessMaker\Http\Controllers\Controller;
use ProcessMaker\Models\Process;
use ProcessMaker\Services\DeployCategoryResolver;
use ProcessMaker\Services\DeployProcessAlternativeB;
use ProcessMaker\Services\ProcessBpmnReferenceService;
use Throwable;

Expand All @@ -34,15 +36,18 @@ class DeployProcess extends Controller
public function __construct(
private readonly ProcessBpmnReferenceService $references,
private readonly DeployCategoryResolver $categories,
private readonly DeployProcessAlternativeB $alternativeB,
) {
}

public function deployProcess(Request $request): JsonResponse
{
$name = (string) $request->input('name');
$isUpdate = Process::where('name', $name)->exists();
// Alternative B writes drafts or B versions, not asset version history.
$needsVersionName = $isUpdate && !$this->targetsAlternativeB($request);

if ($unavailable = $this->ensureDeployVersionHistoryAvailable($isUpdate)) {
if ($unavailable = $this->ensureDeployVersionHistoryAvailable($needsVersionName)) {
return $unavailable;
}

Expand All @@ -53,7 +58,9 @@ public function deployProcess(Request $request): JsonResponse
'name' => 'required|string|max:255',
'description' => 'nullable|string|max:65535',
'process_category_name' => 'nullable|string|max:255',
], $isUpdate),
'alternative' => 'nullable|in:A,B',
'publish' => 'nullable|boolean',
], $needsVersionName),
);

if ($validator->fails()) {
Expand All @@ -69,29 +76,59 @@ public function deployProcess(Request $request): JsonResponse
private function saveDeployedProcess(Request $request): JsonResponse
{
try {
$bpmn = $this->references->resolveNamedReferences($request->input('bpmn'));
$xmlErrors = $this->validateXml($bpmn);
if ($xmlErrors !== []) {
return response()->json([
'success' => false,
'message' => 'Invalid BPMN XML.',
'errors' => ['bpmn' => $xmlErrors],
], 422);
}

[$process, $created] = $this->upsertProcessByName($request, $bpmn);

return response()->json([
'success' => true,
'action' => $created ? 'created' : 'updated',
'process_id' => $process->id,
'name' => $process->name,
]);
return $this->deployFromRequest($request);
} catch (Throwable $exception) {
return $this->deployProcessFailureResponse($exception);
}
}

private function deployFromRequest(Request $request): JsonResponse
{
$bpmn = $this->references->resolveNamedReferences($request->input('bpmn'));
$xmlErrors = $this->validateXml($bpmn);
if ($xmlErrors !== []) {
return response()->json([
'success' => false,
'message' => 'Invalid BPMN XML.',
'errors' => ['bpmn' => $xmlErrors],
], 422);
}

if ($this->targetsAlternativeB($request)) {
return $this->saveDeployedAlternativeB($request, $bpmn);
}

[$process, $created] = $this->upsertProcessByName($request, $bpmn);

return response()->json([
'success' => true,
'action' => $created ? 'created' : 'updated',
'process_id' => $process->id,
'name' => $process->name,
]);
}

private function targetsAlternativeB(Request $request): bool
{
return $request->input('alternative') === 'B';
}

private function saveDeployedAlternativeB(Request $request, string $bpmn): JsonResponse
{
$process = Process::where('name', $request->input('name'))->first();
$publish = $request->boolean('publish');
$result = $this->alternativeB->deploy($process, $bpmn, $publish);

return response()->json([
'success' => true,
'action' => $publish ? 'published' : 'draft',
'alternative' => 'B',
'process_id' => $process->id,
'name' => $process->name,
'process_version_id' => $result['version_id'],
]);
}

/**
* @return array{0: Process, 1: bool}
*/
Expand Down Expand Up @@ -144,6 +181,14 @@ private function upsertProcessByName(Request $request, string $bpmn): array

private function deployProcessFailureResponse(Throwable $exception): JsonResponse
{
if ($exception instanceof ValidationException) {
return response()->json([
'success' => false,
'message' => collect($exception->errors())->flatten()->first(),
'errors' => $exception->errors(),
], 422);
}

if ($exception instanceof MissingBpmnReferenceException) {
return response()->json([
'success' => false,
Expand Down
43 changes: 42 additions & 1 deletion ProcessMaker/Http/Controllers/Api/DeployScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function getScreenYaml(Request $request)
}

[$screen, $screenVersion] = $resolved;
$config = $this->removeInspectorMetadata($screenVersion->config ?? []);
$config = $this->withEmptyInspector($this->removeInspectorMetadata($screenVersion->config ?? []));
$data = [
'config' => $config,
'computed' => $screenVersion->computed,
Expand All @@ -148,6 +148,47 @@ public function getScreenYaml(Request $request)
->header('X-Screen-Name', $screen->title);
}

/**
* The export drops the (large) inspector metadata, but the YAML contract expects every
* item to carry `inspector: []`, so a pulled screen can be pushed back unchanged.
*
* @param array<int, mixed> $config
* @return array<int, mixed>
*/
private function withEmptyInspector(array $config): array
{
foreach ($config as $index => $page) {
if (is_array($page) && isset($page['items']) && is_array($page['items'])) {
$config[$index]['items'] = $this->addEmptyInspector($page['items']);
}
}

return $config;
}

/**
* @param array<int|string, mixed> $items
* @return array<int|string, mixed>
*/
private function addEmptyInspector(array $items): array
{
foreach ($items as $index => $item) {
if (!is_array($item)) {
continue;
}
if (isset($item['component']) && !array_key_exists('inspector', $item)) {
$item['inspector'] = [];
}
if (isset($item['items']) && is_array($item['items'])) {
$item['items'] = $this->addEmptyInspector($item['items']);
}
// A FormMultiColumn holds a list of columns, and each column is a list of items.
$items[$index] = array_is_list($item) && $item !== [] ? $this->addEmptyInspector($item) : $item;
}

return $items;
}

/**
* @return array{0: Screen, 1: object}|JsonResponse
*/
Expand Down
108 changes: 106 additions & 2 deletions ProcessMaker/Http/Controllers/Api/DeployScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use ProcessMaker\Http\Controllers\Api\Concerns\AppliesDeployVersionName;
use ProcessMaker\Http\Controllers\Controller;
use ProcessMaker\Models\Script;
use ProcessMaker\Models\ScriptExecutor;
use ProcessMaker\Models\User;
use ProcessMaker\Services\DeployCategoryResolver;
use ProcessMaker\Services\ScriptExecutorResolver;

Expand Down Expand Up @@ -47,6 +49,17 @@ public function deployScript(Request $request): JsonResponse
$name = (string) $request->input('name');
$isUpdate = Script::where('title', $name)->exists();

$rejection = $this->rejectDeployRequest($request, $name, $isUpdate);

return $rejection ?? $this->persistDeployedScript($request, $name);
}

/**
* Return the response that stops a deploy (version history unavailable,
* validation failure, or forbidden executor binding), or null to proceed.
*/
private function rejectDeployRequest(Request $request, string $name, bool $isUpdate): ?JsonResponse
{
if ($unavailable = $this->ensureDeployVersionHistoryAvailable($isUpdate)) {
return $unavailable;
}
Expand All @@ -58,8 +71,11 @@ public function deployScript(Request $request): JsonResponse
'name' => 'required|string',
'description' => 'nullable|string|max:65535',
'script_category_name' => 'nullable|string|max:255',
'script_executor_id' => 'nullable|integer',
'script_executor_title' => 'nullable|string|max:255',
], $isUpdate),
);
$validator->after(fn ($validator) => $this->validateRequestedExecutor($request, $validator));

if ($validator->fails()) {
return response()->json([
Expand All @@ -68,17 +84,100 @@ public function deployScript(Request $request): JsonResponse
], 422);
}

return $this->persistDeployedScript($request, $name);
return $this->denyUnauthorizedExecutorBinding($request, $name);
}

/**
* Binding a script to an executor needs the same rights as the regular script
* routes: edit-scripts, and an administrator for any executor other than the
* default one (or any custom executor). Requests that name no executor, and
* requests that keep the executor a script already has, are not restricted.
*/
private function denyUnauthorizedExecutorBinding(Request $request, string $name): ?JsonResponse
{
$requested = $this->requestedExecutor($request);
$message = $requested === null
? null
: $this->executorBindingDenialMessage($request->user(), $requested, $name);

if ($message === null) {
return null;
}

return response()->json([
'success' => false,
'message' => $message,
], 403);
}

/**
* Return why the user may not bind the script to the requested executor,
* or null when the binding is allowed.
*/
private function executorBindingDenialMessage(User $user, ScriptExecutor $requested, string $name): ?string
{
if ($user->is_administrator || $this->keepsCurrentExecutor($name, $requested)) {
return null;
}

if (!$user->can('edit-scripts')) {
return 'You are not allowed to choose a script executor.';
}

return $this->executors->isDefaultForNonAdmins($requested)
? null
: 'Only administrators can use this script executor.';
}

private function keepsCurrentExecutor(string $name, ScriptExecutor $requested): bool
{
$current = Script::where('title', $name)->value('script_executor_id');

return $current !== null && (int) $current === $requested->id;
}

private function requestedExecutor(Request $request): ?ScriptExecutor
{
$id = $request->input('script_executor_id');

return $this->executors->findRequested(
$id === null || $id === '' ? null : (int) $id,
$request->input('script_executor_title'),
);
}

private function validateRequestedExecutor(Request $request, \Illuminate\Validation\Validator $validator): void
{
$field = $request->filled('script_executor_id') ? 'script_executor_id' : 'script_executor_title';
if (!$request->filled($field)) {
return;
}

$executor = $this->requestedExecutor($request);
if ($executor === null) {
$validator->errors()->add($field, 'The selected script executor does not exist.');

return;
}
if ($executor->language !== ScriptExecutorResolver::DEPLOY_LANGUAGE) {
$validator->errors()->add($field, sprintf(
'Script executor "%s" runs %s; deploy-script needs a %s executor.',
$executor->title,
$executor->language,
ScriptExecutorResolver::DEPLOY_LANGUAGE,
));
}
}

private function persistDeployedScript(Request $request, string $name): JsonResponse
{
$code = $request->input('code');
$script = Script::where('title', $name)->first();
$created = $script === null;
$requestedExecutor = $this->requestedExecutor($request);

if ($created) {
$executor = $this->executors->resolveForNewScript();
$executor = $requestedExecutor ?? $this->executors->resolveForNewScript();
if ($executor === null) {
return response()->json([
'success' => false,
Expand All @@ -97,6 +196,11 @@ private function persistDeployedScript(Request $request, string $name): JsonResp
$script->retry_wait_time = self::DEFAULT_RETRY_WAIT_TIME;
}

if (!$created && $requestedExecutor !== null) {
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
$script->script_executor_id = $requestedExecutor->id;
$script->language = $requestedExecutor->language;
}

if (!$created && $request->has('description')) {
$script->description = $this->deployScriptDescription($request, $name);
}
Expand Down
8 changes: 7 additions & 1 deletion ProcessMaker/Managers/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ private function cloneRepositoryForInstall(
$this->markNewInstallForRollback($pluginPath);
$this->cloneRepository($authenticatedRepoUrl, $pluginPath, $repoName, $userId, $repoUrl);

// An empty remote has no branch or tag to check out: report that instead of a git checkout error.
if (($branch || $tag) && $this->isEmptyGitRepository($pluginPath)) {
$this->logError(self::EMPTY_REPOSITORY_MESSAGE, $repoName, $userId);
throw PluginInstallException::emptyRepository();
}

if ($branch) {
$this->logRunning("Checking out branch: {$branch}", $repoName, $userId);
$this->checkoutBranch($pluginPath, $branch, $repoName, $userId);
Expand Down Expand Up @@ -1032,7 +1038,7 @@ protected function validatePlugin(string $pluginPath, string $repoName, ?int $us
if (!file_exists($composerJsonPath)) {
if ($this->isEmptyGitRepository($pluginPath) || $this->hasOnlyPlaceholderFiles($pluginPath)) {
$this->logError(self::EMPTY_REPOSITORY_MESSAGE, $repoName, $userId);
throw new RuntimeException(self::EMPTY_REPOSITORY_MESSAGE);
throw PluginInstallException::emptyRepository();
}

$this->logError('composer.json not found in plugin: ' . $pluginPath, $repoName, $userId);
Expand Down
Loading
Loading