Merged in bugfix/PMC-24 (pull request #7062)

PMC-24

Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
Paula Quispe
2019-09-06 12:51:53 +00:00
committed by Julio Cesar Laura Avendaño
4 changed files with 186 additions and 83 deletions

View File

@@ -1,4 +1,5 @@
<?php <?php
namespace Tests\unit\workflow\src\ProcessMaker\Model; namespace Tests\unit\workflow\src\ProcessMaker\Model;
use Faker\Factory; use Faker\Factory;
@@ -18,11 +19,18 @@ use ProcessMaker\Model\TaskUser;
use ProcessMaker\Model\User; use ProcessMaker\Model\User;
use Tests\TestCase; use Tests\TestCase;
/**
* Class DelegationTest
*
* @coversDefaultClass \ProcessMaker\Model\Delegation
*/
class DelegationTest extends TestCase class DelegationTest extends TestCase
{ {
use DatabaseTransactions; use DatabaseTransactions;
/** /**
* This checks to make sure pagination is working properly * This checks to make sure pagination is working properly
*
* @test * @test
*/ */
public function it_should_return_pages_of_data() public function it_should_return_pages_of_data()
@@ -43,6 +51,7 @@ class DelegationTest extends TestCase
/** /**
* This checks to make sure pagination is working properly * This checks to make sure pagination is working properly
*
* @test * @test
*/ */
public function it_should_return_pages_of_data_unassigned() public function it_should_return_pages_of_data_unassigned()
@@ -66,6 +75,7 @@ class DelegationTest extends TestCase
/** /**
* This checks to make sure filter by process is working properly * This checks to make sure filter by process is working properly
*
* @test * @test
*/ */
public function it_should_return_process_of_data() public function it_should_return_process_of_data()
@@ -89,6 +99,7 @@ class DelegationTest extends TestCase
/** /**
* This checks to make sure filter by status is working properly * This checks to make sure filter by status is working properly
* Review status filter by a specific status, such as Draft * Review status filter by a specific status, such as Draft
*
* @test * @test
*/ */
public function it_should_return_status_draft_of_data() public function it_should_return_status_draft_of_data()
@@ -96,7 +107,6 @@ class DelegationTest extends TestCase
factory(User::class, 100)->create(); factory(User::class, 100)->create();
factory(Process::class)->create(); factory(Process::class)->create();
$application = factory(Application::class)->create([ $application = factory(Application::class)->create([
'APP_NUMBER' => 2001,
'APP_STATUS_ID' => 1, 'APP_STATUS_ID' => 1,
'APP_STATUS' => 'DRAFT' 'APP_STATUS' => 'DRAFT'
]); ]);
@@ -118,6 +128,7 @@ class DelegationTest extends TestCase
/** /**
* This checks to make sure filter by status is working properly * This checks to make sure filter by status is working properly
* Review status filter by a specific status, such as To Do * Review status filter by a specific status, such as To Do
*
* @test * @test
*/ */
public function it_should_return_status_todo_of_data() public function it_should_return_status_todo_of_data()
@@ -125,7 +136,6 @@ class DelegationTest extends TestCase
factory(User::class, 100)->create(); factory(User::class, 100)->create();
factory(Process::class)->create(); factory(Process::class)->create();
$application = factory(Application::class)->create([ $application = factory(Application::class)->create([
'APP_NUMBER' => 2001,
'APP_STATUS_ID' => 2, 'APP_STATUS_ID' => 2,
'APP_STATUS' => 'TO_DO' 'APP_STATUS' => 'TO_DO'
]); ]);
@@ -147,6 +157,7 @@ class DelegationTest extends TestCase
/** /**
* This checks to make sure filter by status is working properly * This checks to make sure filter by status is working properly
* Review status filter by a specific status, such as Completed * Review status filter by a specific status, such as Completed
*
* @test * @test
*/ */
public function it_should_return_status_completed_of_data() public function it_should_return_status_completed_of_data()
@@ -154,7 +165,6 @@ class DelegationTest extends TestCase
factory(User::class, 100)->create(); factory(User::class, 100)->create();
factory(Process::class)->create(); factory(Process::class)->create();
$application = factory(Application::class)->create([ $application = factory(Application::class)->create([
'APP_NUMBER' => 2001,
'APP_STATUS_ID' => 3, 'APP_STATUS_ID' => 3,
'APP_STATUS' => 'COMPLETED', 'APP_STATUS' => 'COMPLETED',
]); ]);
@@ -178,6 +188,7 @@ class DelegationTest extends TestCase
/** /**
* This checks to make sure filter by status is working properly * This checks to make sure filter by status is working properly
* Review status filter by a specific status, such as Cancelled * Review status filter by a specific status, such as Cancelled
*
* @test * @test
*/ */
public function it_should_return_status_cancelled_of_data() public function it_should_return_status_cancelled_of_data()
@@ -185,7 +196,6 @@ class DelegationTest extends TestCase
factory(User::class, 100)->create(); factory(User::class, 100)->create();
factory(Process::class)->create(); factory(Process::class)->create();
$application = factory(Application::class)->create([ $application = factory(Application::class)->create([
'APP_NUMBER' => 2001,
'APP_STATUS_ID' => 4, 'APP_STATUS_ID' => 4,
'APP_STATUS' => 'CANCELLED' 'APP_STATUS' => 'CANCELLED'
]); ]);
@@ -208,6 +218,7 @@ class DelegationTest extends TestCase
/** /**
* This ensures searching for a valid user works * This ensures searching for a valid user works
*
* @test * @test
*/ */
public function it_should_return_one_result_for_specified_user() public function it_should_return_one_result_for_specified_user()
@@ -231,6 +242,7 @@ class DelegationTest extends TestCase
/** /**
* This ensures searching by case number and review the order * This ensures searching by case number and review the order
*
* @test * @test
*/ */
public function it_should_search_by_case_id_and_order_of_data() public function it_should_search_by_case_id_and_order_of_data()
@@ -306,6 +318,7 @@ class DelegationTest extends TestCase
/** /**
* This ensures searching by case title and review the page * This ensures searching by case title and review the page
*
* @test * @test
*/ */
public function it_should_search_by_case_title_and_pages_of_data_app_number_matches_case_title() public function it_should_search_by_case_title_and_pages_of_data_app_number_matches_case_title()
@@ -388,6 +401,7 @@ class DelegationTest extends TestCase
/** /**
* This ensures searching by task title and review the page * This ensures searching by task title and review the page
*
* @test * @test
*/ */
public function it_should_search_by_task_title_and_pages_of_data() public function it_should_search_by_task_title_and_pages_of_data()
@@ -395,14 +409,12 @@ class DelegationTest extends TestCase
factory(User::class, 100)->create(); factory(User::class, 100)->create();
factory(Process::class)->create(); factory(Process::class)->create();
$task = factory(Task::class)->create([ $task = factory(Task::class)->create([
'TAS_ID' => 1,
'TAS_TITLE' => 'Request task' 'TAS_TITLE' => 'Request task'
]); ]);
factory(Delegation::class, 5)->create([ factory(Delegation::class, 5)->create([
'TAS_ID' => $task->TAS_ID 'TAS_ID' => $task->TAS_ID
]); ]);
$task = factory(Task::class)->create([ $task = factory(Task::class)->create([
'TAS_ID' => 2,
'TAS_TITLE' => 'Account task' 'TAS_TITLE' => 'Account task'
]); ]);
factory(Delegation::class, 5)->create([ factory(Delegation::class, 5)->create([
@@ -436,6 +448,7 @@ class DelegationTest extends TestCase
/** /**
* This ensures searching by case title and review the page * This ensures searching by case title and review the page
*
* @test * @test
*/ */
public function it_should_search_by_case_title_and_pages_of_data_app_number_no_matches_case_title() public function it_should_search_by_case_title_and_pages_of_data_app_number_no_matches_case_title()
@@ -511,6 +524,7 @@ class DelegationTest extends TestCase
/** /**
* This ensures ordering ascending and descending works by case number APP_NUMBER * This ensures ordering ascending and descending works by case number APP_NUMBER
*
* @test * @test
*/ */
public function it_should_sort_by_case_id() public function it_should_sort_by_case_id()
@@ -543,6 +557,7 @@ class DelegationTest extends TestCase
/** /**
* This ensures ordering ascending and descending works by case title APP_TITLE * This ensures ordering ascending and descending works by case title APP_TITLE
*
* @test * @test
*/ */
public function it_should_sort_by_case_title() public function it_should_sort_by_case_title()
@@ -550,14 +565,12 @@ class DelegationTest extends TestCase
factory(User::class, 100)->create(); factory(User::class, 100)->create();
factory(Process::class)->create(); factory(Process::class)->create();
$application = factory(Application::class)->create([ $application = factory(Application::class)->create([
'APP_NUMBER' => 2001,
'APP_TITLE' => 'Request by Thomas' 'APP_TITLE' => 'Request by Thomas'
]); ]);
factory(Delegation::class)->create([ factory(Delegation::class)->create([
'APP_NUMBER' => $application->APP_NUMBER 'APP_NUMBER' => $application->APP_NUMBER
]); ]);
$application = factory(Application::class)->create([ $application = factory(Application::class)->create([
'APP_NUMBER' => 30002,
'APP_TITLE' => 'Request by Ariel' 'APP_TITLE' => 'Request by Ariel'
]); ]);
factory(Delegation::class)->create([ factory(Delegation::class)->create([
@@ -577,6 +590,7 @@ class DelegationTest extends TestCase
/** /**
* This ensures ordering ascending and descending works by case title APP_PRO_TITLE * This ensures ordering ascending and descending works by case title APP_PRO_TITLE
*
* @test * @test
*/ */
public function it_should_sort_by_process() public function it_should_sort_by_process()
@@ -620,6 +634,7 @@ class DelegationTest extends TestCase
/** /**
* This ensures ordering ascending and descending works by task title APP_TAS_TITLE * This ensures ordering ascending and descending works by task title APP_TAS_TITLE
*
* @test * @test
*/ */
public function it_should_sort_by_task_title() public function it_should_sort_by_task_title()
@@ -627,14 +642,12 @@ class DelegationTest extends TestCase
factory(User::class, 100)->create(); factory(User::class, 100)->create();
factory(Process::class)->create(); factory(Process::class)->create();
$task = factory(Task::class)->create([ $task = factory(Task::class)->create([
'TAS_ID' => 1000,
'TAS_TITLE' => 'Initiate Request' 'TAS_TITLE' => 'Initiate Request'
]); ]);
factory(Delegation::class)->create([ factory(Delegation::class)->create([
'TAS_ID' => $task->TAS_ID 'TAS_ID' => $task->TAS_ID
]); ]);
$task = factory(Task::class)->create([ $task = factory(Task::class)->create([
'TAS_ID' => 4000,
'TAS_TITLE' => 'Waiting for AP Manager Validation' 'TAS_TITLE' => 'Waiting for AP Manager Validation'
]); ]);
factory(Delegation::class)->create([ factory(Delegation::class)->create([
@@ -654,6 +667,7 @@ class DelegationTest extends TestCase
/** /**
* This ensures ordering ascending and descending works by current user * This ensures ordering ascending and descending works by current user
*
* @test * @test
*/ */
public function it_should_sort_by_user() public function it_should_sort_by_user()
@@ -694,6 +708,7 @@ class DelegationTest extends TestCase
/** /**
* This ensures ordering ordering ascending and descending works by last modified APP_UPDATE_DATE * This ensures ordering ordering ascending and descending works by last modified APP_UPDATE_DATE
*
* @test * @test
*/ */
public function it_should_sort_by_last_modified() public function it_should_sort_by_last_modified()
@@ -746,6 +761,7 @@ class DelegationTest extends TestCase
/** /**
* This ensures ordering ascending and descending works by due date DEL_TASK_DUE_DATE * This ensures ordering ascending and descending works by due date DEL_TASK_DUE_DATE
*
* @test * @test
*/ */
public function it_should_sort_by_due_date() public function it_should_sort_by_due_date()
@@ -789,6 +805,7 @@ class DelegationTest extends TestCase
/** /**
* This ensures ordering ascending and descending works by status APP_STATUS * This ensures ordering ascending and descending works by status APP_STATUS
*
* @test * @test
*/ */
public function it_should_sort_by_status() public function it_should_sort_by_status()
@@ -842,6 +859,7 @@ class DelegationTest extends TestCase
/** /**
* This checks to make sure filter by category is working properly * This checks to make sure filter by category is working properly
*
* @test * @test
*/ */
public function it_should_return_data_filtered_by_process_category() public function it_should_return_data_filtered_by_process_category()
@@ -881,6 +899,7 @@ class DelegationTest extends TestCase
/** /**
* This ensure the result is right when you search between two given dates * This ensure the result is right when you search between two given dates
*
* @test * @test
*/ */
public function it_should_return_right_data_between_two_dates() public function it_should_return_right_data_between_two_dates()
@@ -903,6 +922,7 @@ class DelegationTest extends TestCase
/** /**
* This ensure the result is right when you search from a given date * This ensure the result is right when you search from a given date
*
* @test * @test
*/ */
public function it_should_return_right_data_when_you_send_only_dateFrom_parameter() public function it_should_return_right_data_when_you_send_only_dateFrom_parameter()
@@ -924,6 +944,7 @@ class DelegationTest extends TestCase
/** /**
* This ensure the result is right when you search to a given date * This ensure the result is right when you search to a given date
*
* @test * @test
*/ */
public function it_should_return_right_data_when_you_send_only_dateTo_parameter() public function it_should_return_right_data_when_you_send_only_dateTo_parameter()
@@ -945,6 +966,7 @@ class DelegationTest extends TestCase
/** /**
* This ensures return the correct data by sequential * This ensures return the correct data by sequential
*
* @test * @test
*/ */
public function it_should_return_by_sequential_tasks_pages_of_data() public function it_should_return_by_sequential_tasks_pages_of_data()
@@ -993,6 +1015,7 @@ class DelegationTest extends TestCase
/** /**
* This ensures return the correct data by parallel task all threads CLOSED * This ensures return the correct data by parallel task all threads CLOSED
*
* @test * @test
*/ */
public function it_should_return_by_parallel_tasks_threads_closed() public function it_should_return_by_parallel_tasks_threads_closed()
@@ -1026,6 +1049,7 @@ class DelegationTest extends TestCase
/** /**
* This ensures return the correct data by parallel task all threads OPEN * This ensures return the correct data by parallel task all threads OPEN
*
* @test * @test
*/ */
public function it_should_return_by_parallel_tasks_threads_open() public function it_should_return_by_parallel_tasks_threads_open()
@@ -1045,6 +1069,7 @@ class DelegationTest extends TestCase
/** /**
* Review when the status is empty * Review when the status is empty
*
* @test * @test
*/ */
public function it_should_return_status_empty() public function it_should_return_status_empty()
@@ -1064,6 +1089,7 @@ class DelegationTest extends TestCase
/** /**
* Review when filter when the process and category does not have a relation * Review when filter when the process and category does not have a relation
*
* @test * @test
*/ */
public function it_should_return_process_and_category_does_not_have_a_relation() public function it_should_return_process_and_category_does_not_have_a_relation()
@@ -1087,15 +1113,18 @@ class DelegationTest extends TestCase
'PRO_ID' => $processNoCategory->id 'PRO_ID' => $processNoCategory->id
]); ]);
//Search the cases related to the category and process does not have relation //Search the cases related to the category and process does not have relation
$results = Delegation::search(null, 0, 25, null, $processWithCat->id, null, null, null, $category[1]->CATEGORY_UID); $results = Delegation::search(null, 0, 25, null, $processWithCat->id, null, null, null,
$category[1]->CATEGORY_UID);
$this->assertCount(0, $results['data']); $this->assertCount(0, $results['data']);
//Search the cases related to the category and process does not have relation //Search the cases related to the category and process does not have relation
$results = Delegation::search(null, 0, 25, null, $processNoCategory->id, null, null, null, $category[0]->CATEGORY_UID); $results = Delegation::search(null, 0, 25, null, $processNoCategory->id, null, null, null,
$category[0]->CATEGORY_UID);
$this->assertCount(0, $results['data']); $this->assertCount(0, $results['data']);
} }
/** /**
* Review when filter when the process and category does have a relation * Review when filter when the process and category does have a relation
*
* @test * @test
*/ */
public function it_should_return_process_and_category_does_have_a_relation() public function it_should_return_process_and_category_does_have_a_relation()
@@ -1119,7 +1148,8 @@ class DelegationTest extends TestCase
'PRO_ID' => $process->id, 'PRO_ID' => $process->id,
]); ]);
//Search the cases when the category and process does have relation with a category //Search the cases when the category and process does have relation with a category
$results = Delegation::search(null, 0, 25, null, $processWithCat->id, null, null, null, $category->CATEGORY_UID); $results = Delegation::search(null, 0, 25, null, $processWithCat->id, null, null, null,
$category->CATEGORY_UID);
$this->assertCount(1, $results['data']); $this->assertCount(1, $results['data']);
//Search the cases when the category and process does have relation with category empty //Search the cases when the category and process does have relation with category empty
$results = Delegation::search(null, 0, 25, null, $process->id, null, null, null, ''); $results = Delegation::search(null, 0, 25, null, $process->id, null, null, null, '');
@@ -1128,6 +1158,7 @@ class DelegationTest extends TestCase
/** /**
* Check if return participation information * Check if return participation information
*
* @test * @test
*/ */
public function it_should_return_participation_info() public function it_should_return_participation_info()
@@ -1158,6 +1189,7 @@ class DelegationTest extends TestCase
/** /**
* Check if return an empty participation information * Check if return an empty participation information
*
* @test * @test
*/ */
public function it_should_return_empty_participation_info() public function it_should_return_empty_participation_info()
@@ -1171,7 +1203,8 @@ class DelegationTest extends TestCase
/** /**
* This checks the counters is working properly in self-service user assigned * This checks the counters is working properly in self-service user assigned
* @covers Delegation::countSelfService *
* @covers ::countSelfService()
* @test * @test
*/ */
public function it_should_count_cases_by_user_with_self_service_user_assigned() public function it_should_count_cases_by_user_with_self_service_user_assigned()
@@ -1205,9 +1238,10 @@ class DelegationTest extends TestCase
} }
/** /**
* This checks the counters is working properly in self-service-value-based when the variable has a value related with the USR_UID * This checks the counters is working properly in self-service-value-based when the variable has a value related
* When the value assigned in the variable @@ARRAY_OF_USERS = [USR_UID] * with the USR_UID When the value assigned in the variable @@ARRAY_OF_USERS = [USR_UID]
* @covers Delegation::countSelfService *
* @covers ::countSelfService()
* @test * @test
*/ */
public function it_should_count_cases_by_user_with_self_service_value_based_usr_uid() public function it_should_count_cases_by_user_with_self_service_value_based_usr_uid()
@@ -1251,7 +1285,8 @@ class DelegationTest extends TestCase
/** /**
* This checks the counters is working properly in self-service and self-service value based * This checks the counters is working properly in self-service and self-service value based
* @covers Delegation::countSelfService *
* @covers ::countSelfService()
* @test * @test
*/ */
public function it_should_count_cases_by_user_with_self_service_mixed_with_self_service_value_based() public function it_should_count_cases_by_user_with_self_service_mixed_with_self_service_value_based()
@@ -1314,7 +1349,8 @@ class DelegationTest extends TestCase
/** /**
* This checks the counters is working properly in self-service group assigned * This checks the counters is working properly in self-service group assigned
* @covers Delegation::countSelfService *
* @covers ::countSelfService()
* @test * @test
*/ */
public function it_should_count_cases_by_user_with_self_service_group_assigned() public function it_should_count_cases_by_user_with_self_service_group_assigned()
@@ -1356,9 +1392,10 @@ class DelegationTest extends TestCase
} }
/** /**
* This checks the counters is working properly in self-service-value-based when the variable has a value related with the GRP_UID * This checks the counters is working properly in self-service-value-based when the variable has a value related
* When the value assigned in the variable @@ARRAY_OF_USERS = [GRP_UID] * with the GRP_UID When the value assigned in the variable @@ARRAY_OF_USERS = [GRP_UID]
* @covers Delegation::countSelfService *
* @covers ::countSelfService()
* @test * @test
*/ */
public function it_should_count_cases_by_user_with_self_service_value_based_grp_uid() public function it_should_count_cases_by_user_with_self_service_value_based_grp_uid()
@@ -1415,7 +1452,8 @@ class DelegationTest extends TestCase
/** /**
* This checks the counters is working properly in self-service user and group assigned in parallel task * This checks the counters is working properly in self-service user and group assigned in parallel task
* @covers Delegation::countSelfService *
* @covers ::countSelfService()
* @test * @test
*/ */
public function it_should_count_cases_by_user_with_self_service_user_and_group_assigned_parallel_task() public function it_should_count_cases_by_user_with_self_service_user_and_group_assigned_parallel_task()
@@ -1514,9 +1552,10 @@ class DelegationTest extends TestCase
} }
/** /**
* This checks the counters is working properly in self-service-value-based with GRP_UID and USR_UID in parallel task * This checks the counters is working properly in self-service-value-based with GRP_UID and USR_UID in parallel
* When the value assigned in the variable @@ARRAY_OF_USERS = [GRP_UID, USR_UID] * task When the value assigned in the variable @@ARRAY_OF_USERS = [GRP_UID, USR_UID]
* @covers Delegation::countSelfService *
* @covers ::countSelfService()
* @test * @test
*/ */
public function it_should_count_cases_by_user_with_self_service_value_based_usr_uid_and_grp_uid() public function it_should_count_cases_by_user_with_self_service_value_based_usr_uid_and_grp_uid()
@@ -1585,7 +1624,7 @@ class DelegationTest extends TestCase
/** /**
* This check if return the USR_UID assigned in the thread OPEN * This check if return the USR_UID assigned in the thread OPEN
* *
* @covers Delegation::getCurrentUser * @covers ::getCurrentUser()
* @test * @test
*/ */
public function it_should_return_current_user_for_thread_open() public function it_should_return_current_user_for_thread_open()
@@ -1618,7 +1657,7 @@ class DelegationTest extends TestCase
/** /**
* This check if return the USR_UID assigned in the thread CLOSED * This check if return the USR_UID assigned in the thread CLOSED
* *
* @covers Delegation::getCurrentUser * @covers ::getCurrentUser()
* @test * @test
*/ */
public function it_should_return_current_user_for_thread_closed() public function it_should_return_current_user_for_thread_closed()
@@ -1651,7 +1690,7 @@ class DelegationTest extends TestCase
/** /**
* This check if return empty when the data does not exits * This check if return empty when the data does not exits
* *
* @covers Delegation::getCurrentUser * @covers ::getCurrentUser()
* @test * @test
*/ */
public function it_should_return_empty_when_row_does_not_exist() public function it_should_return_empty_when_row_does_not_exist()
@@ -1687,7 +1726,7 @@ class DelegationTest extends TestCase
/** /**
* This checks if return the open thread * This checks if return the open thread
* *
* @covers Delegation::getOpenThreads * @covers ::getOpenThreads()
* @test * @test
*/ */
public function it_should_return_thread_open() public function it_should_return_thread_open()
@@ -1714,7 +1753,7 @@ class DelegationTest extends TestCase
/** /**
* This checks if return empty when the thread is CLOSED * This checks if return empty when the thread is CLOSED
* *
* @covers Delegation::getOpenThreads * @covers ::getOpenThreads()
* @test * @test
*/ */
public function it_should_return_empty_when_thread_is_closed() public function it_should_return_empty_when_thread_is_closed()
@@ -1738,7 +1777,7 @@ class DelegationTest extends TestCase
/** /**
* This checks if return empty when the data is not null * This checks if return empty when the data is not null
* *
* @covers Delegation::getOpenThreads * @covers ::getOpenThreads()
* @test * @test
*/ */
public function it_should_return_empty_when_thread_finish_date_is_not_null() public function it_should_return_empty_when_thread_finish_date_is_not_null()
@@ -1760,4 +1799,49 @@ class DelegationTest extends TestCase
$result = Delegation::getOpenThreads($application->APP_NUMBER, $task->TAS_UID); $result = Delegation::getOpenThreads($application->APP_NUMBER, $task->TAS_UID);
$this->assertEmpty($result); $this->assertEmpty($result);
} }
/**
* This checks if return the participation when the user does have participation
*
* @covers \ProcessMaker\Model\Delegation::participation()
* @test
*/
public function it_when_the_user_does_have_participation()
{
factory(Process::class)->create();
//Create user
$user = factory(User::class)->create();
$application = factory(Application::class)->create();
//Create a delegation
factory(Delegation::class)->create([
'APP_NUMBER' => $application->APP_NUMBER,
'APP_UID' => $application->APP_UID,
'USR_ID' => $user->USR_ID,
'USR_UID' => $user->USR_UID
]);
$result = Delegation::participation($application->APP_UID, $user->USR_UID);
$this->assertTrue($result);
}
/**
* This checks if return the participation of the user when the user does not have participation
*
* @covers \ProcessMaker\Model\Delegation::participation()
* @test
*/
public function it_when_the_user_does_not_have_participation()
{
factory(Process::class)->create();
//Create user
$user = factory(User::class)->create();
$application = factory(Application::class)->create();
//Create a delegation
factory(Delegation::class)->create([
'APP_NUMBER' => $application->APP_NUMBER,
'APP_UID' => $application->APP_UID
]);
$result = Delegation::participation($application->APP_UID, $user->USR_UID);
$this->assertFalse($result);
}
} }

