Skip to content

Commit

Permalink
Merge pull request #5371 from ProcessMaker/epic/FOUR-9674
Browse files Browse the repository at this point in the history
Epic/FOUR-9674: AI in modeler
  • Loading branch information
ryancooley authored Sep 27, 2023
2 parents 027442b + 8fb1c1e commit 911aa17
Show file tree
Hide file tree
Showing 49 changed files with 677 additions and 74 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
2 changes: 1 addition & 1 deletion ProcessMaker/Helpers/MobileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ 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") {
if (preg_match($device, $userAgent) && !empty($_COOKIE['isMobile']) && $_COOKIE['isMobile'] === 'true') {
return true;
}

Expand Down
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
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
3 changes: 2 additions & 1 deletion ProcessMaker/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function showLoginForm()
}
}
}

$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 @@ -121,6 +121,7 @@ public function loginWithIntendedCheck(Request $request)
return $redirect;
}
}

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

Expand Down
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
27 changes: 27 additions & 0 deletions ProcessMaker/Http/Controllers/Process/ModelerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
use ProcessMaker\Managers\ModelerManager;
use ProcessMaker\Managers\SignalManager;
use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessCategory;
use ProcessMaker\Models\ProcessRequest;
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 @@ -31,6 +36,22 @@ public function show(ModelerManager $manager, Process $process, Request $request
*/
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 +64,12 @@ 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,
'screenTypes' => $screenTypes,
'scriptExecutors' => $scriptExecutors,
'countProcessCategories' => $countProcessCategories,
'countScreenCategories' => $countScreenCategories,
'countScriptCategories' => $countScriptCategories,
'isProjectsInstalled' => $isProjectsInstalled,
]);
}

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,
]);
}
}
3 changes: 2 additions & 1 deletion ProcessMaker/Http/Controllers/Process/ScriptController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function edit(Script $script, User $users)
return view('processes.scripts.edit', compact('script', 'selectedUser', 'scriptExecutors', 'addons'));
}

public function builder(ScriptBuilderManager $manager, Request $request, Script $script)
public function builder(ScriptBuilderManager $manager, Request $request, Script $script, $processId = null)
{
$processRequestAttributes = $this->getProcessRequestAttributes();
$processRequestAttributes['user_id'] = $request->user()->id;
Expand Down Expand Up @@ -91,6 +91,7 @@ public function builder(ScriptBuilderManager $manager, Request $request, Script
'isVersionsInstalled' => PackageHelper::isPmPackageVersionsInstalled(),
'isDraft' => $draft !== null,
'user' => \Auth::user(),
'processId' => $processId,
]);
}

Expand Down
1 change: 1 addition & 0 deletions ProcessMaker/Http/Middleware/SanitizeInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected function cleanValue($key, $value)
// Do not sanitize any values (should be handled elsewhere in the controller)
return $value;
}

// If this is a string and is not in the exceptions
// array, return it after sanitization.
return SanitizeHelper::sanitize($value, !in_array($key, $this->except, true));
Expand Down
1 change: 1 addition & 0 deletions ProcessMaker/Http/Middleware/SetLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function handle(Request $request, Closure $next)
// Use the App facade to set the locale for our request lifecycle
App::setLocale($locale);
}

