Skip to content

Commit db8b2d5

Browse files
committed
Merge branch 'next' into feature/FOUR-9709
2 parents 71b98ea + f62189a commit db8b2d5

143 files changed

Lines changed: 6307 additions & 781 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ProcessMaker/Console/Commands/BuildScriptExecutors.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public function buildExecutor()
110110
$success = $this->associateWithExistingImage($scriptExecutor);
111111
if ($success) {
112112
$this->info('Docker Image Associated');
113+
113114
// we associated with an existing image, no need to build
114115
return;
115116
} else {

ProcessMaker/Contracts/WorkflowManagerInterface.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,19 @@ public function existsServiceImplementation($implementation);
178178
/**
179179
* Run the service task implementation
180180
* @param string $implementation
181-
* @param array $dat
181+
* @param array $data
182182
* @param array $config
183183
* @param string $tokenId
184184
*
185185
* @return mixed
186186
*/
187187
public function runServiceImplementation($implementation, array $data, array $config, $tokenId = '');
188+
189+
/**
190+
* Get the service task class implementation
191+
*
192+
* @param string $implementation
193+
* @return string
194+
*/
195+
public function getServiceClassImplementation($implementation);
188196
}

ProcessMaker/Enums/ExporterMap.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace ProcessMaker\Enums;
4+
5+
enum ExporterMap
6+
{
7+
const TYPES = [
8+
'screen' => [\ProcessMaker\Models\Screen::class, \ProcessMaker\ImportExport\Exporters\ScreenExporter::class],
9+
'process' => [\ProcessMaker\Models\Process::class, \ProcessMaker\ImportExport\Exporters\ProcessExporter::class],
10+
'script' => [\ProcessMaker\Models\Script::class, \ProcessMaker\ImportExport\Exporters\ScriptExporter::class],
11+
'process_templates' => [\ProcessMaker\Models\ProcessTemplates::class, \ProcessMaker\ImportExport\Exporters\TemplateExporter::class],
12+
'data_source' => [\ProcessMaker\Packages\Connectors\DataSources\Models\DataSource::class, \ProcessMaker\Packages\Connectors\DataSources\ImportExport\DataSourceExporter::class],
13+
'decision_table' => [\ProcessMaker\Package\PackageDecisionEngine\Models\DecisionTable::class, \ProcessMaker\Package\PackageDecisionEngine\ImportExport\DecisionTableExporter::class],
14+
];
15+
16+
public static function getModelClass(string $type): ?string
17+
{
18+
return self::TYPES[$type][0] ?? null;
19+
}
20+
21+
public static function getExporterClass(string $type): ?string
22+
{
23+
return self::TYPES[$type][1] ?? null;
24+
}
25+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace ProcessMaker\Helpers;
4+
5+
class MobileHelper
6+
{
7+
public static function isMobile($userAgent)
8+
{
9+
$device = '/(Mobile|Android|Tablet|GoBrowser|[0-9]x[0-9]*|uZardWeb\/|Mini|Doris\/|Skyfire\/|iPhone|Fennec\/|Maemo|Iris\/|CLDC\-|Mobi\/)/uis';
10+
if (preg_match($device, $userAgent) && !empty($_COOKIE['isMobile']) && $_COOKIE['isMobile'] === 'true') {
11+
return true;
12+
}
13+
14+
return false;
15+
}
16+
}

ProcessMaker/Http/Controllers/Api/EnvironmentVariablesController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function index(Request $request)
7878
} else {
7979
$environment_variables = EnvironmentVariable::orderBy($orderBy, $orderDirection)->paginate($perPage);
8080
}
81+
8182
// Return fractal representation of paged data
8283
return new ApiCollection($environment_variables);
8384
}

ProcessMaker/Http/Controllers/Api/ExportController.php

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,14 @@
66
use Illuminate\Database\Eloquent\Model;
77
use Illuminate\Http\JsonResponse;
88
use Illuminate\Http\Request;
9+
use ProcessMaker\Enums\ExporterMap;
910
use ProcessMaker\Exception\ExportModelNotFoundException;
1011
use ProcessMaker\Http\Controllers\Controller;
1112
use ProcessMaker\ImportExport\Exporter;
12-
use ProcessMaker\ImportExport\Exporters\ProcessExporter;
13-
use ProcessMaker\ImportExport\Exporters\ScreenExporter;
14-
use ProcessMaker\ImportExport\Exporters\ScriptExporter;
15-
use ProcessMaker\ImportExport\Exporters\TemplateExporter;
1613
use ProcessMaker\ImportExport\Options;
17-
use ProcessMaker\Models\Process;
18-
use ProcessMaker\Models\ProcessTemplates;
19-
use ProcessMaker\Models\Screen;
20-
use ProcessMaker\Models\Script;
21-
use ProcessMaker\PackageHelper;
2214

