Skip to content

Commit 25ca291

Browse files
authored
Merge pull request #8642 from ProcessMaker/bugfix/FOUR-25055
FOUR-25055: Fix process owner when creating from default templates
2 parents dc92565 + 761f30d commit 25ca291

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

ProcessMaker/Templates/ProcessTemplate.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ public function create($request) : JsonResponse
293293
$processId = $rootLog['newId'];
294294

295295
$process = Process::findOrFail($processId);
296+
$process->user_id = Auth::id();
297+
$process->save();
296298

297299
$this->syncLaunchpadAssets($request, $process);
298300

tests/Feature/Templates/Api/ProcessTemplateTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,53 @@ public function testUpdateAssetsWhenCreatingProcess()
342342
$this->assertEquals('Description of the process', $newProcess->description);
343343
}
344344

345+
public function testProcessCreatedFromTemplateUsesAuthenticatedUserAsOwner()
346+
{
347+
$this->addGlobalSignalProcess();
348+
$templateOwner = User::factory()->create(['is_administrator' => true]);
349+
$this->user = User::factory()->create(['is_administrator' => false]);
350+
351+
$processCategory = ProcessCategory::factory()->create(['status' => 'ACTIVE']);
352+
353+
$process = $this->createProcess('process-with-task-screen', [
354+
'name' => 'Template Owned Process',
355+
'description' => 'Template Owned Description',
356+
'user_id' => $templateOwner->getKey(),
357+
'process_category_id' => $processCategory->getKey(),
358+
]);
359+
360+
$manifest = $this->getManifest('process', $process->id);
361+
362+
$template = ProcessTemplates::factory()->create([
363+
'name' => 'Owner Override Template',
364+
'description' => 'Owner Override Template Description',
365+
'process_id' => $process->id,
366+
'process_category_id' => $processCategory->getKey(),
367+
'manifest' => json_encode($manifest),
368+
'user_id' => $templateOwner->getKey(),
369+
'version' => '1.0.0',
370+
]);
371+
372+
$route = route('api.template.create', ['type' => 'process', 'id' => $template->id]);
373+
$response = $this->apiCall('POST', $route, [
374+
'user_id' => $this->user->getKey(),
375+
'name' => 'New Process From Template',
376+
'description' => 'New Process Description',
377+
'process_category_id' => $processCategory->getKey(),
378+
'mode' => 'copy',
379+
'version' => $template->version,
380+
'saveAssetMode' => 'saveAllAssets',
381+
]);
382+
383+
$response->assertStatus(200);
384+
385+
$processId = $response->json('processId');
386+
$newProcess = Process::findOrFail($processId);
387+
388+
$this->assertEquals($this->user->getKey(), $newProcess->user_id);
389+
$this->assertNotEquals($templateOwner->getKey(), $newProcess->user_id);
390+
}
391+
345392
/**
346393
* Tests the fixtures of the private PHP function.
347394
*

0 commit comments

Comments
 (0)