From 1cfba144c8041bf07e4cca8f47ac10922d9e4e24 Mon Sep 17 00:00:00 2001 From: Roly Gutierrez Date: Mon, 23 Aug 2021 11:05:58 -0400 Subject: [PATCH 1/3] PMCORE-3237 Service - Validation import custom case list --- .../src/ProcessMaker/Model/CaseListTest.php | 11 ++- .../translations/english/processmaker.en.po | 18 +++++ workflow/engine/data/mysql/insert.sql | 3 + .../src/ProcessMaker/Model/CaseList.php | 69 +++++++++++++++++-- 4 files changed, 93 insertions(+), 8 deletions(-) diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/CaseListTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/CaseListTest.php index 5deceb05c..87f500e3c 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/CaseListTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/CaseListTest.php @@ -281,15 +281,17 @@ class CaseListTest extends TestCase */ public function it_should_test_import() { + $additionalTables = factory(AdditionalTables::class)->create(); $data = [ 'type' => 'inbox', 'name' => 'test1', 'description' => 'my description', - 'tableUid' => '', + 'tableUid' => $additionalTables->ADD_TAB_UID, 'columns' => [], 'iconList' => 'deafult.png', 'iconColor' => 'red', - 'iconColorScreen' => 'blue' + 'iconColorScreen' => 'blue', + 'tableName' => $additionalTables->ADD_TAB_NAME ]; $json = json_encode($data); $tempFile = sys_get_temp_dir() . '/test_' . random_int(10000, 99999); @@ -300,7 +302,10 @@ class CaseListTest extends TestCase 'error' => 0 ] ]; - $request_data = []; + $request_data = [ + 'invalidFields' => 'continue', + 'duplicateName' => 'continue' + ]; $ownerId = 1; $result = CaseList::import($request_data, $ownerId); diff --git a/workflow/engine/content/translations/english/processmaker.en.po b/workflow/engine/content/translations/english/processmaker.en.po index 0d0fd93de..7481705ff 100755 --- a/workflow/engine/content/translations/english/processmaker.en.po +++ b/workflow/engine/content/translations/english/processmaker.en.po @@ -3515,6 +3515,12 @@ msgstr "No actions available for this case." msgid "Case Demo" msgstr "Case Demo" +# TRANSLATION +# LABEL/ID_CASELIST_CAN_NOT_BE_IMPORTED_THE_PMTABLE_NOT_EXIST +#: LABEL/ID_CASELIST_CAN_NOT_BE_IMPORTED_THE_PMTABLE_NOT_EXIST +msgid "Custom Case List {0} can not be imported because the PM Table does not exist in this Workspace." +msgstr "Custom Case List {0} can not be imported because the PM Table does not exist in this Workspace." + # TRANSLATION # LABEL/ID_CASE_DELETE_SUCCESFULLY #: LABEL/ID_CASE_DELETE_SUCCESFULLY @@ -10043,6 +10049,12 @@ msgstr "Group already exists. You need set an action to continue. Available acti msgid "Project already exists. Set an action to continue. Available actions: [{0}]." msgstr "Project already exists. Set an action to continue. Available actions: [{0}]." +# TRANSLATION +# LABEL/ID_IMPORTING_CASELIST_WITH_THE_SAME_NAME_SELECT_OPTION +#: LABEL/ID_IMPORTING_CASELIST_WITH_THE_SAME_NAME_SELECT_OPTION +msgid "You are about importing a Case List with the same name {0}, please select an option." +msgstr "You are about importing a Case List with the same name {0}, please select an option." + # TRANSLATION # LABEL/ID_IMPORTING_ERROR #: LABEL/ID_IMPORTING_ERROR @@ -21929,6 +21941,12 @@ msgstr "The PM Table associated with this DynaForm could not be found." msgid "The data from this case was saved in the database, but it was not saved in the PM Table, which it couldn't be found." msgstr "The data from this case was saved in the database, but it was not saved in the PM Table, which it couldn't be found." +# TRANSLATION +# LABEL/ID_PMTABLE_NOT_HAVE_ALL_CASELIST_FIELDS_WOULD_YOU_LIKE_CONTINUE +#: LABEL/ID_PMTABLE_NOT_HAVE_ALL_CASELIST_FIELDS_WOULD_YOU_LIKE_CONTINUE +msgid "The PM Table {0} does not have all the Custom Case List fields for file {1}. Would you like continue?" +msgstr "The PM Table {0} does not have all the Custom Case List fields for file {1}. Would you like continue?" + # TRANSLATION # LABEL/ID_PMTABLE_NOT_IMPORT_HAS_ERRORS #: LABEL/ID_PMTABLE_NOT_IMPORT_HAS_ERRORS diff --git a/workflow/engine/data/mysql/insert.sql b/workflow/engine/data/mysql/insert.sql index 4c09f2da4..ab16e55a8 100755 --- a/workflow/engine/data/mysql/insert.sql +++ b/workflow/engine/data/mysql/insert.sql @@ -57392,6 +57392,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE ( 'LABEL','ID_CASE','en','Case','2014-01-15') , ( 'LABEL','ID_CASECANCEL','en','No actions available for this case.','2014-01-15') , ( 'LABEL','ID_CASEDEMO','en','Case Demo','2014-01-15') , +( 'LABEL','ID_CASELIST_CAN_NOT_BE_IMPORTED_THE_PMTABLE_NOT_EXIST','en','Custom Case List {0} can not be imported because the PM Table does not exist in this Workspace.','2021-08-20') , ( 'LABEL','ID_CASE_DELETE_SUCCESFULLY','en','The Case was deleted successfully.','2020-01-08') , ( 'LABEL','ID_CASE_UID','en','Case Uid','2021-04-04') , ( 'LABEL','ID_CASES','en','HOME','2014-01-15') , @@ -58523,6 +58524,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE ( 'LABEL','ID_IMPORTER_FILE_PROCESSMAKER_PROJECT_VERSION_IS_MISSING','en','ProcessMaker Project version is missing on file source.','2014-05-20') , ( 'LABEL','ID_IMPORTER_GROUP_ALREADY_EXISTS_SET_ACTION_TO_CONTINUE','en','Group already exists. You need set an action to continue. Available actions: [{0}].','2014-10-21') , ( 'LABEL','ID_IMPORTER_PROJECT_ALREADY_EXISTS_SET_ACTION_TO_CONTINUE','en','Project already exists. Set an action to continue. Available actions: [{0}].','2014-10-21') , +( 'LABEL','ID_IMPORTING_CASELIST_WITH_THE_SAME_NAME_SELECT_OPTION','en','You are about importing a Case List with the same name {0}, please select an option.','2021-08-20') , ( 'LABEL','ID_IMPORTING_ERROR','en','Importing Error','2014-01-15') , ( 'LABEL','ID_IMPORTING_USERS','en','Importing Users...','2015-09-15') , ( 'LABEL','ID_IMPORT_ALREADY_EXISTS','en','The process you are trying to import already exists. Please select one of the following options to continue:','2014-10-21') , @@ -60553,6 +60555,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE ( 'LABEL','ID_PMTABLE_INVALID_NAME','en','Could not create the table with the name "{0}" because it is a reserved word.','2014-01-15') , ( 'LABEL','ID_PMTABLE_NOT_FOUND','en','The PM Table associated with this DynaForm could not be found.','2014-11-12') , ( 'LABEL','ID_PMTABLE_NOT_FOUNDED_SAVED_DATA','en','The data from this case was saved in the database, but it was not saved in the PM Table, which it couldn''t be found.','2014-11-12') , +( 'LABEL','ID_PMTABLE_NOT_HAVE_ALL_CASELIST_FIELDS_WOULD_YOU_LIKE_CONTINUE','en','The PM Table {0} does not have all the Custom Case List fields for file {1}. Would you like continue?','2014-11-12') , ( 'LABEL','ID_PMTABLE_NOT_IMPORT_HAS_ERRORS','en','File "{0}" was not imported has errors:','2016-02-18') , ( 'LABEL','ID_PMTABLE_PRIMARY_KEY_FIELD_IS_MISSING_IN_ATTRIBUTE','en','The primary key field {0} of the PM Table is missing in the attribute {1}.','2014-05-20') , ( 'LABEL','ID_PMTABLE_REQUIRED','en','It is required to select a PM table','2014-10-27') , diff --git a/workflow/engine/src/ProcessMaker/Model/CaseList.php b/workflow/engine/src/ProcessMaker/Model/CaseList.php index 690307326..7c4148be5 100644 --- a/workflow/engine/src/ProcessMaker/Model/CaseList.php +++ b/workflow/engine/src/ProcessMaker/Model/CaseList.php @@ -7,6 +7,7 @@ use G; use ProcessMaker\BusinessModel\Table; use ProcessMaker\Core\System; use ProcessMaker\Model\AdditionalTables; +use ProcessMaker\Model\Fields; use ProcessMaker\Model\User; use Illuminate\Database\Eloquent\Model; @@ -246,7 +247,8 @@ class CaseList extends Model ->leftJoin('USERS', 'USERS.USR_ID', '=', 'CASE_LIST.USR_ID') ->leftJoin('ADDITIONAL_TABLES', 'ADDITIONAL_TABLES.ADD_TAB_UID', '=', 'CASE_LIST.ADD_TAB_UID') ->select([ - 'CASE_LIST.*' + 'CASE_LIST.*', + 'ADDITIONAL_TABLES.ADD_TAB_NAME' ]) ->get() ->first(); @@ -256,6 +258,7 @@ class CaseList extends Model $result = CaseList::getAliasFromColumnName($model->toArray()); $result['columns'] = json_decode($result['columns']); + $result['tableName'] = $model->ADD_TAB_NAME; //clean invalid items unset($result['id']); @@ -275,21 +278,77 @@ class CaseList extends Model /** * The import requires a $ _FILES content in json format to create a record. - * @param array $request_data + * @param array $requestData * @param int $ownerId * @return array * @throws Exception */ - public static function import(array $request_data, int $ownerId) + public static function import(array $requestData, int $ownerId) { if ($_FILES['file_content']['error'] !== UPLOAD_ERR_OK || $_FILES['file_content']['tmp_name'] === '') { - throw new Exception(G::LoadTranslation('ID_ERROR_UPLOADING_FILENAME')); + throw new Exception(G::LoadTranslation('ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR')); } $content = file_get_contents($_FILES['file_content']['tmp_name']); try { $array = json_decode($content, true); - $caseList = CaseList::createSetting($array, $ownerId); + + $tableName = $array['tableName']; + unset($array['tableName']); + + //the pmtable not exist + $table = AdditionalTables::where('ADD_TAB_NAME', '=', $tableName) + ->get() + ->first(); + if ($table === null) { + return [ + 'status' => 'tableNotExist', + 'message' => G::LoadTranslation('ID_CASELIST_CAN_NOT_BE_IMPORTED_THE_PMTABLE_NOT_EXIST', [$_FILES['file_content']['name']]) + ]; + } + $array['tableUid'] = $table->ADD_TAB_UID; + + //the fields have differences between the import file and the current table + $requestData['invalidFields'] = $requestData['invalidFields'] ?? ''; + if ($requestData['invalidFields'] !== 'continue') { + $fields = Fields::where('ADD_TAB_UID', '=', $array['tableUid']) + ->whereNotIn('FLD_NAME', self::$excludeColumns) + ->select('FLD_NAME') + ->get() + ->transform(function ($object) { + return $object->FLD_NAME; + }) + ->toArray(); + foreach ($array['columns'] as $value) { + if (!in_array($value['field'], $fields)) { + return [ + 'status' => 'invalidFields', + 'message' => G::LoadTranslation('ID_PMTABLE_NOT_HAVE_ALL_CASELIST_FIELDS_WOULD_YOU_LIKE_CONTINUE', [$tableName, $_FILES['file_content']['name']]) + ]; + } + } + } + + //the name of the case list already exist + $list = CaseList::where('CAL_NAME', '=', $array['name']) + ->get() + ->first(); + $requestData['duplicateName'] = $requestData['duplicateName'] ?? ''; + if ($requestData['duplicateName'] !== 'continue') { + if ($list !== null) { + return [ + 'status' => 'duplicateName', + 'message' => G::LoadTranslation('ID_IMPORTING_CASELIST_WITH_THE_SAME_NAME_SELECT_OPTION', [$array['name']]) + ]; + } + } + + if ($requestData['duplicateName'] === 'continue' && $list !== null) { + $caseList = CaseList::updateSetting($list->CAL_ID, $array, $ownerId); + } else { + $caseList = CaseList::createSetting($array, $ownerId); + } + $result = CaseList::getAliasFromColumnName($caseList->toArray()); return $result; } catch (Exception $e) { From 35af0a98267bfee410ed11324572143314afac44 Mon Sep 17 00:00:00 2001 From: fabio Date: Mon, 23 Aug 2021 12:43:10 -0400 Subject: [PATCH 2/3] PMCORE-3213:Review the default columns in the new case list panel Corrections --- .../settings/customCaseList/Api/CaseList.js | 9 ++++++-- .../settings/customCaseList/Api/Services.js | 1 + .../customCaseList/CaseListSketch.vue | 21 ++++++++++++++++--- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/resources/assets/js/admin/settings/customCaseList/Api/CaseList.js b/resources/assets/js/admin/settings/customCaseList/Api/CaseList.js index 552e5dcaf..c41382739 100644 --- a/resources/assets/js/admin/settings/customCaseList/Api/CaseList.js +++ b/resources/assets/js/admin/settings/customCaseList/Api/CaseList.js @@ -56,8 +56,13 @@ class caseListApi extends Api { keys: {} }); } - getDefault(module){ - return Defaults[module] + getDefault(type){ + return this.get({ + service: 'DEFAULT_COLUMNS', + keys: { + type: type + } + }); } createCaseList(data) { return this.post({ diff --git a/resources/assets/js/admin/settings/customCaseList/Api/Services.js b/resources/assets/js/admin/settings/customCaseList/Api/Services.js index e6cc594f4..f21b65475 100644 --- a/resources/assets/js/admin/settings/customCaseList/Api/Services.js +++ b/resources/assets/js/admin/settings/customCaseList/Api/Services.js @@ -5,5 +5,6 @@ export default { CASE_LIST_PAUSED: "/caseList/paused", REPORT_TABLES: "/caseList/report-tables", CASE_LIST: "/caseList", + DEFAULT_COLUMNS: "/caseList/{type}/default-columns", PUT_CASE_LIST: "/caseList/{id}" }; diff --git a/resources/assets/js/admin/settings/customCaseList/CaseListSketch.vue b/resources/assets/js/admin/settings/customCaseList/CaseListSketch.vue index be8d4f598..97bf78754 100644 --- a/resources/assets/js/admin/settings/customCaseList/CaseListSketch.vue +++ b/resources/assets/js/admin/settings/customCaseList/CaseListSketch.vue @@ -367,7 +367,7 @@ export default { count: "", }, }, - defaultCaseList: null, + defaultCaseList: [], isValidName: null, isValidTable: null, pmTable: null @@ -379,8 +379,7 @@ export default { }, }, mounted() { - this.defaultCaseList = Api.getDefault(this.module.key); - this.dataCaseList = this.defaultCaseList; + this.getDefaultColumns(this.module.key); if(this.params.id) { this.editMode(); } @@ -675,6 +674,22 @@ export default { variant: variant, solid: true }) + }, + /** + * Get default Columns + * @param {string} type + */ + getDefaultColumns(type) { + let that = this; + if (!this.params.columns) { + Api.getDefault(type) + .then((response) => { + that.dataCaseList = response.data; + }) + .catch((e) => { + console.error(e); + }) + } } }, }; From 0234fcc59c2a347e4ce0743f60d96763c46a0f63 Mon Sep 17 00:00:00 2001 From: Andrea Adamczyk Date: Mon, 23 Aug 2021 15:19:23 -0400 Subject: [PATCH 3/3] PMCORE-3238 --- workflow/engine/src/ProcessMaker/BusinessModel/Cases.php | 2 +- workflow/engine/src/ProcessMaker/Model/Delegation.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php index af167f8a0..99b3829a5 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php @@ -882,7 +882,7 @@ class Cases public function participation($usrUid, $caseNumber, $index) { $userId = User::getId($usrUid); - $query = Delegation::query()->select(['APP_NUMBER'])->case($caseNumber)->index($index)->threadOpen(); + $query = Delegation::query()->select(['APP_NUMBER'])->case($caseNumber)->index($index)->openAndPause(); $query1 = clone $query; $result = $query->userId($userId)->limit(1)->get()->values()->toArray(); $permission = empty($result) ? false : true; diff --git a/workflow/engine/src/ProcessMaker/Model/Delegation.php b/workflow/engine/src/ProcessMaker/Model/Delegation.php index d0b44bf10..22d9772b3 100644 --- a/workflow/engine/src/ProcessMaker/Model/Delegation.php +++ b/workflow/engine/src/ProcessMaker/Model/Delegation.php @@ -1989,8 +1989,8 @@ class Delegation extends Model ]); // Join with task $query->joinTask(); - // Get the open threads - $query->threadOpen(); + // Get the open and paused threads + $query->openAndPause(); // Related to the specific case number $query->case($appNumber); // Get the results