View File

@@ -1,9 +1,18 @@
<?php <?php
/**
* cases_Resume.php
*
* Shows a brief information about the case
*
* @link https://wiki.processmaker.com/3.2/Cases/Cases#Participated
*/
use ProcessMaker\BusinessModel\Cases as BmCases;
use ProcessMaker\BusinessModel\Task as BusinessModelTask; use ProcessMaker\BusinessModel\Task as BusinessModelTask;
use ProcessMaker\Util\DateTime; use ProcessMaker\Util\DateTime;
/* Permissions */ /** Permissions */
switch ($RBAC->userCanAccess('PM_CASES')) { switch ($RBAC->userCanAccess('PM_CASES')) {
case -2: case -2:
G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_SYSTEM', 'error', 'labels'); G::SendTemporalMessage('ID_USER_HAVENT_RIGHTS_SYSTEM', 'error', 'labels');
@@ -17,33 +26,31 @@ switch ($RBAC->userCanAccess('PM_CASES')) {
break; break;
} }
/* GET , POST & $_SESSION Vars */ /** Menu's */
/* Menues */
$_SESSION['bNoShowSteps'] = true; $_SESSION['bNoShowSteps'] = true;
$G_MAIN_MENU = 'processmaker'; $G_MAIN_MENU = 'processmaker';
$G_SUB_MENU = 'caseOptions'; $G_SUB_MENU = 'caseOptions';
$G_ID_MENU_SELECTED = 'CASES'; $G_ID_MENU_SELECTED = 'CASES';
$G_ID_SUB_MENU_SELECTED = '_'; $G_ID_SUB_MENU_SELECTED = '_';
/* Prepare page before to show */ /** Prepare page before to show */
$oCase = new Cases();
// Check the authorization // Check the authorization
$objCase = new \ProcessMaker\BusinessModel\Cases(); $objCase = new BmCases();
$aUserCanAccess = $objCase->userAuthorization( $userCanAccess = $objCase->userAuthorization(
$_SESSION['USER_LOGGED'], $_SESSION['USER_LOGGED'],
$_SESSION['PROCESS'], $_SESSION['PROCESS'],
$_GET['APP_UID'], $_GET['APP_UID'],
array('PM_ALLCASES'), ['PM_ALLCASES'],
array('SUMMARY_FORM' => 'VIEW') ['SUMMARY_FORM' => 'VIEW']
); );
$cases = new Cases();
if (isset($_SESSION['ACTION']) && ($_SESSION['ACTION'] == 'jump')) { if (isset($_SESSION['ACTION']) && ($_SESSION['ACTION'] == 'jump')) {
$Fields = $oCase->loadCase($_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['ACTION']); $Fields = $cases->loadCase($_SESSION['APPLICATION'], $_SESSION['INDEX'], $_SESSION['ACTION']);
$process = new Process(); $process = new Process();
$processData = $process->load($Fields['PRO_UID']); $processData = $process->load($Fields['PRO_UID']);
if (isset($processData['PRO_DYNAFORMS']['PROCESS']) && $processData['PRO_DYNAFORMS']['PROCESS'] != '' && if (isset($processData['PRO_DYNAFORMS']['PROCESS']) && $processData['PRO_DYNAFORMS']['PROCESS'] != '' &&
$aUserCanAccess['objectPermissions']['SUMMARY_FORM'] $userCanAccess['objectPermissions']['SUMMARY_FORM']
) { ) {
$_REQUEST['APP_UID'] = $Fields['APP_UID']; $_REQUEST['APP_UID'] = $Fields['APP_UID'];
$_REQUEST['DEL_INDEX'] = $Fields['DEL_INDEX']; $_REQUEST['DEL_INDEX'] = $Fields['DEL_INDEX'];
@@ -52,35 +59,30 @@ if (isset($_SESSION['ACTION']) && ($_SESSION['ACTION'] == 'jump')) {
exit(); exit();
} }
} else { } else {
$Fields = $oCase->loadCase($_SESSION['APPLICATION'], $_SESSION['INDEX']); $Fields = $cases->loadCase($_SESSION['APPLICATION'], $_SESSION['INDEX']);
} }
if (!$aUserCanAccess['participated'] && !$aUserCanAccess['supervisor'] && !$aUserCanAccess['rolesPermissions']['PM_ALLCASES'] && !$aUserCanAccess['objectPermissions']['SUMMARY_FORM']) { if (
$aMessage['MESSAGE'] = G::LoadTranslation('ID_NO_PERMISSION_NO_PARTICIPATED'); !$userCanAccess['participated'] &&
!$userCanAccess['supervisor'] &&
!$userCanAccess['rolesPermissions']['PM_ALLCASES'] &&
!$userCanAccess['objectPermissions']['SUMMARY_FORM']
) {
$message = [];
$message['MESSAGE'] = G::LoadTranslation('ID_NO_PERMISSION_NO_PARTICIPATED');
$G_PUBLISH = new Publisher(); $G_PUBLISH = new Publisher();
$G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $aMessage); $G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $message);
G::RenderPage('publishBlank', 'blank'); G::RenderPage('publishBlank', 'blank');
die(); die();
} }
if (isset($aRow['APP_TYPE'])) {
switch ($aRow['APP_TYPE']) {
case 'PAUSE':
$Fields['STATUS'] = ucfirst(strtolower(G::LoadTranslation('ID_PAUSED')));
break;
case 'CANCEL':
$Fields['STATUS'] = ucfirst(strtolower(G::LoadTranslation('ID_CANCELLED')));
break;
}
}
$actions = 'false'; $actions = 'false';
if (isset($_GET['action']) && $_GET['action'] == 'paused') { if (isset($_GET['action']) && $_GET['action'] == 'paused') {
$actions = 'true'; $actions = 'true';
} }
/* Render page */ /** Render page */
$oHeadPublisher = headPublisher::getSingleton(); $oHeadPublisher = headPublisher::getSingleton();
$oHeadPublisher->addScriptCode(" $oHeadPublisher->addScriptCode("
if (typeof parent != 'undefined') { if (typeof parent != 'undefined') {
if (parent.showCaseNavigatorPanel) { if (parent.showCaseNavigatorPanel) {
@@ -103,11 +105,11 @@ $oHeadPublisher->addScriptCode('
require_once 'classes/model/Process.php'; require_once 'classes/model/Process.php';
$objProc = new Process(); $objProc = new Process();
$aProc = $objProc->load($Fields['PRO_UID']); $processFields = $objProc->load($Fields['PRO_UID']);
$Fields['PRO_TITLE'] = $aProc['PRO_TITLE']; $Fields['PRO_TITLE'] = $processFields['PRO_TITLE'];
$objTask = new Task(); $objTask = new Task();
if (!isset($Fields['TAS_UID']) || $Fields['TAS_UID'] == '') { if (!isset($Fields['TAS_UID']) || empty($Fields['TAS_UID'])) {
$Fields['TAS_UID'] = $Fields['APP_DATA']['TASK']; $Fields['TAS_UID'] = $Fields['APP_DATA']['TASK'];
} }
@@ -118,12 +120,12 @@ $tasksInParallel = array_filter($tasksInParallel, function ($value) {
$nTasksInParallel = count($tasksInParallel); $nTasksInParallel = count($tasksInParallel);
if ($nTasksInParallel > 1) { if ($nTasksInParallel > 1) {
$aTask = $objTask->load($tasksInParallel[$nTasksInParallel - 1]); $taskInfo = $objTask->load($tasksInParallel[$nTasksInParallel - 1]);
} else { } else {
$aTask = $objTask->load($Fields['TAS_UID']); $taskInfo = $objTask->load($Fields['TAS_UID']);
} }
$Fields['TAS_TITLE'] = $aTask['TAS_TITLE']; $Fields['TAS_TITLE'] = $taskInfo['TAS_TITLE'];
$Fields = DateTime::convertUtcToTimeZone($Fields); $Fields = DateTime::convertUtcToTimeZone($Fields);
$objUser = new Users(); $objUser = new Users();

View File

@@ -11,6 +11,7 @@ use AppDelegationPeer;
use AppDocument; use AppDocument;
use AppDocumentPeer; use AppDocumentPeer;
use AppHistoryPeer; use AppHistoryPeer;
use Application;
use ApplicationPeer; use ApplicationPeer;
use Applications; use Applications;
use AppNotesPeer; use AppNotesPeer;
@@ -45,7 +46,6 @@ use ProcessMaker\Services\OAuth2\Server;
use ProcessMaker\Util\DateTime as UtilDateTime; use ProcessMaker\Util\DateTime as UtilDateTime;
use ProcessMaker\Validation\ExceptionRestApi; use ProcessMaker\Validation\ExceptionRestApi;
use ProcessMaker\Validation\Validator as FileValidator; use ProcessMaker\Validation\Validator as FileValidator;
use ProcessPeer; use ProcessPeer;
use ProcessUser; use ProcessUser;
use ProcessUserPeer; use ProcessUserPeer;
@@ -3317,6 +3317,7 @@ class Cases
* @param array $objectPermissions, the permissions that we need to review * @param array $objectPermissions, the permissions that we need to review
* @param boolean $objectSupervisor, if we need to get all the objects supervisor * @param boolean $objectSupervisor, if we need to get all the objects supervisor
* @param string $tasUid * @param string $tasUid
*
* @return array * @return array
*/ */
public function userAuthorization( public function userAuthorization(
@@ -3331,9 +3332,7 @@ class Cases
$arrayAccess = []; $arrayAccess = [];
// User has participated // User has participated
$participated = new ListParticipatedLast(); $arrayAccess['participated'] = Delegation::participation($appUid, $usrUid);
$listParticipated = $participated->loadList($usrUid, [], null, $appUid);
$arrayAccess['participated'] = (count($listParticipated) == 0) ? false : true;
// User is supervisor // User is supervisor
$supervisor = new BmProcessSupervisor(); $supervisor = new BmProcessSupervisor();

View File

@@ -563,4 +563,22 @@ class Delegation extends Model
return $arrayOpenThreads; return $arrayOpenThreads;
} }
/**
* Return if the user has participation in the case
*
* @param string $appUid, Case key
* @param string $userUid, User key
*
* @return boolean
*/
public static function participation($appUid, $userUid)
{
$query = Delegation::query()->select();
$query->where('APP_UID', $appUid);
$query->where('USR_UID', $userUid);
$query->limit(1);
return ($query->count() > 0);
}
} }