Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ProcessMaker/Repositories/TokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ public function persistActivityClosed(ActivityInterface $activity, TokenInterfac
$token->process_id = $token->getInstance()->process_id;
$token->process_request_id = $token->getInstance()->getKey();
$token->data = $token->getInstance()->getDataStore()->getData();
// A closed token can no longer be claimed, e.g. when an interrupting boundary event closes an unclaimed self-service task
if ($token->is_self_service) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devmiguelangel Instead of force the claim, the self-service task needs to list all the self-service with ACTIVE status (this avoid to show the self-service CLOSED)
Could you check please?
Regards

$token->is_self_service = 0;
}

$token->updateTokenProperties();
$token->save();
$token->setId($token->getKey());
Expand Down
71 changes: 71 additions & 0 deletions tests/Feature/Api/BoundaryEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ProcessMaker\Managers\TaskSchedulerManager;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Models\ScheduledTask;
use ProcessMaker\Models\User;
use Tests\Feature\Shared\ProcessTestingTrait;
use Tests\Feature\Shared\RequestHelper;
use Tests\TestCase;
Expand Down Expand Up @@ -444,4 +445,74 @@ public function testTimerBoundaryEventMultiInstance()
$this->assertCount(1, $activeTokens);
$this->assertEquals('Task 2', $activeTokens[0]->element_name);
}

/**
* Tests that an interrupting timer boundary event closes an unclaimed self-service task
* and clears its self-service flag
*
* @group timer_events
*/
public function testTimerBoundaryEventClosesSelfServiceTask()
{
$now = TaskSchedulerManager::fakeToday('2018-05-01T00:00:00Z');
$process = $this->createSelfServiceTimerProcess(true);

$instance = $this->startProcess($process, 'node_1');

$selfServiceToken = $instance->tokens()->where('element_id', 'node_2')->firstOrFail();
$this->assertEquals('ACTIVE', $selfServiceToken->status);
$this->assertEquals(1, $selfServiceToken->is_self_service);
$this->assertNull($selfServiceToken->user_id);

$now->modify('+1 minute');
TaskSchedulerManager::fakeToday($now);
$this->runScheduledTasks();

$selfServiceToken->refresh();
$this->assertEquals('CLOSED', $selfServiceToken->status);
$this->assertEquals(0, $selfServiceToken->is_self_service);
$this->assertEquals('COMPLETED', $instance->refresh()->status);

$route = route('api.tasks.index', [
'process_request_id' => $instance->id,
'pmql' => 'is_self_service = 1',
]);
$response = $this->apiCall('GET', $route);
$response->assertStatus(200);
$this->assertNotContains($selfServiceToken->id, array_column($response->json('data'), 'id'));
}

/**
* Tests that a non-interrupting timer boundary event keeps the self-service task open
*
* @group timer_events
*/
public function testNonInterruptingTimerBoundaryEventKeepsSelfServiceTaskOpen()
{
$now = TaskSchedulerManager::fakeToday('2018-05-01T00:00:00Z');
$process = $this->createSelfServiceTimerProcess(false);

$instance = $this->startProcess($process, 'node_1');

$now->modify('+1 minute');
TaskSchedulerManager::fakeToday($now);
$this->runScheduledTasks();

$selfServiceToken = $instance->tokens()->where('element_id', 'node_2')->firstOrFail();
$this->assertEquals('ACTIVE', $selfServiceToken->status);
$this->assertEquals(1, $selfServiceToken->is_self_service);
$this->assertNull($selfServiceToken->user_id);
}

private function createSelfServiceTimerProcess(bool $cancelActivity)
{
$selfServiceUser = User::factory()->create(['status' => 'ACTIVE']);
$bpmn = file_get_contents(__DIR__ . '/processes/Timer_BoundaryEvent_SelfService.bpmn');
$bpmn = str_replace('{selfServiceUserId}', $selfServiceUser->id, $bpmn);
if (!$cancelActivity) {
$bpmn = str_replace('cancelActivity="true"', 'cancelActivity="false"', $bpmn);
}

return $this->createProcess($bpmn);
}
}
58 changes: 58 additions & 0 deletions tests/Feature/Api/processes/Timer_BoundaryEvent_SelfService.bpmn
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:pm="http://processmaker.com/BPMN/2.0/Schema.xsd" targetNamespace="http://bpmn.io/schema/bpmn" exporter="ProcessMaker Modeler" exporterVersion="1.0">
<bpmn:process id="ProcessId" name="ProcessName" isExecutable="true">
<bpmn:startEvent id="node_1" name="Start Event">
<bpmn:outgoing>node_4</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:task id="node_2" name="Self Service Task" pm:assignment="user_group" pm:assignedUsers="{selfServiceUserId}" pm:assignedGroups="" pm:config="{&#34;selfService&#34;:true}">
<bpmn:incoming>node_4</bpmn:incoming>
<bpmn:outgoing>node_5</bpmn:outgoing>
</bpmn:task>
<bpmn:endEvent id="node_3" name="End Event">
<bpmn:incoming>node_5</bpmn:incoming>
</bpmn:endEvent>
<bpmn:boundaryEvent id="node_6" name="Boundary Timer Event" attachedToRef="node_2" cancelActivity="true">
<bpmn:outgoing>node_8</bpmn:outgoing>
<bpmn:timerEventDefinition id="node_6_timer_event_definition">
<bpmn:timeCycle>R4/2018-05-01T00:00:00Z/PT1M</bpmn:timeCycle>
</bpmn:timerEventDefinition>
</bpmn:boundaryEvent>
<bpmn:endEvent id="node_7" name="Timer End Event">
<bpmn:incoming>node_8</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="node_4" sourceRef="node_1" targetRef="node_2" />
<bpmn:sequenceFlow id="node_5" sourceRef="node_2" targetRef="node_3" />
<bpmn:sequenceFlow id="node_8" sourceRef="node_6" targetRef="node_7" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagramId">
<bpmndi:BPMNPlane id="BPMNPlaneId" bpmnElement="ProcessId">
<bpmndi:BPMNShape id="node_1_di" bpmnElement="node_1">
<dc:Bounds x="360" y="248.5" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="node_2_di" bpmnElement="node_2">
<dc:Bounds x="460" y="228.5" width="116" height="76" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="node_3_di" bpmnElement="node_3">
<dc:Bounds x="640" y="248.5" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="node_6_di" bpmnElement="node_6">
<dc:Bounds x="500" y="286.5" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="node_7_di" bpmnElement="node_7">
<dc:Bounds x="500" y="387" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="node_4_di" bpmnElement="node_4">
<di:waypoint x="396" y="266.5" />
<di:waypoint x="460" y="266.5" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="node_5_di" bpmnElement="node_5">
<di:waypoint x="576" y="266.5" />
<di:waypoint x="640" y="266.5" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="node_8_di" bpmnElement="node_8">
<di:waypoint x="518" y="322.5" />
<di:waypoint x="518" y="387" />
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
Loading