// Process next
return $next($request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ public function handle(Request $request, Closure $next)
{
$user = $request->route('user');
$fields = $request->json()->all();
if (($fields['username'] !== $user->getAttribute('username') || in_array('password', $fields)) &&
if (($fields['username'] !== $user->getAttribute('username') || in_array('password', $fields)) &&
!Auth::user()->hasPermission('edit-user-and-password') && !Auth::user()->is_administrator) {
throw new AuthorizationException(__('Not authorized to update the username and password.'));

}

return $next($request);
Expand Down
1 change: 0 additions & 1 deletion ProcessMaker/Jobs/ImportProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,6 @@ protected function decodeFile()
if (property_exists($this->file, 'process') && property_exists($this->file->process, 'bpmn')) {
$this->file->process->bpmn = str_replace('bpmn2', 'bpmn', $this->file->process->bpmn);
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion ProcessMaker/Jobs/RefreshArtisanCaches.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function handle()
{
Artisan::call('clear-compiled', $options = [
'--no-interaction' => true,
'--quiet' => true
'--quiet' => true,
]);

if (app()->configurationIsCached()) {
Expand Down
1 change: 1 addition & 0 deletions ProcessMaker/Models/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ public function getCollaborations()
$this->bpmnDefinitions = app(BpmnDocumentInterface::class, ['process' => $this]);
if ($this->bpmn) {
$this->bpmnDefinitions->loadXML($this->bpmn);

// Load the collaborations if exists
return $this->bpmnDefinitions->getElementsByTagNameNS(BpmnDocument::BPMN_MODEL, 'collaboration');
}
Expand Down
1 change: 1 addition & 0 deletions ProcessMaker/Models/ProcessRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ public function getErrors()
if ($this->errors) {
return $this->errors;
}

// select tokens with errors
return $this->tokens()
->select('token_properties->error as message', 'created_at', 'element_name')
Expand Down
5 changes: 5 additions & 0 deletions ProcessMaker/Models/ProcessRequestToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ public function getScreen(): ?Screen
$isManualTask = $localName === 'manualTask';
$defaultScreen = $isManualTask ? 'default-display-screen' : 'default-form-screen';
$screen = Screen::firstWhere('key', $defaultScreen);

if (array_key_exists('implementation', $definition) && $definition['implementation'] === 'package-ai/processmaker-ai-assistant') {
$defaultScreen = 'default-ai-form-screen';
$screen = Screen::firstWhere('key', $defaultScreen);
}
}

return $screen;
Expand Down
2 changes: 2 additions & 0 deletions ProcessMaker/Nayra/Managers/WorkflowManagerDefault.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public function triggerStartEvent(Definitions $definitions, StartEventInterface
{
//Validate data
$this->validateData($data, $definitions, $event);

//Schedule BPMN Action
return (new StartEvent($definitions, $event, $data))->handle();
}
Expand All @@ -169,6 +170,7 @@ public function callProcess(Definitions $definitions, ProcessInterface $process,
{
//Validate data
$this->validateData($data, $definitions, $process);

//Validate user permissions
//Validate BPMN rules
//Log BPMN actions
Expand Down
1 change: 1 addition & 0 deletions ProcessMaker/Providers/UserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function retrieveByCredentials(array $credentials)
} elseif (isset($credentials['username'])) {
return User::where('username', $credentials['username'])->first();
}

// No valid credential to find, let's return nothing
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion ProcessMaker/SanitizeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private static function getRichTextElements($items, $parent = null)
$elements = array_merge($elements, self::getRichTextElements($item['items'], ($parent ? $parent . '.' . $item['config']['name'] : $item['config']['name'])));
} elseif (isset($item['component']) && $item['component'] === 'FormTextArea' && isset($item['config']['richtext']) && $item['config']['richtext'] === true) {
$elements[] = ($parent ? $parent . '.' . $item['config']['name'] : $item['config']['name']);
// Inside a table ..
// Inside a table ..
} elseif ($item['component'] == 'FormMultiColumn') {
foreach ($item['items'] as $cell) {
if (
Expand Down
2 changes: 1 addition & 1 deletion config/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@
|
*/

'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'),
'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_') . '_cache_'),

];
2 changes: 1 addition & 1 deletion config/filesystems.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
'throw' => false,
],
Expand Down
2 changes: 1 addition & 1 deletion config/logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
'handler_with' => [
'host' => env('PAPERTRAIL_URL'),
'port' => env('PAPERTRAIL_PORT'),
'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
'connectionString' => 'tls://' . env('PAPERTRAIL_URL') . ':' . env('PAPERTRAIL_PORT'),
],
'processors' => [PsrLogMessageProcessor::class],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class extends Migration {
/**
* Run the migrations.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
use Illuminate\Support\Facades\Schema;
use ProcessMaker\Models\ProcessTemplates;

return new class extends Migration
{
return new class extends Migration {
/**
* Run the migrations.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class extends Migration {
/**
* Run the migrations.
*
Expand Down
429 changes: 429 additions & 0 deletions database/processes/screens/default-ai-form-screen.json

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions resources/img/cornea_icon.svg

This file was deleted.

Loading

0 comments on commit 911aa17

Please sign in to comment.