Skip to content

Commit

Permalink
Merge branch 'next' into FOUR-9465
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanpro committed Sep 29, 2023
2 parents ad7f935 + 87a28c9 commit 5007fbd
Show file tree
Hide file tree
Showing 130 changed files with 6,125 additions and 767 deletions.
1 change: 1 addition & 0 deletions ProcessMaker/Console/Commands/BuildScriptExecutors.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public function buildExecutor()
$success = $this->associateWithExistingImage($scriptExecutor);
if ($success) {
$this->info('Docker Image Associated');

// we associated with an existing image, no need to build
return;
} else {
Expand Down
25 changes: 25 additions & 0 deletions ProcessMaker/Enums/ExporterMap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace ProcessMaker\Enums;

enum ExporterMap
{
const TYPES = [
'screen' => [\ProcessMaker\Models\Screen::class, \ProcessMaker\ImportExport\Exporters\ScreenExporter::class],
'process' => [\ProcessMaker\Models\Process::class, \ProcessMaker\ImportExport\Exporters\ProcessExporter::class],
'script' => [\ProcessMaker\Models\Script::class, \ProcessMaker\ImportExport\Exporters\ScriptExporter::class],
'process_templates' => [\ProcessMaker\Models\ProcessTemplates::class, \ProcessMaker\ImportExport\Exporters\TemplateExporter::class],
'data_source' => [\ProcessMaker\Packages\Connectors\DataSources\Models\DataSource::class, \ProcessMaker\Packages\Connectors\DataSources\ImportExport\DataSourceExporter::class],
'decision_table' => [\ProcessMaker\Package\PackageDecisionEngine\Models\DecisionTable::class, \ProcessMaker\Package\PackageDecisionEngine\ImportExport\DecisionTableExporter::class],
];

public static function getModelClass(string $type): ?string
{
return self::TYPES[$type][0] ?? null;
}

public static function getExporterClass(string $type): ?string
{
return self::TYPES[$type][1] ?? null;
}
}
16 changes: 16 additions & 0 deletions ProcessMaker/Helpers/MobileHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace ProcessMaker\Helpers;

class MobileHelper
{
public static function isMobile($userAgent)
{
$device = '/(Mobile|Android|Tablet|GoBrowser|[0-9]x[0-9]*|uZardWeb\/|Mini|Doris\/|Skyfire\/|iPhone|Fennec\/|Maemo|Iris\/|CLDC\-|Mobi\/)/uis';
if (preg_match($device, $userAgent) && !empty($_COOKIE['isMobile']) && $_COOKIE['isMobile'] === 'true') {
return true;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function index(Request $request)
} else {
$environment_variables = EnvironmentVariable::orderBy($orderBy, $orderDirection)->paginate($perPage);
}

// Return fractal representation of paged data
return new ApiCollection($environment_variables);
}
Expand Down
44 changes: 5 additions & 39 deletions ProcessMaker/Http/Controllers/Api/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,14 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use ProcessMaker\Enums\ExporterMap;
use ProcessMaker\Exception\ExportModelNotFoundException;
use ProcessMaker\Http\Controllers\Controller;
use ProcessMaker\ImportExport\Exporter;
use ProcessMaker\ImportExport\Exporters\ProcessExporter;
use ProcessMaker\ImportExport\Exporters\ScreenExporter;
use ProcessMaker\ImportExport\Exporters\ScriptExporter;
use ProcessMaker\ImportExport\Exporters\TemplateExporter;
use ProcessMaker\ImportExport\Options;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessTemplates;
use ProcessMaker\Models\Screen;
use ProcessMaker\Models\Script;
use ProcessMaker\PackageHelper;

class ExportController extends Controller
{
const DATA_SOURCE_CLASS = 'ProcessMaker\Packages\Connectors\DataSources\Models\DataSource';

const DATA_SOURCE_EXPORTER_CLASS = 'ProcessMaker\Packages\Connectors\DataSources\ImportExport\DataSourceExporter';

const DECISION_TABLE_CLASS = 'ProcessMaker\Package\PackageDecisionEngine\Models\DecisionTable';

const DECISION_TABLE_EXPORTER_CLASS = 'ProcessMaker\Package\PackageDecisionEngine\ImportExport\DecisionTableExporter';

protected array $types = [
'screen' => [Screen::class, ScreenExporter::class],
'process' => [Process::class, ProcessExporter::class],
'script' => [Script::class, ScriptExporter::class],
'process_templates' => [ProcessTemplates::class, TemplateExporter::class],
];

public function __construct()
{
if (PackageHelper::isPackageInstalled(self::DATA_SOURCE_CLASS)) {
$this->types['data_source'] = [self::DATA_SOURCE_CLASS, self::DATA_SOURCE_EXPORTER_CLASS];
}
if (PackageHelper::isPackageInstalled(self::DECISION_TABLE_CLASS)) {
$this->types['decision_table'] = [self::DECISION_TABLE_CLASS, self::DECISION_TABLE_EXPORTER_CLASS];
}
}

/**
* Return only the manifest
*/
Expand All @@ -55,7 +22,7 @@ public function manifest(string $type, int $id): JsonResponse
$model = $this->getModel($type)->findOrFail($id);
try {
$exporter = new Exporter(true);
$exporter->export($model, $this->types[$type][1]);
$exporter->export($model, ExporterMap::getExporterClass($type));

return response()->json($exporter->payload(true), 200);
} catch (ExportModelNotFoundException $error) {
Expand All @@ -74,7 +41,7 @@ public function download(Request $request, string $type, int $id)
$password = (isset($post['password']) ? $post['password'] : null);

$exporter = new Exporter();
$exporter->export($model, $this->types[$type][1], $options);
$exporter->export($model, ExporterMap::getExporterClass($type), $options);

$payload = $exporter->payload();

Expand Down Expand Up @@ -111,9 +78,8 @@ function () use ($payload) {

public function getModel(string $type): Model
{
if (isset($this->types[$type])) {
$modelClass = current($this->types[$type]);

$modelClass = ExporterMap::getModelClass($type);
if ($modelClass) {
return new $modelClass;
}
throw new Exception("Type {$type} not found", 404);
Expand Down
5 changes: 5 additions & 0 deletions ProcessMaker/Http/Controllers/Api/ScreenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ public function index(Request $request)
return response(['message' => __('Your PMQL contains invalid syntax.')], 400);
}
}

if ($request->has('key')) {
$query->where('key', $request->get('key'));
}

$response =
$query->orderBy(
$request->input('order_by', 'title'),
Expand Down
6 changes: 5 additions & 1 deletion ProcessMaker/Http/Controllers/Api/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ public function index(Request $request, $getTotal = false, User $user = null)

//list only display elements type task
$nonSystem = filter_var($request->input('non_system'), FILTER_VALIDATE_BOOLEAN);
$query->where('element_type', '=', 'task')
$query->where(function ($query) {
$query->where('element_type', '=', 'task');
$query->orWhere('element_type', '=', 'serviceTask');
$query->where('element_name', '=', 'AI Assistant');
})
->when($nonSystem, function ($query) {
$query->nonSystem();
});
Expand Down
2 changes: 2 additions & 0 deletions ProcessMaker/Http/Controllers/Api/TemplateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ public function create(string $type, Request $request)
$response = $this->template->create($type, $request);
}
} elseif ($type === 'update-assets') {
$request['request'] = json_decode($request['request'], true);
$request['existingAssets'] = json_decode($request['existingAssets'], true);
$request->validate([
'id' => 'required|numeric',
'request' => 'required|array',
Expand Down
26 changes: 26 additions & 0 deletions ProcessMaker/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use ProcessMaker\Events\Logout;
use ProcessMaker\Http\Controllers\Controller;
use ProcessMaker\Managers\LoginManager;
use ProcessMaker\Models\Setting;
use ProcessMaker\Models\User;
use ProcessMaker\Traits\HasControllerAddons;

Expand Down Expand Up @@ -55,6 +56,24 @@ public function showLoginForm()
{
$manager = App::make(LoginManager::class);
$addons = $manager->list();
$default = Setting::where('key', 'sso.default.login')->first();
$arrayAddons = $addons->toArray();
// Redirectind to default login
if (!empty($default) && !empty($arrayAddons)) {
$position = $default->getAttribute('config'); // Type int
$data = head($arrayAddons)->data ?? [];
$drivers = array_key_exists('drivers', $data) ? $data['drivers'] : [];
if (isset($position) && !empty($drivers)) {
$elements = $default->getAttribute('ui')->elements;
if (count($elements) >= $position + 1) {
$element = $elements[$position];
if (array_key_exists(strtolower($element->name), $drivers)) {
return redirect()->route('sso.redirect', ['driver' => strtolower($element->name)]);
}
}
}
}

$block = $manager->getBlock();
// clear cookie to avoid an issue when logout SLO and then try to login with simple PM login form
\Cookie::queue(\Cookie::forget(config('session.cookie')));
Expand Down Expand Up @@ -96,6 +115,13 @@ public function loginWithIntendedCheck(Request $request)
}
}

if (class_exists(\ProcessMaker\Package\Auth\Auth\LDAPLogin::class)) {
$redirect = \ProcessMaker\Package\Auth\Auth\LDAPLogin::auth($user, $request->input('password'));
if ($redirect !== false) {
return $redirect;
}
}

return $this->login($request);
}

Expand Down
48 changes: 48 additions & 0 deletions ProcessMaker/Http/Controllers/Designer/DesignerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace ProcessMaker\Http\Controllers\Designer;

use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use ProcessMaker\Http\Controllers\Controller;
use ProcessMaker\Traits\HasControllerAddons;

class DesignerController extends Controller
{
use HasControllerAddons;

/**
* Get initial data for Designer Home Page
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index(Request $request)
{
$redirect = $this->checkAuth();
if ($redirect) {
return redirect()->route($redirect);
}

return view('designer.index');
}

private function checkAuth()
{
$perm = 'view-processes|view-process-categories|view-scripts|view-screens|view-environment_variables';
switch (Auth::user()->canAnyFirst($perm)) {
case 'view-processes':
return false; // already on index, continue with it
case 'view-process-categories':
return 'process-categories.index';
case 'view-scripts':
return 'scripts.index';
case 'view-screens':
return 'screens.index';
case 'view-environment_variables':
return 'environment-variables.index';
default:
throw new AuthorizationException();
}
}
}
1 change: 1 addition & 0 deletions ProcessMaker/Http/Controllers/Designer/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function show(Process $process = null, Form $form = null)
{
if ($process->id !== $form->process_id) {
request()->session()->flash('_alert', json_encode(['danger', __('The form does not belong to process.')]));

// @todo This should actually redirect to designer url
return view('designer.designer', compact('process'));
}
Expand Down
52 changes: 52 additions & 0 deletions ProcessMaker/Http/Controllers/Process/ModelerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
use ProcessMaker\Managers\ModelerManager;
use ProcessMaker\Managers\SignalManager;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessCategory;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Package\PackagePmBlocks\Http\Controllers\Api\PmBlockController;
use ProcessMaker\Models\ScreenCategory;
use ProcessMaker\Models\ScreenType;
use ProcessMaker\Models\ScriptCategory;
use ProcessMaker\Models\ScriptExecutor;
use ProcessMaker\PackageHelper;
use ProcessMaker\Traits\HasControllerAddons;
use ProcessMaker\Traits\ProcessMapTrait;
Expand All @@ -24,13 +30,31 @@ class ModelerController extends Controller
*/
public function show(ModelerManager $manager, Process $process, Request $request)
{
$pmBlockList = $this->getPmBlockList();

/*
* Emit the ModelerStarting event, passing in our ModelerManager instance. This will
* allow packages to add additional javascript for modeler initialization which
* can customize the modeler controls list.
*/
event(new ModelerStarting($manager));

// For create subprocess modal in modeler
$countProcessCategories = ProcessCategory::where(['status' => 'ACTIVE', 'is_system' => false])->count();

// For create screen modal in modeler
$screenTypes = [];
foreach (ScreenType::pluck('name')->toArray() as $type) {
$screenTypes[$type] = __(ucwords(strtolower($type)));
}
asort($screenTypes);
$countScreenCategories = ScreenCategory::where(['status' => 'ACTIVE', 'is_system' => false])->count();
$isProjectsInstalled = PackageHelper::isPackageInstalled(PackageHelper::PM_PACKAGE_PROJECTS);

// For create script modal in modeler
$scriptExecutors = ScriptExecutor::list();
$countScriptCategories = ScriptCategory::where(['status' => 'ACTIVE', 'is_system' => false])->count();

$draft = $process->versions()->draft()->first();
if ($draft) {
$process->fill($draft->only(['svg', 'bpmn']));
Expand All @@ -43,6 +67,13 @@ public function show(ModelerManager $manager, Process $process, Request $request
'autoSaveDelay' => config('versions.delay.process', 5000),
'isVersionsInstalled' => PackageHelper::isPackageInstalled('ProcessMaker\Package\Versions\PluginServiceProvider'),
'isDraft' => $draft !== null,
'pmBlockList' => $pmBlockList,
'screenTypes' => $screenTypes,
'scriptExecutors' => $scriptExecutors,
'countProcessCategories' => $countProcessCategories,
'countScreenCategories' => $countScreenCategories,
'countScriptCategories' => $countScriptCategories,
'isProjectsInstalled' => $isProjectsInstalled,
]);
}

Expand All @@ -51,6 +82,8 @@ public function show(ModelerManager $manager, Process $process, Request $request
*/
public function inflight(ModelerManager $manager, Process $process, ProcessRequest $request)
{
$pmBlockList = $this->getPmBlockList();

event(new ModelerStarting($manager));

$bpmn = $process->bpmn;
Expand Down Expand Up @@ -91,9 +124,28 @@ public function inflight(ModelerManager $manager, Process $process, ProcessReque
'requestInProgressNodes' => $requestInProgressNodes,
'requestIdleNodes' => $requestIdleNodes,
'requestId' => $request->id,
'pmBlockList' => $pmBlockList,
]);
}

/**
* Load PMBlock list
*/
private function getPmBlockList()
{
$pmBlockList = null;
if (hasPackage('package-pm-blocks')) {
$controller = new PmBlockController();
$newRequest = new Request(['per_page' => 10000]);
$response = $controller->index($newRequest);
if ($response->response($newRequest)->status() === 200) {
$pmBlockList = json_decode($response->response()->content())->data;
}
}

return $pmBlockList;
}

/**
* Invokes the Modeler for In-flight Process Map rendering for ai generative.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ScreenBuilderController extends Controller
*
* @return Factory|View
*/
public function edit(ScreenBuilderManager $manager, Screen $screen)
public function edit(ScreenBuilderManager $manager, Screen $screen, $processId = null)
{
/**
* Emit the ModelerStarting event, passing in our ModelerManager instance. This will
Expand All @@ -44,6 +44,7 @@ public function edit(ScreenBuilderManager $manager, Screen $screen)
'autoSaveDelay' => config('versions.delay.process', 5000),
'isVersionsInstalled' => PackageHelper::isPmPackageVersionsInstalled(),
'isDraft' => $draft !== null,
'processId' => $processId,
]);
}
}
Loading

0 comments on commit 5007fbd

Please sign in to comment.