2315
class ExportController extends Controller
2416
{
25-
const DATA_SOURCE_CLASS = 'ProcessMaker\Packages\Connectors\DataSources\Models\DataSource';
26-
27-
const DATA_SOURCE_EXPORTER_CLASS = 'ProcessMaker\Packages\Connectors\DataSources\ImportExport\DataSourceExporter';
28-
29-
const DECISION_TABLE_CLASS = 'ProcessMaker\Package\PackageDecisionEngine\Models\DecisionTable';
30-
31-
const DECISION_TABLE_EXPORTER_CLASS = 'ProcessMaker\Package\PackageDecisionEngine\ImportExport\DecisionTableExporter';
32-
33-
protected array $types = [
34-
'screen' => [Screen::class, ScreenExporter::class],
35-
'process' => [Process::class, ProcessExporter::class],
36-
'script' => [Script::class, ScriptExporter::class],
37-
'process_templates' => [ProcessTemplates::class, TemplateExporter::class],
38-
];
39-
40-
public function __construct()
41-
{
42-
if (PackageHelper::isPackageInstalled(self::DATA_SOURCE_CLASS)) {
43-
$this->types['data_source'] = [self::DATA_SOURCE_CLASS, self::DATA_SOURCE_EXPORTER_CLASS];
44-
}
45-
if (PackageHelper::isPackageInstalled(self::DECISION_TABLE_CLASS)) {
46-
$this->types['decision_table'] = [self::DECISION_TABLE_CLASS, self::DECISION_TABLE_EXPORTER_CLASS];
47-
}
48-
}
49-
5017
/**
5118
* Return only the manifest
5219
*/
@@ -55,7 +22,7 @@ public function manifest(string $type, int $id): JsonResponse
5522
$model = $this->getModel($type)->findOrFail($id);
5623
try {
5724
$exporter = new Exporter(true);
58-
$exporter->export($model, $this->types[$type][1]);
25+
$exporter->export($model, ExporterMap::getExporterClass($type));
5926

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

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

7946
$payload = $exporter->payload();
8047

@@ -111,9 +78,8 @@ function () use ($payload) {
11178

11279
public function getModel(string $type): Model
11380
{
114-
if (isset($this->types[$type])) {
115-
$modelClass = current($this->types[$type]);
116-
81+
$modelClass = ExporterMap::getModelClass($type);
82+
if ($modelClass) {
11783
return new $modelClass;
11884
}
11985
throw new Exception("Type {$type} not found", 404);

ProcessMaker/Http/Controllers/Api/ScreenController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ public function index(Request $request)
144144
return response(['message' => __('Your PMQL contains invalid syntax.')], 400);
145145
}
146146
}
147+
148+
if ($request->has('key')) {
149+
$query->where('key', $request->get('key'));
150+
}
151+
147152
$response =
148153
$query->orderBy(
149154
$request->input('order_by', 'title'),

ProcessMaker/Http/Controllers/Api/TaskController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ public function index(Request $request, $getTotal = false, User $user = null)
161161

162162
//list only display elements type task
163163
$nonSystem = filter_var($request->input('non_system'), FILTER_VALIDATE_BOOLEAN);
164-
$query->where('element_type', '=', 'task')
164+
$query->where(function ($query) {
165+
$query->where('element_type', '=', 'task');
166+
$query->orWhere('element_type', '=', 'serviceTask');
167+
$query->where('element_name', '=', 'AI Assistant');
168+
})
165169
->when($nonSystem, function ($query) {
166170
$query->nonSystem();
167171
});

ProcessMaker/Http/Controllers/Api/TemplateController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ public function create(string $type, Request $request)
143143
$response = $this->template->create($type, $request);
144144
}
145145
} elseif ($type === 'update-assets') {
146+
$request['request'] = json_decode($request['request'], true);
147+
$request['existingAssets'] = json_decode($request['existingAssets'], true);
146148
$request->validate([
147149
'id' => 'required|numeric',
148150
'request' => 'required|array',

ProcessMaker/Http/Controllers/Auth/LoginController.php

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use ProcessMaker\Events\Logout;
1111
use ProcessMaker\Http\Controllers\Controller;
1212
use ProcessMaker\Managers\LoginManager;
13+
use ProcessMaker\Models\Setting;
1314
use ProcessMaker\Models\User;
1415
use ProcessMaker\Traits\HasControllerAddons;
1516

@@ -55,17 +56,90 @@ public function showLoginForm()
5556
{
5657
$manager = App::make(LoginManager::class);
5758
$addons = $manager->list();
59+
// Review if we need to redirect the default SSO
60+
if (config('app.enable_default_sso')) {
61+
$arrayAddons = $addons->toArray();
62+
$driver = $this->getDefaultSSO($arrayAddons);
63+
// If a default SSO was defined we will to redirect
64+
if (!empty($driver)) {
65+
return redirect()->route('sso.redirect', ['driver' => $driver]);
66+
}
67+
}
5868
$block = $manager->getBlock();
5969
// clear cookie to avoid an issue when logout SLO and then try to login with simple PM login form
6070
\Cookie::queue(\Cookie::forget(config('session.cookie')));
6171
// cookie required here because SSO redirect resets the session
62-
$cookie = cookie('processmaker_intended', redirect()->intended()->getTargetUrl(), 10, null, null, true, true, false, 'none');
72+
$cookie = cookie(
73+
'processmaker_intended',
74+
redirect()->intended()->getTargetUrl(),
75+
10,
76+
null,
77+
null,
78+
true,
79+
true,
80+
false,
81+
'none'
82+
);
6383
$response = response(view('auth.login', compact('addons', 'block')));
6484
$response->withCookie($cookie);
6585

6686
return $response;
6787
}
6888

89+
protected function getDefaultSSO(array $addons): string
90+
{
91+
$addonsData = !empty($addons) ? head($addons)->data : [];
92+
$defaultSSO = '';
93+
if (class_exists(\ProcessMaker\Package\Auth\Database\Seeds\AuthDefaultSeeder::class)) {
94+
$defaultSSO = Setting::byKey(
95+
\ProcessMaker\Package\Auth\Database\Seeds\AuthDefaultSeeder::SSO_DEFAULT_LOGIN
96+
);
97+
}
98+
if (!empty($defaultSSO) && !empty($addonsData)) {
99+
// Get the config selected
100+
$position = $this->getColumnAttribute($defaultSSO, 'config', 'config');
101+
// Get the ui defined
102+
$elements = $this->getColumnAttribute($defaultSSO, 'ui', 'elements');
103+
$options = $this->getColumnAttribute($defaultSSO, 'ui', 'options');
104+
// Get the sso drivers configured
105+
$drivers = !empty($addonsData['drivers']) ? $addonsData['drivers'] : [];
106+
if (
107+
is_int($position)
108+
&& $options[$position] !== AuthDefaultSeeder::PM_LOGIN
109+
&& !empty($elements)
110+
&& !empty($drivers)
111+
) {
112+
// Get the specific element defined with the default SSO
113+
$element = !empty($elements[$position]->name) ? strtolower($elements[$position]->name) : '';
114+
if (!empty($element) && array_key_exists($element, $drivers)) {
115+
return $element;
116+
}
117+
}
118+
}
119+
120+
return '';
121+
}
122+
123+
protected function getColumnAttribute(object $setting, string $attribute, string $key = '')
124+
{
125+
$config = $setting->getAttribute($attribute);
126+
switch ($key) {
127+
case 'config':
128+
$result = !is_null($config) ? (int) $config : null;
129+
break;
130+
case 'elements':
131+
$result = !empty($config->elements) ? $config->elements : [];
132+
break;
133+
case 'options':
134+
$result = !empty($config->options) ? $config->options : [];
135+
break;
136+
default:
137+
$result = null;
138+
}
139+
140+
return $result;
141+
}
142+
69143
public function loginWithIntendedCheck(Request $request)
70144
{
71145
$intended = Cookie::get('processmaker_intended');
@@ -96,6 +170,13 @@ public function loginWithIntendedCheck(Request $request)
96170
}
97171
}
98172

173+
if (class_exists(\ProcessMaker\Package\Auth\Auth\LDAPLogin::class)) {
174+
$redirect = \ProcessMaker\Package\Auth\Auth\LDAPLogin::auth($user, $request->input('password'));
175+
if ($redirect !== false) {
176+
return $redirect;
177+
}
178+
}
179+
99180
return $this->login($request);
100181
}
101182

0 commit comments

Comments
 (0)