Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOUR-12577 Request Title Configuration. #5721

Merged
merged 5 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions ProcessMaker/Http/Controllers/Api/ProcessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ProcessController extends Controller
public $doNotSanitize = [
'bpmn',
'svg',
'case_title',
];

/**
Expand Down
2 changes: 1 addition & 1 deletion ProcessMaker/Models/MustacheExpressionEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct()
* is returned
*
* @param string $template
* @param string $data
* @param array $data
* @return string
*/
public function render($template, $data)
Expand Down
2 changes: 2 additions & 0 deletions ProcessMaker/Models/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
* @property string $bpmn
* @property string $description
* @property string $name
* @property string $case_title
* @property string $status
* @property array $start_events
* @property int $manager_id
Expand All @@ -68,6 +69,7 @@
* schema="ProcessEditable",
* @OA\Property(property="process_category_id", type="integer", format="id"),
* @OA\Property(property="name", type="string"),
* @OA\Property(property="case_title", type="string"),
* @OA\Property(property="description", type="string"),
* @OA\Property(property="status", type="string", enum={"ACTIVE", "INACTIVE", "ARCHIVED"}),
* @OA\Property(property="pause_timer_start", type="integer"),
Expand Down
16 changes: 15 additions & 1 deletion ProcessMaker/Models/ProcessRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
* @property string $process_collaboration_id
* @property string $participant_id
* @property string $name
* @property string $case_title
* @property string $status
* @property string $data
* @property array $data
* @property string $collaboration_uuid
* @property \Carbon\Carbon $initiated_at
* @property \Carbon\Carbon $completed_at
Expand All @@ -59,6 +60,7 @@
* @OA\Property(property="data", type="object"),
* @OA\Property(property="status", type="string", enum={"ACTIVE", "COMPLETED", "ERROR", "CANCELED"}),
* @OA\Property(property="name", type="string"),
* @OA\Property(property="case_title", type="string"),
* @OA\Property(property="process_id", type="integer"),
* @OA\Property(property="process", type="object"),
* ),
Expand Down Expand Up @@ -920,4 +922,16 @@ public function getErrors()
->get()
->toArray();
}

public function evaluateCaseTitle(array $data): string
{
// check if $this->process relation is loaded
if ($this->process && $this->process instanceof Process) {
$mustacheTitle = $this->process->case_title;
} else {
$mustacheTitle = $this->process()->select('case_title')->first()->case_title;
}
$mustache = new MustacheExpressionEvaluator();
return $mustache->render($mustacheTitle, $data);
}
}
12 changes: 10 additions & 2 deletions ProcessMaker/Nayra/Repositories/PersistenceTokenTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,17 @@ public function persistGatewayTokenConsumed(array $transaction)
public function persistGatewayTokenPassed(array $transaction)
{
$gateway = $this->deserializer->unserializeEntity($transaction['gateway']);
$transition = $this->deserializer->unserializeEntity($transaction['transition']);
if (!is_numeric($transaction['transition'])) {
Log::info('Invalid transition id for gateway token passed. ' . json_encode($transaction));
return;
}
$transition = $gateway->getTransitions()[$transaction['transition']] ?? null;
if (empty($transition)) {
Log::info('Invalid transition for gateway token passed. ' . json_encode($transaction));
return;
}
$tokens = $this->deserializer->unserializeTokensCollection($transaction['tokens']);
$this->tokenRepository->persistGatewayTokenPassed($gateway, $tokens[0]);
$this->tokenRepository->persistGatewayTokenPassed($gateway, $tokens->item(0));

// Comments
$subscriber = new CommentsSubscriber();
Expand Down
9 changes: 9 additions & 0 deletions ProcessMaker/Observers/ProcessRequestObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,13 @@ public function saved(ProcessRequest $request)
$request->scheduledTasks()->delete();
}
}

public function saving(ProcessRequest $request)
{
// When data is updated we update the case_title
if ($request->isDirty('data')) {
$data = $request->data;
$request->case_title = $request->evaluateCaseTitle($data);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('processes', function (Blueprint $table) {
$table->string('case_title', 200)->nullable();
});
Schema::table('process_versions', function (Blueprint $table) {
$table->string('case_title', 200)->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('processes', function (Blueprint $table) {
$table->dropColumn('case_title');
});
Schema::table('process_versions', function (Blueprint $table) {
$table->dropColumn('case_title');
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('process_requests', function (Blueprint $table) {
$table->string('case_title', 200)->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('process_requests', function (Blueprint $table) {
$table->dropColumn('case_title');
});
}
};
10 changes: 7 additions & 3 deletions resources/js/requests/components/RequestsListing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,13 @@ export default {
default: true,
},
{
label: "Name",
label: "Case Title",
field: "case_title",
sortable: true,
default: true,
},
{
label: "Process Name",
field: "name",
sortable: true,
default: true,
Expand Down Expand Up @@ -356,5 +362,3 @@ export default {
},
};
</script>
<style>
</style>
13 changes: 13 additions & 0 deletions resources/views/processes/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@
</select-user>
<div class="invalid-feedback" role="alert" v-if="errors.manager_id">@{{errors.manager_id[0]}}</div>
</div>
<div class="form-group">
{!! Form::label('case_title', __('Case Title')) !!}
{!!Form::text('case_title', null,
[ 'id'=> 'case_title',
'class'=> 'form-control',
'v-model'=> 'formData.case_title',
'v-bind:class' => '{\'form-control\':true, \'is-invalid\':errors.case_title}'
])
!!}
<small class="form-text text-muted" v-if="! errors.name">
{{ __('This field has a limit of 200 characters when calculated') }}
</small>
</div>
<div class="form-group p-0">
{!! Form::label('cancelRequest', __('Cancel Request')) !!}
<multiselect id="cancelRequest"
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Api/ProcessRequestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public function testUpdateProcessRequest()
//Post saved success
$response = $this->apiCall('PUT', $url, [
'name' => $faker->unique()->name(),
'data' => '{"test":1}',
'data' => ['test' => 1],
'process_id' => json_decode($verify->getContent())->process_id,
]);

Expand Down