From 2757bf7f644e205e82772e62b7709c8c76ecacc6 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Thu, 4 Jun 2020 10:38:48 -0400 Subject: [PATCH 01/10] PMCORE-1542 --- database/factories/DocumentsFactory.php | 54 +++++ gulliver/system/class.g.php | 2 + tests/resources/images/activate.png | Bin 0 -> 750 bytes tests/resources/images/activity.gif | Bin 0 -> 6610 bytes .../ProcessMaker/BusinessModel/CasesTest.php | 59 ++++++ .../src/ProcessMaker/Model/DocumentsTest.php | 29 +++ .../Util/Helpers/SaveAppDocumentTest.php | 47 +++++ workflow/engine/classes/WsBase.php | 21 +- workflow/engine/classes/class.pmFunctions.php | 6 +- .../model/map/AppDocumentMapBuilder.php | 4 +- .../classes/model/map/AppNotesMapBuilder.php | 4 +- .../classes/model/om/BaseAppDocument.php | 186 ++++++++++++------ .../classes/model/om/BaseAppDocumentPeer.php | 23 ++- .../engine/classes/model/om/BaseAppNotes.php | 156 ++++++++++----- .../classes/model/om/BaseAppNotesPeer.php | 23 ++- workflow/engine/config/schema.xml | 9 +- workflow/engine/data/mysql/schema.sql | 3 + .../src/ProcessMaker/BusinessModel/Cases.php | 134 +++++++++++++ .../src/ProcessMaker/Model/AppNotes.php | 36 ++++ .../src/ProcessMaker/Model/Documents.php | 96 +++++++++ .../engine/src/ProcessMaker/Util/helpers.php | 36 ++++ 21 files changed, 781 insertions(+), 147 deletions(-) create mode 100644 database/factories/DocumentsFactory.php create mode 100644 tests/resources/images/activate.png create mode 100644 tests/resources/images/activity.gif create mode 100644 tests/unit/workflow/engine/src/ProcessMaker/Model/DocumentsTest.php create mode 100644 tests/unit/workflow/engine/src/ProcessMaker/Util/Helpers/SaveAppDocumentTest.php create mode 100644 workflow/engine/src/ProcessMaker/Model/Documents.php diff --git a/database/factories/DocumentsFactory.php b/database/factories/DocumentsFactory.php new file mode 100644 index 000000000..acfafb0ce --- /dev/null +++ b/database/factories/DocumentsFactory.php @@ -0,0 +1,54 @@ +define(\ProcessMaker\Model\Documents::class, function (Faker $faker) { + $types = ['INPUT', 'OUTPUT', 'ATTACHED']; + $type = $faker->randomElement($types); + return [ + 'APP_DOC_UID' => G::generateUniqueID(), + 'APP_DOC_FILENAME' => 'image.png', + 'APP_DOC_TITLE' => '', + 'APP_DOC_COMMENT' => '', + 'DOC_VERSION' => 1, + 'APP_UID' => G::generateUniqueID(), + 'DEL_INDEX' => 1, + 'DOC_UID' => G::generateUniqueID(), + 'USR_UID' => G::generateUniqueID(), + 'APP_DOC_TYPE' => $type, + 'APP_DOC_CREATE_DATE' => $faker->date(), + 'APP_DOC_INDEX' => 1, + 'FOLDER_UID' => G::generateUniqueID(), + 'APP_DOC_PLUGIN' => '', + 'APP_DOC_TAGS' => '', + 'APP_DOC_STATUS' => 'ACTIVE', + 'APP_DOC_STATUS_DATE' => $faker->date(), + 'APP_DOC_FIELDNAME' => '', + 'APP_DOC_DRIVE_DOWNLOAD' => '', + ]; +}); + +// Create a dynaform with the foreign keys +$factory->state(\ProcessMaker\Model\Documents::class, 'case_notes', function (Faker $faker) { + return [ + 'APP_DOC_UID' => G::generateUniqueID(), + 'APP_DOC_FILENAME' => 'image.png', + 'APP_DOC_TITLE' => '', + 'APP_DOC_COMMENT' => '', + 'DOC_VERSION' => 1, + 'APP_UID' => G::generateUniqueID(), + 'DEL_INDEX' => 1, + 'DOC_UID' => G::generateUniqueID(), + 'USR_UID' => G::generateUniqueID(), + 'APP_DOC_TYPE' => 'CASE_NOTE', + 'APP_DOC_CREATE_DATE' => $faker->date(), + 'APP_DOC_INDEX' => 1, + 'FOLDER_UID' => G::generateUniqueID(), + 'APP_DOC_PLUGIN' => '', + 'APP_DOC_TAGS' => '', + 'APP_DOC_STATUS' => 'ACTIVE', + 'APP_DOC_STATUS_DATE' => $faker->date(), + 'APP_DOC_FIELDNAME' => '', + 'APP_DOC_DRIVE_DOWNLOAD' => '', + ]; +}); diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index ee129521e..8e9e9af86 100644 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -2708,6 +2708,8 @@ class G $nameToSave = $filter->validateInput($nameToSave, "path"); @chmod($path . "/" . $nameToSave, $permission); umask($oldumask); + + return true; } catch (Exception $oException) { throw $oException; } diff --git a/tests/resources/images/activate.png b/tests/resources/images/activate.png new file mode 100644 index 0000000000000000000000000000000000000000..1be605c56c14b9b49d46d78d8f269193f1908316 GIT binary patch literal 750 zcmVPx#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2igi2 z6&wl0^#N%B00M4FL_t(I%cYXvOOsI?#-Gj2HJN7FQZ^jRJ2ituvx1N=Gy6BXjVQd4 zj3N?@b`kyl2fFE|4C$g9wJfx&rCS4o+RVW=b#uP&dwzaT7tR;Wx`-Y)HwT{2d7kh2 zdW50WIv5R5Tk#CkrjExgQB)7Jnbc08V)3S-I93z1;-aqr>Yc!3pAZFJ1z@gQq|ha?3>3W5YUF*k)E0j@dHn<+#ZBG5+1TmUD=Y-Kmv%7(0U z-ffh-08Dc*?LaccT!5`?!-=6PtB^+SGYXOrdOMM13XWn>wlXe2kO)dr*pM3lu;)ct zt0ScZ34*dD3<$(^5CFUYP?43Ktu2HDVU$G~RawQBv|uS47PlZA4rNJ*vOrVoK`_lB zHe}8P6s_XOY++{gSg2zg;#6R93*6c^$}I)HF3=clM1M;^W`9htvH}~~vqiMy2&Y@mU?wyDZEa!w>e9XRge%okz gol0cHUjhHBUvhNKI-;$=ZvX%Q07*qoM6N<$g00L$VgLXD literal 0 HcmV?d00001 diff --git a/tests/resources/images/activity.gif b/tests/resources/images/activity.gif new file mode 100644 index 0000000000000000000000000000000000000000..94d46c129f6bba02f2f0b230d9f4d2c7a48e1412 GIT binary patch literal 6610 zcmbW5S2!H(x`u}_hB11{5DYU2LV}PeAqax#(TQlmNR(*NjUK)C-Y239QKR?Xd+)tO z|A{SYueJBS);ik%*?agM+}Hhl&+|$~ieJEB7C;VY1pqobI~y7rva_>GN=ga~3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W@11E2QHZE&!9K-Pt^?sjEqfG4^ht|$H7yB!=o$n?VEFJyGvV$)rGz7$;0Je^V2?O ze;xF<*=iIA)e*zEm|$ppzlukP&_7cO7Fq>FFBi`5Wr!2h4*AHTe1vF^pnHAmCy_w5 zDiex$USrHmW+I3G@a{;U0NUzu)kE@f@(uEsquF9Tk9M6Pro+l%orr?@=5V7FhxAX)~mg(e3A z`24qrhkXqJMAeu?l-2+@bcR|9rzc@cG;8yAAuh5rB(fcy|+MWi)ZNh*fL9KR=V&mrDB7 z@px^_Yi^#d{_<>LDX3vT)y)w`AmLDWonX7!cI!z+jRrzG;htcc$w^0(EG)`&50H3# zx=${5sfulfE`PFOH)@j6pY1&!!s_OGrGfc_#0$p2hxstWfD7M~c{jm6=>!K7N9HbP zftm`V5P}o_`MV9fGba3mR7)>h>UfeVT$;u|C2~!2swrC5_}?}?)Ov#1pL!wmUtSV{ AkpKVy literal 0 HcmV?d00001 diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/CasesTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/CasesTest.php index 99778d4f2..3c7da31c5 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/CasesTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/CasesTest.php @@ -5,6 +5,8 @@ namespace ProcessMaker\BusinessModel; use Exception; use G; use ProcessMaker\Model\Application; +use ProcessMaker\Model\Delegation; +use ProcessMaker\Model\Documents; use RBAC; use Tests\TestCase; @@ -77,4 +79,61 @@ class CasesTest extends TestCase $case = new Cases(); $case->deleteCase($application->APP_UID, $_SESSION['USER_LOGGED']); } + + /** + * Review the upload file related to the case notes, an return an exception when the array is empty + * + * @covers \ProcessMaker\BusinessModel\Cases::uploadFilesInCaseNotes() + * + * @test + * @expectedException Exception + */ + public function it_return_exception_in_upload_files_related_case_note() + { + $application = factory(Application::class)->create(); + factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID + ]); + // Upload the file + $case = new Cases(); + // Return an exception because the files does not exist + $case->uploadFilesInCaseNotes('00000000000000000000000000000001', $application->APP_UID, $filesReferences = []); + } + + /** + * Review the upload file related to the case notes + * + * @covers \ProcessMaker\BusinessModel\Cases::uploadFilesInCaseNotes() + * + * @test + */ + public function it_should_upload_files_related_case_note() + { + $application = factory(Application::class)->create(); + factory(Delegation::class)->states('foreign_keys')->create([ + 'APP_NUMBER' => $application->APP_NUMBER, + 'APP_UID' => $application->APP_UID + ]); + // File reference to upload + $filesReferences = [ + 'activityRename.gif' => PATH_TRUNK . 'tests' . PATH_SEP . 'resources' . PATH_SEP . 'images' . PATH_SEP . 'activity.gif', + ]; + // Path of the case + $pathCase = PATH_DB . config('system.workspace') . PATH_SEP . 'files' . PATH_SEP . $application->APP_UID . PATH_SEP; + // Upload the file + $case = new Cases(); + $result = $case->uploadFilesInCaseNotes('00000000000000000000000000000001', $application->APP_UID, $filesReferences); + $result = head($result); + $this->assertNotEmpty($result); + $this->assertArrayHasKey('APP_UID', $result); + $this->assertEquals($application->APP_UID, $result['APP_UID']); + $this->assertArrayHasKey('APP_DOC_TYPE', $result); + $this->assertEquals(Documents::DOC_TYPE_CASE_NOTE, $result['APP_DOC_TYPE']); + $this->assertArrayHasKey('APP_DOC_FILENAME', $result); + $this->assertEquals('activityRename.gif', $result['APP_DOC_FILENAME']); + + // Remove the path created + G::rm_dir($pathCase); + } } diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DocumentsTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DocumentsTest.php new file mode 100644 index 000000000..bc882b79d --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DocumentsTest.php @@ -0,0 +1,29 @@ +states('case_notes')->create(); + $doc = new Documents(); + $res = $doc->getAppFiles($appDoc->APP_UID, Documents::DOC_TYPE_CASE_NOTE); + $this->assertNotEmpty($res); + } +} \ No newline at end of file diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Util/Helpers/SaveAppDocumentTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Util/Helpers/SaveAppDocumentTest.php new file mode 100644 index 000000000..4f1079a08 --- /dev/null +++ b/tests/unit/workflow/engine/src/ProcessMaker/Util/Helpers/SaveAppDocumentTest.php @@ -0,0 +1,47 @@ + PATH_TRUNK . 'tests' . PATH_SEP . 'resources' . PATH_SEP . 'images' . PATH_SEP . 'activate.png', + 'tmp_name' => PATH_TRUNK . 'tests' . PATH_SEP . 'resources' . PATH_SEP . 'images' . PATH_SEP . 'activate.png', + ]; + $appUid = G::generateUniqueID(); + $appDocUid = G::generateUniqueID(); + $pathCase = PATH_DB . config('system.workspace') . PATH_SEP . 'files' . PATH_SEP . G::getPathFromUID($appUid) . PATH_SEP; + saveAppDocument($files, $appUid, $appDocUid, 1, false); + $this->assertFileExists($pathCase . $appDocUid . '_1.png'); + G::rm_dir($pathCase); + } + + /** + * It test if the file reference was uploaded + * + * @test + */ + public function it_should_copy_file_different_name() + { + $files = [ + 'name' => 'activityRename.gif', + 'tmp_name' => PATH_TRUNK . 'tests' . PATH_SEP . 'resources' . PATH_SEP . 'images' . PATH_SEP . 'activity.gif', + ]; + $appUid = G::generateUniqueID(); + $appDocUid = G::generateUniqueID(); + $pathCase = PATH_DB . config('system.workspace') . PATH_SEP . 'files' . PATH_SEP . G::getPathFromUID($appUid) . PATH_SEP; + saveAppDocument($files, $appUid, $appDocUid, 1, false); + $this->assertFileExists($pathCase . $appDocUid . '_1.gif'); + G::rm_dir($pathCase); + } +} \ No newline at end of file diff --git a/workflow/engine/classes/WsBase.php b/workflow/engine/classes/WsBase.php index 898b2af56..48330d1cd 100644 --- a/workflow/engine/classes/WsBase.php +++ b/workflow/engine/classes/WsBase.php @@ -3420,16 +3420,17 @@ class WsBase /** * Add case note * - * @param string caseUid : ID of the case. - * @param string processUid : ID of the process. - * @param string taskUid : ID of the task. - * @param string userUid : The unique ID of the user who will add note case. - * @param string note : Note of the case. - * @param int sendMail : Optional parameter. If set to 1, will send an email to all participants in the case. + * @param string $caseUid, ID of the case. + * @param string $processUid, ID of the process. + * @param string $taskUid, ID of the task. + * @param string $userUid, The unique ID of the user who will add note case. + * @param string $note, Note of the case. + * @param int $sendMail, Optional parameter. If set to 1, will send an email to all participants in the case. + * @param array $files, Optional parameter. This is an array of files. * - * @return $result will return an object + * @return object */ - public function addCaseNote($caseUid, $processUid, $taskUid, $userUid, $note, $sendMail = 1) + public function addCaseNote($caseUid, $processUid, $taskUid, $userUid, $note, $sendMail = 1, $files = []) { try { if (empty($caseUid)) { @@ -3474,8 +3475,8 @@ class WsBase } //Add note case - $appNote = new AppNotes(); - $response = $appNote->addCaseNote($caseUid, $userUid, $note, $sendMail); + $appNote = new ProcessMaker\BusinessModel\Cases(); + $response = $appNote->addNote($caseUid, $userUid, $note, $sendMail, $files); //Response $result = new WsResponse(0, G::LoadTranslation("ID_COMMAND_EXECUTED_SUCCESSFULLY")); diff --git a/workflow/engine/classes/class.pmFunctions.php b/workflow/engine/classes/class.pmFunctions.php index e99854804..5193afb66 100644 --- a/workflow/engine/classes/class.pmFunctions.php +++ b/workflow/engine/classes/class.pmFunctions.php @@ -2887,13 +2887,15 @@ function PMFUnpauseCase ($caseUid, $delIndex, $userUid) * @param string(32) | $userUid | ID user | The unique ID of the user who will add note case. * @param string | $note | Note of the case | Note of the case. * @param int | $sendMail = 1 | Send mail | Optional parameter. If set to 1, will send an email to all participants in the case. + * @param array | $files | Array of files | An array of files (full paths) to be attached to the case notes. + * * @return int | $result | Result of the add a case note | Returns 1 if the note has been added to the case.; otherwise, returns 0 if an error occurred. * */ -function PMFAddCaseNote($caseUid, $processUid, $taskUid, $userUid, $note, $sendMail = 1) +function PMFAddCaseNote($caseUid, $processUid, $taskUid, $userUid, $note, $sendMail = 1, $files = []) { $ws = new WsBase(); - $result = $ws->addCaseNote($caseUid, $processUid, $taskUid, $userUid, $note, $sendMail); + $result = $ws->addCaseNote($caseUid, $processUid, $taskUid, $userUid, $note, $sendMail, $files); if ($result->status_code == 0) { return 1; diff --git a/workflow/engine/classes/model/map/AppDocumentMapBuilder.php b/workflow/engine/classes/model/map/AppDocumentMapBuilder.php index c0a6495d2..9e8ca2f1a 100644 --- a/workflow/engine/classes/model/map/AppDocumentMapBuilder.php +++ b/workflow/engine/classes/model/map/AppDocumentMapBuilder.php @@ -81,6 +81,8 @@ class AppDocumentMapBuilder $tMap->addColumn('DOC_UID', 'DocUid', 'string', CreoleTypes::VARCHAR, true, 32); + $tMap->addColumn('DOC_ID', 'DocId', 'int', CreoleTypes::INTEGER, false, null); + $tMap->addColumn('USR_UID', 'UsrUid', 'string', CreoleTypes::VARCHAR, true, 32); $tMap->addColumn('APP_DOC_TYPE', 'AppDocType', 'string', CreoleTypes::VARCHAR, true, 32); @@ -127,7 +129,7 @@ class AppDocumentMapBuilder $tMap->addValidator('USR_UID', 'required', 'propel.validator.RequiredValidator', '', 'User UID is required.'); - $tMap->addValidator('APP_DOC_TYPE', 'validValues', 'propel.validator.ValidValuesValidator', 'INPUT|OUTPUT|ATTACHED', 'Please select a valid document type.'); + $tMap->addValidator('APP_DOC_TYPE', 'validValues', 'propel.validator.ValidValuesValidator', 'INPUT|OUTPUT|ATTACHED|CASE_NOTE', 'Please select a valid document type.'); $tMap->addValidator('APP_DOC_TYPE', 'required', 'propel.validator.RequiredValidator', '', 'Application Document Type is required.'); diff --git a/workflow/engine/classes/model/map/AppNotesMapBuilder.php b/workflow/engine/classes/model/map/AppNotesMapBuilder.php index 469e66cda..90f497a0b 100644 --- a/workflow/engine/classes/model/map/AppNotesMapBuilder.php +++ b/workflow/engine/classes/model/map/AppNotesMapBuilder.php @@ -63,7 +63,9 @@ class AppNotesMapBuilder $tMap = $this->dbMap->addTable('APP_NOTES'); $tMap->setPhpName('AppNotes'); - $tMap->setUseIdGenerator(false); + $tMap->setUseIdGenerator(true); + + $tMap->addColumn('NOTE_ID', 'NoteId', 'int', CreoleTypes::INTEGER, true, null); $tMap->addColumn('APP_UID', 'AppUid', 'string', CreoleTypes::VARCHAR, true, 32); diff --git a/workflow/engine/classes/model/om/BaseAppDocument.php b/workflow/engine/classes/model/om/BaseAppDocument.php index d4874f670..ce2d5a86c 100644 --- a/workflow/engine/classes/model/om/BaseAppDocument.php +++ b/workflow/engine/classes/model/om/BaseAppDocument.php @@ -75,6 +75,12 @@ abstract class BaseAppDocument extends BaseObject implements Persistent */ protected $doc_uid = ''; + /** + * The value for the doc_id field. + * @var int + */ + protected $doc_id = 0; + /** * The value for the usr_uid field. * @var string @@ -255,6 +261,17 @@ abstract class BaseAppDocument extends BaseObject implements Persistent return $this->doc_uid; } + /** + * Get the [doc_id] column value. + * + * @return int + */ + public function getDocId() + { + + return $this->doc_id; + } + /** * Get the [usr_uid] column value. * @@ -616,6 +633,28 @@ abstract class BaseAppDocument extends BaseObject implements Persistent } // setDocUid() + /** + * Set the value of [doc_id] column. + * + * @param int $v new value + * @return void + */ + public function setDocId($v) + { + + // Since the native PHP type for this column is integer, + // we will cast the input value to an int (if it is not). + if ($v !== null && !is_int($v) && is_numeric($v)) { + $v = (int) $v; + } + + if ($this->doc_id !== $v || $v === 0) { + $this->doc_id = $v; + $this->modifiedColumns[] = AppDocumentPeer::DOC_ID; + } + + } // setDocId() + /** * Set the value of [usr_uid] column. * @@ -949,38 +988,40 @@ abstract class BaseAppDocument extends BaseObject implements Persistent $this->doc_uid = $rs->getString($startcol + 7); - $this->usr_uid = $rs->getString($startcol + 8); + $this->doc_id = $rs->getInt($startcol + 8); - $this->app_doc_type = $rs->getString($startcol + 9); + $this->usr_uid = $rs->getString($startcol + 9); - $this->app_doc_create_date = $rs->getTimestamp($startcol + 10, null); + $this->app_doc_type = $rs->getString($startcol + 10); - $this->app_doc_index = $rs->getInt($startcol + 11); + $this->app_doc_create_date = $rs->getTimestamp($startcol + 11, null); - $this->folder_uid = $rs->getString($startcol + 12); + $this->app_doc_index = $rs->getInt($startcol + 12); - $this->app_doc_plugin = $rs->getString($startcol + 13); + $this->folder_uid = $rs->getString($startcol + 13); - $this->app_doc_tags = $rs->getString($startcol + 14); + $this->app_doc_plugin = $rs->getString($startcol + 14); - $this->app_doc_status = $rs->getString($startcol + 15); + $this->app_doc_tags = $rs->getString($startcol + 15); - $this->app_doc_status_date = $rs->getTimestamp($startcol + 16, null); + $this->app_doc_status = $rs->getString($startcol + 16); - $this->app_doc_fieldname = $rs->getString($startcol + 17); + $this->app_doc_status_date = $rs->getTimestamp($startcol + 17, null); - $this->app_doc_drive_download = $rs->getString($startcol + 18); + $this->app_doc_fieldname = $rs->getString($startcol + 18); - $this->sync_with_drive = $rs->getString($startcol + 19); + $this->app_doc_drive_download = $rs->getString($startcol + 19); - $this->sync_permissions = $rs->getString($startcol + 20); + $this->sync_with_drive = $rs->getString($startcol + 20); + + $this->sync_permissions = $rs->getString($startcol + 21); $this->resetModified(); $this->setNew(false); // FIXME - using NUM_COLUMNS may be clearer. - return $startcol + 21; // 21 = AppDocumentPeer::NUM_COLUMNS - AppDocumentPeer::NUM_LAZY_LOAD_COLUMNS). + return $startcol + 22; // 22 = AppDocumentPeer::NUM_COLUMNS - AppDocumentPeer::NUM_LAZY_LOAD_COLUMNS). } catch (Exception $e) { throw new PropelException("Error populating AppDocument object", $e); @@ -1209,42 +1250,45 @@ abstract class BaseAppDocument extends BaseObject implements Persistent return $this->getDocUid(); break; case 8: - return $this->getUsrUid(); + return $this->getDocId(); break; case 9: - return $this->getAppDocType(); + return $this->getUsrUid(); break; case 10: - return $this->getAppDocCreateDate(); + return $this->getAppDocType(); break; case 11: - return $this->getAppDocIndex(); + return $this->getAppDocCreateDate(); break; case 12: - return $this->getFolderUid(); + return $this->getAppDocIndex(); break; case 13: - return $this->getAppDocPlugin(); + return $this->getFolderUid(); break; case 14: - return $this->getAppDocTags(); + return $this->getAppDocPlugin(); break; case 15: - return $this->getAppDocStatus(); + return $this->getAppDocTags(); break; case 16: - return $this->getAppDocStatusDate(); + return $this->getAppDocStatus(); break; case 17: - return $this->getAppDocFieldname(); + return $this->getAppDocStatusDate(); break; case 18: - return $this->getAppDocDriveDownload(); + return $this->getAppDocFieldname(); break; case 19: - return $this->getSyncWithDrive(); + return $this->getAppDocDriveDownload(); break; case 20: + return $this->getSyncWithDrive(); + break; + case 21: return $this->getSyncPermissions(); break; default: @@ -1275,19 +1319,20 @@ abstract class BaseAppDocument extends BaseObject implements Persistent $keys[5] => $this->getAppUid(), $keys[6] => $this->getDelIndex(), $keys[7] => $this->getDocUid(), - $keys[8] => $this->getUsrUid(), - $keys[9] => $this->getAppDocType(), - $keys[10] => $this->getAppDocCreateDate(), - $keys[11] => $this->getAppDocIndex(), - $keys[12] => $this->getFolderUid(), - $keys[13] => $this->getAppDocPlugin(), - $keys[14] => $this->getAppDocTags(), - $keys[15] => $this->getAppDocStatus(), - $keys[16] => $this->getAppDocStatusDate(), - $keys[17] => $this->getAppDocFieldname(), - $keys[18] => $this->getAppDocDriveDownload(), - $keys[19] => $this->getSyncWithDrive(), - $keys[20] => $this->getSyncPermissions(), + $keys[8] => $this->getDocId(), + $keys[9] => $this->getUsrUid(), + $keys[10] => $this->getAppDocType(), + $keys[11] => $this->getAppDocCreateDate(), + $keys[12] => $this->getAppDocIndex(), + $keys[13] => $this->getFolderUid(), + $keys[14] => $this->getAppDocPlugin(), + $keys[15] => $this->getAppDocTags(), + $keys[16] => $this->getAppDocStatus(), + $keys[17] => $this->getAppDocStatusDate(), + $keys[18] => $this->getAppDocFieldname(), + $keys[19] => $this->getAppDocDriveDownload(), + $keys[20] => $this->getSyncWithDrive(), + $keys[21] => $this->getSyncPermissions(), ); return $result; } @@ -1344,42 +1389,45 @@ abstract class BaseAppDocument extends BaseObject implements Persistent $this->setDocUid($value); break; case 8: - $this->setUsrUid($value); + $this->setDocId($value); break; case 9: - $this->setAppDocType($value); + $this->setUsrUid($value); break; case 10: - $this->setAppDocCreateDate($value); + $this->setAppDocType($value); break; case 11: - $this->setAppDocIndex($value); + $this->setAppDocCreateDate($value); break; case 12: - $this->setFolderUid($value); + $this->setAppDocIndex($value); break; case 13: - $this->setAppDocPlugin($value); + $this->setFolderUid($value); break; case 14: - $this->setAppDocTags($value); + $this->setAppDocPlugin($value); break; case 15: - $this->setAppDocStatus($value); + $this->setAppDocTags($value); break; case 16: - $this->setAppDocStatusDate($value); + $this->setAppDocStatus($value); break; case 17: - $this->setAppDocFieldname($value); + $this->setAppDocStatusDate($value); break; case 18: - $this->setAppDocDriveDownload($value); + $this->setAppDocFieldname($value); break; case 19: - $this->setSyncWithDrive($value); + $this->setAppDocDriveDownload($value); break; case 20: + $this->setSyncWithDrive($value); + break; + case 21: $this->setSyncPermissions($value); break; } // switch() @@ -1438,55 +1486,59 @@ abstract class BaseAppDocument extends BaseObject implements Persistent } if (array_key_exists($keys[8], $arr)) { - $this->setUsrUid($arr[$keys[8]]); + $this->setDocId($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { - $this->setAppDocType($arr[$keys[9]]); + $this->setUsrUid($arr[$keys[9]]); } if (array_key_exists($keys[10], $arr)) { - $this->setAppDocCreateDate($arr[$keys[10]]); + $this->setAppDocType($arr[$keys[10]]); } if (array_key_exists($keys[11], $arr)) { - $this->setAppDocIndex($arr[$keys[11]]); + $this->setAppDocCreateDate($arr[$keys[11]]); } if (array_key_exists($keys[12], $arr)) { - $this->setFolderUid($arr[$keys[12]]); + $this->setAppDocIndex($arr[$keys[12]]); } if (array_key_exists($keys[13], $arr)) { - $this->setAppDocPlugin($arr[$keys[13]]); + $this->setFolderUid($arr[$keys[13]]); } if (array_key_exists($keys[14], $arr)) { - $this->setAppDocTags($arr[$keys[14]]); + $this->setAppDocPlugin($arr[$keys[14]]); } if (array_key_exists($keys[15], $arr)) { - $this->setAppDocStatus($arr[$keys[15]]); + $this->setAppDocTags($arr[$keys[15]]); } if (array_key_exists($keys[16], $arr)) { - $this->setAppDocStatusDate($arr[$keys[16]]); + $this->setAppDocStatus($arr[$keys[16]]); } if (array_key_exists($keys[17], $arr)) { - $this->setAppDocFieldname($arr[$keys[17]]); + $this->setAppDocStatusDate($arr[$keys[17]]); } if (array_key_exists($keys[18], $arr)) { - $this->setAppDocDriveDownload($arr[$keys[18]]); + $this->setAppDocFieldname($arr[$keys[18]]); } if (array_key_exists($keys[19], $arr)) { - $this->setSyncWithDrive($arr[$keys[19]]); + $this->setAppDocDriveDownload($arr[$keys[19]]); } if (array_key_exists($keys[20], $arr)) { - $this->setSyncPermissions($arr[$keys[20]]); + $this->setSyncWithDrive($arr[$keys[20]]); + } + + if (array_key_exists($keys[21], $arr)) { + $this->setSyncPermissions($arr[$keys[21]]); } } @@ -1532,6 +1584,10 @@ abstract class BaseAppDocument extends BaseObject implements Persistent $criteria->add(AppDocumentPeer::DOC_UID, $this->doc_uid); } + if ($this->isColumnModified(AppDocumentPeer::DOC_ID)) { + $criteria->add(AppDocumentPeer::DOC_ID, $this->doc_id); + } + if ($this->isColumnModified(AppDocumentPeer::USR_UID)) { $criteria->add(AppDocumentPeer::USR_UID, $this->usr_uid); } @@ -1662,6 +1718,8 @@ abstract class BaseAppDocument extends BaseObject implements Persistent $copyObj->setDocUid($this->doc_uid); + $copyObj->setDocId($this->doc_id); + $copyObj->setUsrUid($this->usr_uid); $copyObj->setAppDocType($this->app_doc_type); diff --git a/workflow/engine/classes/model/om/BaseAppDocumentPeer.php b/workflow/engine/classes/model/om/BaseAppDocumentPeer.php index df748ac54..4aaeb0c1d 100644 --- a/workflow/engine/classes/model/om/BaseAppDocumentPeer.php +++ b/workflow/engine/classes/model/om/BaseAppDocumentPeer.php @@ -25,7 +25,7 @@ abstract class BaseAppDocumentPeer const CLASS_DEFAULT = 'classes.model.AppDocument'; /** The total number of columns. */ - const NUM_COLUMNS = 21; + const NUM_COLUMNS = 22; /** The number of lazy-loaded columns. */ const NUM_LAZY_LOAD_COLUMNS = 0; @@ -55,6 +55,9 @@ abstract class BaseAppDocumentPeer /** the column name for the DOC_UID field */ const DOC_UID = 'APP_DOCUMENT.DOC_UID'; + /** the column name for the DOC_ID field */ + const DOC_ID = 'APP_DOCUMENT.DOC_ID'; + /** the column name for the USR_UID field */ const USR_UID = 'APP_DOCUMENT.USR_UID'; @@ -105,10 +108,10 @@ abstract class BaseAppDocumentPeer * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ private static $fieldNames = array ( - BasePeer::TYPE_PHPNAME => array ('AppDocUid', 'AppDocFilename', 'AppDocTitle', 'AppDocComment', 'DocVersion', 'AppUid', 'DelIndex', 'DocUid', 'UsrUid', 'AppDocType', 'AppDocCreateDate', 'AppDocIndex', 'FolderUid', 'AppDocPlugin', 'AppDocTags', 'AppDocStatus', 'AppDocStatusDate', 'AppDocFieldname', 'AppDocDriveDownload', 'SyncWithDrive', 'SyncPermissions', ), - BasePeer::TYPE_COLNAME => array (AppDocumentPeer::APP_DOC_UID, AppDocumentPeer::APP_DOC_FILENAME, AppDocumentPeer::APP_DOC_TITLE, AppDocumentPeer::APP_DOC_COMMENT, AppDocumentPeer::DOC_VERSION, AppDocumentPeer::APP_UID, AppDocumentPeer::DEL_INDEX, AppDocumentPeer::DOC_UID, AppDocumentPeer::USR_UID, AppDocumentPeer::APP_DOC_TYPE, AppDocumentPeer::APP_DOC_CREATE_DATE, AppDocumentPeer::APP_DOC_INDEX, AppDocumentPeer::FOLDER_UID, AppDocumentPeer::APP_DOC_PLUGIN, AppDocumentPeer::APP_DOC_TAGS, AppDocumentPeer::APP_DOC_STATUS, AppDocumentPeer::APP_DOC_STATUS_DATE, AppDocumentPeer::APP_DOC_FIELDNAME, AppDocumentPeer::APP_DOC_DRIVE_DOWNLOAD, AppDocumentPeer::SYNC_WITH_DRIVE, AppDocumentPeer::SYNC_PERMISSIONS, ), - BasePeer::TYPE_FIELDNAME => array ('APP_DOC_UID', 'APP_DOC_FILENAME', 'APP_DOC_TITLE', 'APP_DOC_COMMENT', 'DOC_VERSION', 'APP_UID', 'DEL_INDEX', 'DOC_UID', 'USR_UID', 'APP_DOC_TYPE', 'APP_DOC_CREATE_DATE', 'APP_DOC_INDEX', 'FOLDER_UID', 'APP_DOC_PLUGIN', 'APP_DOC_TAGS', 'APP_DOC_STATUS', 'APP_DOC_STATUS_DATE', 'APP_DOC_FIELDNAME', 'APP_DOC_DRIVE_DOWNLOAD', 'SYNC_WITH_DRIVE', 'SYNC_PERMISSIONS', ), - BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ) + BasePeer::TYPE_PHPNAME => array ('AppDocUid', 'AppDocFilename', 'AppDocTitle', 'AppDocComment', 'DocVersion', 'AppUid', 'DelIndex', 'DocUid', 'DocId', 'UsrUid', 'AppDocType', 'AppDocCreateDate', 'AppDocIndex', 'FolderUid', 'AppDocPlugin', 'AppDocTags', 'AppDocStatus', 'AppDocStatusDate', 'AppDocFieldname', 'AppDocDriveDownload', 'SyncWithDrive', 'SyncPermissions', ), + BasePeer::TYPE_COLNAME => array (AppDocumentPeer::APP_DOC_UID, AppDocumentPeer::APP_DOC_FILENAME, AppDocumentPeer::APP_DOC_TITLE, AppDocumentPeer::APP_DOC_COMMENT, AppDocumentPeer::DOC_VERSION, AppDocumentPeer::APP_UID, AppDocumentPeer::DEL_INDEX, AppDocumentPeer::DOC_UID, AppDocumentPeer::DOC_ID, AppDocumentPeer::USR_UID, AppDocumentPeer::APP_DOC_TYPE, AppDocumentPeer::APP_DOC_CREATE_DATE, AppDocumentPeer::APP_DOC_INDEX, AppDocumentPeer::FOLDER_UID, AppDocumentPeer::APP_DOC_PLUGIN, AppDocumentPeer::APP_DOC_TAGS, AppDocumentPeer::APP_DOC_STATUS, AppDocumentPeer::APP_DOC_STATUS_DATE, AppDocumentPeer::APP_DOC_FIELDNAME, AppDocumentPeer::APP_DOC_DRIVE_DOWNLOAD, AppDocumentPeer::SYNC_WITH_DRIVE, AppDocumentPeer::SYNC_PERMISSIONS, ), + BasePeer::TYPE_FIELDNAME => array ('APP_DOC_UID', 'APP_DOC_FILENAME', 'APP_DOC_TITLE', 'APP_DOC_COMMENT', 'DOC_VERSION', 'APP_UID', 'DEL_INDEX', 'DOC_UID', 'DOC_ID', 'USR_UID', 'APP_DOC_TYPE', 'APP_DOC_CREATE_DATE', 'APP_DOC_INDEX', 'FOLDER_UID', 'APP_DOC_PLUGIN', 'APP_DOC_TAGS', 'APP_DOC_STATUS', 'APP_DOC_STATUS_DATE', 'APP_DOC_FIELDNAME', 'APP_DOC_DRIVE_DOWNLOAD', 'SYNC_WITH_DRIVE', 'SYNC_PERMISSIONS', ), + BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, ) ); /** @@ -118,10 +121,10 @@ abstract class BaseAppDocumentPeer * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0 */ private static $fieldKeys = array ( - BasePeer::TYPE_PHPNAME => array ('AppDocUid' => 0, 'AppDocFilename' => 1, 'AppDocTitle' => 2, 'AppDocComment' => 3, 'DocVersion' => 4, 'AppUid' => 5, 'DelIndex' => 6, 'DocUid' => 7, 'UsrUid' => 8, 'AppDocType' => 9, 'AppDocCreateDate' => 10, 'AppDocIndex' => 11, 'FolderUid' => 12, 'AppDocPlugin' => 13, 'AppDocTags' => 14, 'AppDocStatus' => 15, 'AppDocStatusDate' => 16, 'AppDocFieldname' => 17, 'AppDocDriveDownload' => 18, 'SyncWithDrive' => 19, 'SyncPermissions' => 20, ), - BasePeer::TYPE_COLNAME => array (AppDocumentPeer::APP_DOC_UID => 0, AppDocumentPeer::APP_DOC_FILENAME => 1, AppDocumentPeer::APP_DOC_TITLE => 2, AppDocumentPeer::APP_DOC_COMMENT => 3, AppDocumentPeer::DOC_VERSION => 4, AppDocumentPeer::APP_UID => 5, AppDocumentPeer::DEL_INDEX => 6, AppDocumentPeer::DOC_UID => 7, AppDocumentPeer::USR_UID => 8, AppDocumentPeer::APP_DOC_TYPE => 9, AppDocumentPeer::APP_DOC_CREATE_DATE => 10, AppDocumentPeer::APP_DOC_INDEX => 11, AppDocumentPeer::FOLDER_UID => 12, AppDocumentPeer::APP_DOC_PLUGIN => 13, AppDocumentPeer::APP_DOC_TAGS => 14, AppDocumentPeer::APP_DOC_STATUS => 15, AppDocumentPeer::APP_DOC_STATUS_DATE => 16, AppDocumentPeer::APP_DOC_FIELDNAME => 17, AppDocumentPeer::APP_DOC_DRIVE_DOWNLOAD => 18, AppDocumentPeer::SYNC_WITH_DRIVE => 19, AppDocumentPeer::SYNC_PERMISSIONS => 20, ), - BasePeer::TYPE_FIELDNAME => array ('APP_DOC_UID' => 0, 'APP_DOC_FILENAME' => 1, 'APP_DOC_TITLE' => 2, 'APP_DOC_COMMENT' => 3, 'DOC_VERSION' => 4, 'APP_UID' => 5, 'DEL_INDEX' => 6, 'DOC_UID' => 7, 'USR_UID' => 8, 'APP_DOC_TYPE' => 9, 'APP_DOC_CREATE_DATE' => 10, 'APP_DOC_INDEX' => 11, 'FOLDER_UID' => 12, 'APP_DOC_PLUGIN' => 13, 'APP_DOC_TAGS' => 14, 'APP_DOC_STATUS' => 15, 'APP_DOC_STATUS_DATE' => 16, 'APP_DOC_FIELDNAME' => 17, 'APP_DOC_DRIVE_DOWNLOAD' => 18, 'SYNC_WITH_DRIVE' => 19, 'SYNC_PERMISSIONS' => 20, ), - BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ) + BasePeer::TYPE_PHPNAME => array ('AppDocUid' => 0, 'AppDocFilename' => 1, 'AppDocTitle' => 2, 'AppDocComment' => 3, 'DocVersion' => 4, 'AppUid' => 5, 'DelIndex' => 6, 'DocUid' => 7, 'DocId' => 8, 'UsrUid' => 9, 'AppDocType' => 10, 'AppDocCreateDate' => 11, 'AppDocIndex' => 12, 'FolderUid' => 13, 'AppDocPlugin' => 14, 'AppDocTags' => 15, 'AppDocStatus' => 16, 'AppDocStatusDate' => 17, 'AppDocFieldname' => 18, 'AppDocDriveDownload' => 19, 'SyncWithDrive' => 20, 'SyncPermissions' => 21, ), + BasePeer::TYPE_COLNAME => array (AppDocumentPeer::APP_DOC_UID => 0, AppDocumentPeer::APP_DOC_FILENAME => 1, AppDocumentPeer::APP_DOC_TITLE => 2, AppDocumentPeer::APP_DOC_COMMENT => 3, AppDocumentPeer::DOC_VERSION => 4, AppDocumentPeer::APP_UID => 5, AppDocumentPeer::DEL_INDEX => 6, AppDocumentPeer::DOC_UID => 7, AppDocumentPeer::DOC_ID => 8, AppDocumentPeer::USR_UID => 9, AppDocumentPeer::APP_DOC_TYPE => 10, AppDocumentPeer::APP_DOC_CREATE_DATE => 11, AppDocumentPeer::APP_DOC_INDEX => 12, AppDocumentPeer::FOLDER_UID => 13, AppDocumentPeer::APP_DOC_PLUGIN => 14, AppDocumentPeer::APP_DOC_TAGS => 15, AppDocumentPeer::APP_DOC_STATUS => 16, AppDocumentPeer::APP_DOC_STATUS_DATE => 17, AppDocumentPeer::APP_DOC_FIELDNAME => 18, AppDocumentPeer::APP_DOC_DRIVE_DOWNLOAD => 19, AppDocumentPeer::SYNC_WITH_DRIVE => 20, AppDocumentPeer::SYNC_PERMISSIONS => 21, ), + BasePeer::TYPE_FIELDNAME => array ('APP_DOC_UID' => 0, 'APP_DOC_FILENAME' => 1, 'APP_DOC_TITLE' => 2, 'APP_DOC_COMMENT' => 3, 'DOC_VERSION' => 4, 'APP_UID' => 5, 'DEL_INDEX' => 6, 'DOC_UID' => 7, 'DOC_ID' => 8, 'USR_UID' => 9, 'APP_DOC_TYPE' => 10, 'APP_DOC_CREATE_DATE' => 11, 'APP_DOC_INDEX' => 12, 'FOLDER_UID' => 13, 'APP_DOC_PLUGIN' => 14, 'APP_DOC_TAGS' => 15, 'APP_DOC_STATUS' => 16, 'APP_DOC_STATUS_DATE' => 17, 'APP_DOC_FIELDNAME' => 18, 'APP_DOC_DRIVE_DOWNLOAD' => 19, 'SYNC_WITH_DRIVE' => 20, 'SYNC_PERMISSIONS' => 21, ), + BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, ) ); /** @@ -238,6 +241,8 @@ abstract class BaseAppDocumentPeer $criteria->addSelectColumn(AppDocumentPeer::DOC_UID); + $criteria->addSelectColumn(AppDocumentPeer::DOC_ID); + $criteria->addSelectColumn(AppDocumentPeer::USR_UID); $criteria->addSelectColumn(AppDocumentPeer::APP_DOC_TYPE); diff --git a/workflow/engine/classes/model/om/BaseAppNotes.php b/workflow/engine/classes/model/om/BaseAppNotes.php index 60225d6d6..4eba38105 100644 --- a/workflow/engine/classes/model/om/BaseAppNotes.php +++ b/workflow/engine/classes/model/om/BaseAppNotes.php @@ -27,6 +27,12 @@ abstract class BaseAppNotes extends BaseObject implements Persistent */ protected static $peer; + /** + * The value for the note_id field. + * @var int + */ + protected $note_id; + /** * The value for the app_uid field. * @var string @@ -101,6 +107,17 @@ abstract class BaseAppNotes extends BaseObject implements Persistent */ protected $alreadyInValidation = false; + /** + * Get the [note_id] column value. + * + * @return int + */ + public function getNoteId() + { + + return $this->note_id; + } + /** * Get the [app_uid] column value. * @@ -232,6 +249,28 @@ abstract class BaseAppNotes extends BaseObject implements Persistent return $this->note_recipients; } + /** + * Set the value of [note_id] column. + * + * @param int $v new value + * @return void + */ + public function setNoteId($v) + { + + // Since the native PHP type for this column is integer, + // we will cast the input value to an int (if it is not). + if ($v !== null && !is_int($v) && is_numeric($v)) { + $v = (int) $v; + } + + if ($this->note_id !== $v) { + $this->note_id = $v; + $this->modifiedColumns[] = AppNotesPeer::NOTE_ID; + } + + } // setNoteId() + /** * Set the value of [app_uid] column. * @@ -476,32 +515,34 @@ abstract class BaseAppNotes extends BaseObject implements Persistent { try { - $this->app_uid = $rs->getString($startcol + 0); + $this->note_id = $rs->getInt($startcol + 0); - $this->usr_uid = $rs->getString($startcol + 1); + $this->app_uid = $rs->getString($startcol + 1); - $this->note_date = $rs->getTimestamp($startcol + 2, null); + $this->usr_uid = $rs->getString($startcol + 2); - $this->note_content = $rs->getString($startcol + 3); + $this->note_date = $rs->getTimestamp($startcol + 3, null); - $this->note_type = $rs->getString($startcol + 4); + $this->note_content = $rs->getString($startcol + 4); - $this->note_availability = $rs->getString($startcol + 5); + $this->note_type = $rs->getString($startcol + 5); - $this->note_origin_obj = $rs->getString($startcol + 6); + $this->note_availability = $rs->getString($startcol + 6); - $this->note_affected_obj1 = $rs->getString($startcol + 7); + $this->note_origin_obj = $rs->getString($startcol + 7); - $this->note_affected_obj2 = $rs->getString($startcol + 8); + $this->note_affected_obj1 = $rs->getString($startcol + 8); - $this->note_recipients = $rs->getString($startcol + 9); + $this->note_affected_obj2 = $rs->getString($startcol + 9); + + $this->note_recipients = $rs->getString($startcol + 10); $this->resetModified(); $this->setNew(false); // FIXME - using NUM_COLUMNS may be clearer. - return $startcol + 10; // 10 = AppNotesPeer::NUM_COLUMNS - AppNotesPeer::NUM_LAZY_LOAD_COLUMNS). + return $startcol + 11; // 11 = AppNotesPeer::NUM_COLUMNS - AppNotesPeer::NUM_LAZY_LOAD_COLUMNS). } catch (Exception $e) { throw new PropelException("Error populating AppNotes object", $e); @@ -706,33 +747,36 @@ abstract class BaseAppNotes extends BaseObject implements Persistent { switch($pos) { case 0: - return $this->getAppUid(); + return $this->getNoteId(); break; case 1: - return $this->getUsrUid(); + return $this->getAppUid(); break; case 2: - return $this->getNoteDate(); + return $this->getUsrUid(); break; case 3: - return $this->getNoteContent(); + return $this->getNoteDate(); break; case 4: - return $this->getNoteType(); + return $this->getNoteContent(); break; case 5: - return $this->getNoteAvailability(); + return $this->getNoteType(); break; case 6: - return $this->getNoteOriginObj(); + return $this->getNoteAvailability(); break; case 7: - return $this->getNoteAffectedObj1(); + return $this->getNoteOriginObj(); break; case 8: - return $this->getNoteAffectedObj2(); + return $this->getNoteAffectedObj1(); break; case 9: + return $this->getNoteAffectedObj2(); + break; + case 10: return $this->getNoteRecipients(); break; default: @@ -755,16 +799,17 @@ abstract class BaseAppNotes extends BaseObject implements Persistent { $keys = AppNotesPeer::getFieldNames($keyType); $result = array( - $keys[0] => $this->getAppUid(), - $keys[1] => $this->getUsrUid(), - $keys[2] => $this->getNoteDate(), - $keys[3] => $this->getNoteContent(), - $keys[4] => $this->getNoteType(), - $keys[5] => $this->getNoteAvailability(), - $keys[6] => $this->getNoteOriginObj(), - $keys[7] => $this->getNoteAffectedObj1(), - $keys[8] => $this->getNoteAffectedObj2(), - $keys[9] => $this->getNoteRecipients(), + $keys[0] => $this->getNoteId(), + $keys[1] => $this->getAppUid(), + $keys[2] => $this->getUsrUid(), + $keys[3] => $this->getNoteDate(), + $keys[4] => $this->getNoteContent(), + $keys[5] => $this->getNoteType(), + $keys[6] => $this->getNoteAvailability(), + $keys[7] => $this->getNoteOriginObj(), + $keys[8] => $this->getNoteAffectedObj1(), + $keys[9] => $this->getNoteAffectedObj2(), + $keys[10] => $this->getNoteRecipients(), ); return $result; } @@ -797,33 +842,36 @@ abstract class BaseAppNotes extends BaseObject implements Persistent { switch($pos) { case 0: - $this->setAppUid($value); + $this->setNoteId($value); break; case 1: - $this->setUsrUid($value); + $this->setAppUid($value); break; case 2: - $this->setNoteDate($value); + $this->setUsrUid($value); break; case 3: - $this->setNoteContent($value); + $this->setNoteDate($value); break; case 4: - $this->setNoteType($value); + $this->setNoteContent($value); break; case 5: - $this->setNoteAvailability($value); + $this->setNoteType($value); break; case 6: - $this->setNoteOriginObj($value); + $this->setNoteAvailability($value); break; case 7: - $this->setNoteAffectedObj1($value); + $this->setNoteOriginObj($value); break; case 8: - $this->setNoteAffectedObj2($value); + $this->setNoteAffectedObj1($value); break; case 9: + $this->setNoteAffectedObj2($value); + break; + case 10: $this->setNoteRecipients($value); break; } // switch() @@ -850,43 +898,47 @@ abstract class BaseAppNotes extends BaseObject implements Persistent $keys = AppNotesPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { - $this->setAppUid($arr[$keys[0]]); + $this->setNoteId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { - $this->setUsrUid($arr[$keys[1]]); + $this->setAppUid($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { - $this->setNoteDate($arr[$keys[2]]); + $this->setUsrUid($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { - $this->setNoteContent($arr[$keys[3]]); + $this->setNoteDate($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { - $this->setNoteType($arr[$keys[4]]); + $this->setNoteContent($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { - $this->setNoteAvailability($arr[$keys[5]]); + $this->setNoteType($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { - $this->setNoteOriginObj($arr[$keys[6]]); + $this->setNoteAvailability($arr[$keys[6]]); } if (array_key_exists($keys[7], $arr)) { - $this->setNoteAffectedObj1($arr[$keys[7]]); + $this->setNoteOriginObj($arr[$keys[7]]); } if (array_key_exists($keys[8], $arr)) { - $this->setNoteAffectedObj2($arr[$keys[8]]); + $this->setNoteAffectedObj1($arr[$keys[8]]); } if (array_key_exists($keys[9], $arr)) { - $this->setNoteRecipients($arr[$keys[9]]); + $this->setNoteAffectedObj2($arr[$keys[9]]); + } + + if (array_key_exists($keys[10], $arr)) { + $this->setNoteRecipients($arr[$keys[10]]); } } @@ -900,6 +952,10 @@ abstract class BaseAppNotes extends BaseObject implements Persistent { $criteria = new Criteria(AppNotesPeer::DATABASE_NAME); + if ($this->isColumnModified(AppNotesPeer::NOTE_ID)) { + $criteria->add(AppNotesPeer::NOTE_ID, $this->note_id); + } + if ($this->isColumnModified(AppNotesPeer::APP_UID)) { $criteria->add(AppNotesPeer::APP_UID, $this->app_uid); } @@ -997,6 +1053,8 @@ abstract class BaseAppNotes extends BaseObject implements Persistent public function copyInto($copyObj, $deepCopy = false) { + $copyObj->setNoteId($this->note_id); + $copyObj->setAppUid($this->app_uid); $copyObj->setUsrUid($this->usr_uid); diff --git a/workflow/engine/classes/model/om/BaseAppNotesPeer.php b/workflow/engine/classes/model/om/BaseAppNotesPeer.php index 2efabc48c..858e32b61 100644 --- a/workflow/engine/classes/model/om/BaseAppNotesPeer.php +++ b/workflow/engine/classes/model/om/BaseAppNotesPeer.php @@ -25,12 +25,15 @@ abstract class BaseAppNotesPeer const CLASS_DEFAULT = 'classes.model.AppNotes'; /** The total number of columns. */ - const NUM_COLUMNS = 10; + const NUM_COLUMNS = 11; /** The number of lazy-loaded columns. */ const NUM_LAZY_LOAD_COLUMNS = 0; + /** the column name for the NOTE_ID field */ + const NOTE_ID = 'APP_NOTES.NOTE_ID'; + /** the column name for the APP_UID field */ const APP_UID = 'APP_NOTES.APP_UID'; @@ -72,10 +75,10 @@ abstract class BaseAppNotesPeer * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ private static $fieldNames = array ( - BasePeer::TYPE_PHPNAME => array ('AppUid', 'UsrUid', 'NoteDate', 'NoteContent', 'NoteType', 'NoteAvailability', 'NoteOriginObj', 'NoteAffectedObj1', 'NoteAffectedObj2', 'NoteRecipients', ), - BasePeer::TYPE_COLNAME => array (AppNotesPeer::APP_UID, AppNotesPeer::USR_UID, AppNotesPeer::NOTE_DATE, AppNotesPeer::NOTE_CONTENT, AppNotesPeer::NOTE_TYPE, AppNotesPeer::NOTE_AVAILABILITY, AppNotesPeer::NOTE_ORIGIN_OBJ, AppNotesPeer::NOTE_AFFECTED_OBJ1, AppNotesPeer::NOTE_AFFECTED_OBJ2, AppNotesPeer::NOTE_RECIPIENTS, ), - BasePeer::TYPE_FIELDNAME => array ('APP_UID', 'USR_UID', 'NOTE_DATE', 'NOTE_CONTENT', 'NOTE_TYPE', 'NOTE_AVAILABILITY', 'NOTE_ORIGIN_OBJ', 'NOTE_AFFECTED_OBJ1', 'NOTE_AFFECTED_OBJ2', 'NOTE_RECIPIENTS', ), - BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ) + BasePeer::TYPE_PHPNAME => array ('NoteId', 'AppUid', 'UsrUid', 'NoteDate', 'NoteContent', 'NoteType', 'NoteAvailability', 'NoteOriginObj', 'NoteAffectedObj1', 'NoteAffectedObj2', 'NoteRecipients', ), + BasePeer::TYPE_COLNAME => array (AppNotesPeer::NOTE_ID, AppNotesPeer::APP_UID, AppNotesPeer::USR_UID, AppNotesPeer::NOTE_DATE, AppNotesPeer::NOTE_CONTENT, AppNotesPeer::NOTE_TYPE, AppNotesPeer::NOTE_AVAILABILITY, AppNotesPeer::NOTE_ORIGIN_OBJ, AppNotesPeer::NOTE_AFFECTED_OBJ1, AppNotesPeer::NOTE_AFFECTED_OBJ2, AppNotesPeer::NOTE_RECIPIENTS, ), + BasePeer::TYPE_FIELDNAME => array ('NOTE_ID', 'APP_UID', 'USR_UID', 'NOTE_DATE', 'NOTE_CONTENT', 'NOTE_TYPE', 'NOTE_AVAILABILITY', 'NOTE_ORIGIN_OBJ', 'NOTE_AFFECTED_OBJ1', 'NOTE_AFFECTED_OBJ2', 'NOTE_RECIPIENTS', ), + BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ) ); /** @@ -85,10 +88,10 @@ abstract class BaseAppNotesPeer * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0 */ private static $fieldKeys = array ( - BasePeer::TYPE_PHPNAME => array ('AppUid' => 0, 'UsrUid' => 1, 'NoteDate' => 2, 'NoteContent' => 3, 'NoteType' => 4, 'NoteAvailability' => 5, 'NoteOriginObj' => 6, 'NoteAffectedObj1' => 7, 'NoteAffectedObj2' => 8, 'NoteRecipients' => 9, ), - BasePeer::TYPE_COLNAME => array (AppNotesPeer::APP_UID => 0, AppNotesPeer::USR_UID => 1, AppNotesPeer::NOTE_DATE => 2, AppNotesPeer::NOTE_CONTENT => 3, AppNotesPeer::NOTE_TYPE => 4, AppNotesPeer::NOTE_AVAILABILITY => 5, AppNotesPeer::NOTE_ORIGIN_OBJ => 6, AppNotesPeer::NOTE_AFFECTED_OBJ1 => 7, AppNotesPeer::NOTE_AFFECTED_OBJ2 => 8, AppNotesPeer::NOTE_RECIPIENTS => 9, ), - BasePeer::TYPE_FIELDNAME => array ('APP_UID' => 0, 'USR_UID' => 1, 'NOTE_DATE' => 2, 'NOTE_CONTENT' => 3, 'NOTE_TYPE' => 4, 'NOTE_AVAILABILITY' => 5, 'NOTE_ORIGIN_OBJ' => 6, 'NOTE_AFFECTED_OBJ1' => 7, 'NOTE_AFFECTED_OBJ2' => 8, 'NOTE_RECIPIENTS' => 9, ), - BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ) + BasePeer::TYPE_PHPNAME => array ('NoteId' => 0, 'AppUid' => 1, 'UsrUid' => 2, 'NoteDate' => 3, 'NoteContent' => 4, 'NoteType' => 5, 'NoteAvailability' => 6, 'NoteOriginObj' => 7, 'NoteAffectedObj1' => 8, 'NoteAffectedObj2' => 9, 'NoteRecipients' => 10, ), + BasePeer::TYPE_COLNAME => array (AppNotesPeer::NOTE_ID => 0, AppNotesPeer::APP_UID => 1, AppNotesPeer::USR_UID => 2, AppNotesPeer::NOTE_DATE => 3, AppNotesPeer::NOTE_CONTENT => 4, AppNotesPeer::NOTE_TYPE => 5, AppNotesPeer::NOTE_AVAILABILITY => 6, AppNotesPeer::NOTE_ORIGIN_OBJ => 7, AppNotesPeer::NOTE_AFFECTED_OBJ1 => 8, AppNotesPeer::NOTE_AFFECTED_OBJ2 => 9, AppNotesPeer::NOTE_RECIPIENTS => 10, ), + BasePeer::TYPE_FIELDNAME => array ('NOTE_ID' => 0, 'APP_UID' => 1, 'USR_UID' => 2, 'NOTE_DATE' => 3, 'NOTE_CONTENT' => 4, 'NOTE_TYPE' => 5, 'NOTE_AVAILABILITY' => 6, 'NOTE_ORIGIN_OBJ' => 7, 'NOTE_AFFECTED_OBJ1' => 8, 'NOTE_AFFECTED_OBJ2' => 9, 'NOTE_RECIPIENTS' => 10, ), + BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ) ); /** @@ -189,6 +192,8 @@ abstract class BaseAppNotesPeer public static function addSelectColumns(Criteria $criteria) { + $criteria->addSelectColumn(AppNotesPeer::NOTE_ID); + $criteria->addSelectColumn(AppNotesPeer::APP_UID); $criteria->addSelectColumn(AppNotesPeer::USR_UID); diff --git a/workflow/engine/config/schema.xml b/workflow/engine/config/schema.xml index 24e4d7490..313c2ed73 100644 --- a/workflow/engine/config/schema.xml +++ b/workflow/engine/config/schema.xml @@ -230,6 +230,7 @@ + @@ -284,7 +285,7 @@ - + @@ -3287,7 +3288,7 @@ - +
@@ -3308,6 +3309,7 @@ + @@ -3318,6 +3320,9 @@ + + + diff --git a/workflow/engine/data/mysql/schema.sql b/workflow/engine/data/mysql/schema.sql index 4946fb777..67608ac2e 100644 --- a/workflow/engine/data/mysql/schema.sql +++ b/workflow/engine/data/mysql/schema.sql @@ -120,6 +120,7 @@ CREATE TABLE `APP_DOCUMENT` `APP_UID` VARCHAR(32) default '' NOT NULL, `DEL_INDEX` INTEGER default 0 NOT NULL, `DOC_UID` VARCHAR(32) default '' NOT NULL, + `DOC_ID` INTEGER default 0, `USR_UID` VARCHAR(32) default '' NOT NULL, `APP_DOC_TYPE` VARCHAR(32) default '' NOT NULL, `APP_DOC_CREATE_DATE` DATETIME NOT NULL, @@ -1583,6 +1584,7 @@ DROP TABLE IF EXISTS `APP_NOTES`; CREATE TABLE `APP_NOTES` ( + `NOTE_ID` INTEGER NOT NULL AUTO_INCREMENT, `APP_UID` VARCHAR(32) default '' NOT NULL, `USR_UID` VARCHAR(32) default '' NOT NULL, `NOTE_DATE` DATETIME NOT NULL, @@ -1593,6 +1595,7 @@ CREATE TABLE `APP_NOTES` `NOTE_AFFECTED_OBJ1` VARCHAR(32) default '', `NOTE_AFFECTED_OBJ2` VARCHAR(32) default '' NOT NULL, `NOTE_RECIPIENTS` MEDIUMTEXT, + UNIQUE KEY `NOTE_ID` (`NOTE_ID`), KEY `indexAppNotesDate`(`APP_UID`, `NOTE_DATE`), KEY `indexAppNotesUser`(`APP_UID`, `USR_UID`) )ENGINE=InnoDB DEFAULT CHARSET='utf8' COMMENT='Application Notes'; diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php index c8e078d8a..15727a9c9 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php @@ -41,7 +41,9 @@ use ProcessMaker\BusinessModel\User as BmUser; use ProcessMaker\Core\System; use ProcessMaker\Exception\UploadException; use ProcessMaker\Model\Application as ModelApplication; +use ProcessMaker\Model\AppNotes; use ProcessMaker\Model\Delegation; +use ProcessMaker\Model\Documents; use ProcessMaker\Plugins\PluginRegistry; use ProcessMaker\Services\OAuth2\Server; use ProcessMaker\Util\DateTime as UtilDateTime; @@ -3843,6 +3845,138 @@ class Cases return $response; } + /** + * Add a case note + * + * @param string $appUid + * @param string $userUid + * @param string $note + * @param bool $sendMail + * @param array $files + * + * @return array + * @throws Exception + */ + public function addNote($appUid, $userUid, $note, $sendMail = false, $files = []) + { + // Register the note + $attributes = [ + "APP_UID" => $appUid, + "USR_UID" => $userUid, + "NOTE_DATE" => date("Y-m-d H:i:s"), + "NOTE_CONTENT" => $note, + "NOTE_TYPE" => "USER", + "NOTE_AVAILABILITY" => "PUBLIC", + "NOTE_RECIPIENTS" => "" + ]; + $response = AppNotes::create($attributes); + // Get the FK + $noteId = $response->NOTE_ID; + + // Register the files related to the note + $this->uploadFilesInCaseNotes($userUid, $appUid, $files, $noteId); + + // Send the email + if ($sendMail) { + // @todo refactor this section the files attached need to send in the email + $case = new ClassesCases(); + $p = $case->getUsersParticipatedInCase($appUid, 'ACTIVE'); + $noteRecipientsList = []; + + foreach ($p["array"] as $key => $userParticipated) { + if ($key != '') { + $noteRecipientsList[] = $key; + } + } + + $noteRecipients = implode(",", $noteRecipientsList); + $note = stripslashes($note); + + $note = new \AppNotes(); + $note->sendNoteNotification($appUid, $userUid, $note, $noteRecipients); + } + } + + /** + * Upload file related to the case notes + * + * @param string $userUid + * @param string $appUid + * @param array $filesReferences + * @param string $appDocUid + * + * @return array + * @throws Exception + */ + public function uploadFilesInCaseNotes($userUid, $appUid, $filesReferences = [], $noteId = 0) + { + if (!empty($_FILES["form"]["name"])) { + $upload = true; + // Array from post upload + foreach ($_FILES["form"]["name"] as $fileIndex => $fileName) { + if (!is_array($fileName)) { + $files[] = [ + 'name' => $_FILES["form"]["name"][$fileIndex], + 'tmp_name' => $_FILES["form"]["tmp_name"][$fileIndex], + 'error' => $_FILES["form"]["error"][$fileIndex] + ]; + } + } + } elseif (!empty($filesReferences)) { + $upload = false; + // Array with path references + foreach ($filesReferences as $fileIndex => $fileName) { + $nameFile = !is_numeric($fileIndex) ? basename($fileIndex) : basename($fileName); + $files[] = [ + 'name' => $nameFile, + 'tmp_name' => $fileName, + 'error' => UPLOAD_ERR_OK + ]; + } + } + + // Get the delIndex related to the case + $cases = new ClassesCases(); + $delIndex = $cases->getCurrentDelegation($appUid); + + // We will to register the files in the database + $response = []; + if (!empty($files)) { + $i = 0; + foreach ($files as $fileIndex => $fileName) { + // There is no error, the file uploaded with success + if ($fileName["error"] === UPLOAD_ERR_OK) { + $appDocUid = G::generateUniqueID(); + $attributes = [ + "DOC_ID" => $noteId, + "APP_DOC_UID" => $appDocUid, + "DOC_VERSION" => 1, + "APP_UID" => $appUid, + "DEL_INDEX" => $delIndex, + "USR_UID" => $userUid, + "DOC_UID" => -1, + "APP_DOC_TYPE" => 'CASE_NOTE', + "APP_DOC_CREATE_DATE" => date("Y-m-d H:i:s"), + "APP_DOC_FILENAME" => $fileName["name"] + ]; + Documents::create($attributes); + + // Upload or move the file + $isUploaded = saveAppDocument($fileName, $appUid, $appDocUid, 1, $upload); + + // List of files uploaded or copy + $response[$i++] = $attributes; + } else { + throw new UploadException($fileName['error']); + } + } + } else { + throw new Exception(G::LoadTranslation('ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR')); + } + + return $response; + } + /** * Run the validations related to an Input Document * diff --git a/workflow/engine/src/ProcessMaker/Model/AppNotes.php b/workflow/engine/src/ProcessMaker/Model/AppNotes.php index 2db007ad5..402662991 100644 --- a/workflow/engine/src/ProcessMaker/Model/AppNotes.php +++ b/workflow/engine/src/ProcessMaker/Model/AppNotes.php @@ -6,6 +6,42 @@ use Illuminate\Database\Eloquent\Model; class AppNotes extends Model { + // Set our table name protected $table = 'APP_NOTES'; + // No timestamps public $timestamps = false; + // Primary key + protected $primaryKey = 'NOTE_ID'; + // The IDs are auto-incrementing + public $incrementing = true; + + /** + * The model's default values for attributes. + * + * @var array + */ + protected $attributes = [ + 'NOTE_TYPE' => 'USER', + 'NOTE_ORIGIN_OBJ' => '', + 'NOTE_AFFECTED_OBJ1' => '', + 'NOTE_AFFECTED_OBJ2' => '' + ]; + + /** + * The attributes that are mass assignable. + * + * @var array + */ + protected $fillable = [ + 'APP_UID', + 'USR_UID', + 'NOTE_DATE', + 'NOTE_CONTENT', + 'NOTE_TYPE', + 'NOTE_AVAILABILITY', + 'NOTE_ORIGIN_OBJ', + 'NOTE_AFFECTED_OBJ1', + 'NOTE_AFFECTED_OBJ2', + 'NOTE_RECIPIENTS' + ]; } diff --git a/workflow/engine/src/ProcessMaker/Model/Documents.php b/workflow/engine/src/ProcessMaker/Model/Documents.php new file mode 100644 index 000000000..740e7d689 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Model/Documents.php @@ -0,0 +1,96 @@ + '', + 'APP_DOC_COMMENT' => '', + 'DOC_UID' => '-1', + 'FOLDER_UID' => '', + 'APP_DOC_PLUGIN' => '', + 'APP_DOC_TAGS' => '', + 'APP_DOC_FIELDNAME' => '', + 'APP_DOC_DRIVE_DOWNLOAD' => 'a:0:{}', + 'SYNC_WITH_DRIVE' => 'UNSYNCHRONIZED', + 'SYNC_PERMISSIONS' => '', + 'APP_DOC_STATUS_DATE' => '', + ]; + + /** + * The attributes that are mass assignable. + * + * @var array + */ + protected $fillable = [ + 'DOC_ID', + 'APP_DOC_UID', + 'DOC_VERSION', + 'APP_DOC_FILENAME', + 'APP_UID', + 'DEL_INDEX', + 'DOC_UID', + 'USR_UID', + 'APP_DOC_TYPE', + 'APP_DOC_CREATE_DATE', + 'APP_DOC_INDEX', + 'FOLDER_UID', + 'APP_DOC_STATUS', + ]; + + /** + * Scope a query to filter an specific case + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $proUid + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeAppUid($query, string $appUid) + { + return $query->where('APP_UID', $appUid); + } + + /** + * Return the documents related to the case + * + * @param int $proId + * @param string $type + * + * @return array + */ + public static function getAppFiles(string $appUid, $type = 'CASE_NOTES') + { + $query = Documents::query()->select(); + $query->appUid($appUid); + $query->where('APP_DOC_TYPE', $type); + $results = $query->get(); + $documentList = []; + $results->each(function ($item, $key) use (&$documentList) { + $documentList[] = $item->toArray(); + }); + + return $documentList; + } +} diff --git a/workflow/engine/src/ProcessMaker/Util/helpers.php b/workflow/engine/src/ProcessMaker/Util/helpers.php index 22272a78e..a844b2eaa 100644 --- a/workflow/engine/src/ProcessMaker/Util/helpers.php +++ b/workflow/engine/src/ProcessMaker/Util/helpers.php @@ -601,3 +601,39 @@ function getMysqlVersion() return $mysqlVersion; } + +/** + * Move the uploaded file to the documents folder + * + * @param array $file + * @param string $appUid + * @param string $appDocUid + * @param int $version + * + * @return string + */ +function saveAppDocument($file, $appUid, $appDocUid, $version = 1, $upload = true) +{ + try { + $info = pathinfo($file["name"]); + $extension = ((isset($info["extension"])) ? $info["extension"] : ""); + //$pathCase = G::getPathFromUID($appUid); + $fileName = $appDocUid . "_" . $version . "." . $extension; + + $pathCase = PATH_DATA_SITE . 'files' . PATH_SEP . G::getPathFromUID($appUid) . PATH_SEP; + + $response = false; + if ($upload) { + $response = G::uploadFile( + $file["tmp_name"], + $pathCase, + $fileName + ); + } else { + G::verifyPath($pathCase, true); + $response = copy($file["tmp_name"], $pathCase . $fileName); + } + } catch (Exception $e) { + throw $e; + } +} From 536c3588dacbcc3d7f5d5c5677f3d016986a6310 Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Thu, 11 Jun 2020 11:49:54 -0400 Subject: [PATCH 02/10] PMCORE-1596 The files attached in the cases notes needs to send in the email notification. --- .../engine/classes/model/AppNotesTest.php | 136 +++++++++++++++++- .../src/ProcessMaker/Model/DocumentsTest.php | 20 +++ workflow/engine/classes/model/AppNotes.php | 41 ++++-- .../translations/english/processmaker.en.po | 6 + workflow/engine/data/mysql/insert.sql | 1 + .../src/ProcessMaker/Model/Documents.php | 16 +++ 6 files changed, 204 insertions(+), 16 deletions(-) diff --git a/tests/unit/workflow/engine/classes/model/AppNotesTest.php b/tests/unit/workflow/engine/classes/model/AppNotesTest.php index e6529b4f4..4d8b3feda 100644 --- a/tests/unit/workflow/engine/classes/model/AppNotesTest.php +++ b/tests/unit/workflow/engine/classes/model/AppNotesTest.php @@ -3,10 +3,14 @@ namespace Tests\unit\workflow\engine\classes\model; use AppNotes as ModelAppNotes; -use ProcessMaker\Model\Delegation; -use ProcessMaker\Model\AppMessage; +use Exception; +use Faker\Factory; use ProcessMaker\Model\Application; +use ProcessMaker\Model\AppMessage; use ProcessMaker\Model\AppNotes; +use ProcessMaker\Model\Delegation; +use ProcessMaker\Model\Documents; +use ProcessMaker\Model\EmailServerModel; use ProcessMaker\Model\User; use Tests\TestCase; @@ -17,12 +21,23 @@ use Tests\TestCase; */ class AppNotesTest extends TestCase { + private $faker; + + /** + * Set up method + */ + public function setUp() + { + parent::setUp(); + $this->faker = Factory::create(); + } + /** * It test the cases notes creation * * @test */ - public function it_test_case_notes_creation() + public function it_test_case_notes_creation() { $application = factory(Application::class)->create(); $user = factory(User::class)->create(); @@ -37,7 +52,7 @@ class AppNotesTest extends TestCase $query = AppNotes::query(); $query->select()->where('APP_UID', $application->APP_UID)->where('USR_UID', $user->USR_UID); $result = $query->get()->values()->toArray(); - $this->assertNotEmpty($result); + $this->assertNotEmpty($result); } /** @@ -45,7 +60,7 @@ class AppNotesTest extends TestCase * * @test */ - public function it_test_case_notes_creation_and_send_email_to_user() + public function it_test_case_notes_creation_and_send_email_to_user() { $application = factory(Application::class)->create(); $user = factory(User::class)->create(); @@ -74,7 +89,7 @@ class AppNotesTest extends TestCase * * @test */ - public function it_test_case_notes_creation_and_send_email() + public function it_test_case_notes_creation_and_send_email() { $application = factory(Application::class)->create(); $user = factory(User::class)->create(); @@ -101,4 +116,111 @@ class AppNotesTest extends TestCase $result = $query->get()->values()->toArray(); $this->assertNotEmpty($result); } -} \ No newline at end of file + + /** + * This test verifies the sending of the notification note with Exception. + * @test + * @covers \AppNotes::sendNoteNotification + */ + public function it_should_test_send_note_notification_with_exception() + { + //assert + $this->expectException(Exception::class); + + $appNotes = new ModelAppNotes(); + $appNotes->sendNoteNotification(null, null, null, null, null, null); + } + + /** + * This test verifies the sending of the notification note. + * @test + * @covers \AppNotes::sendNoteNotification + */ + public function it_should_test_send_note_notification_without_user() + { + $user = User::where('USR_UID', '=', '00000000000000000000000000000001') + ->get() + ->first(); + $application = factory(Application::class)->create(); + $delegation = factory(Delegation::class)->create([ + 'APP_UID' => $application->APP_UID, + 'USR_UID' => $user->USR_UID + ]); + + $params = [ + $application->APP_UID, + '', + '', + $user->USR_UID, + $this->faker->email, + $delegation->DEL_INDEX + ]; + $appNotes = new ModelAppNotes(); + $appNotes->sendNoteNotification(...$params); + + //assert + $appMessage = AppMessage::where('APP_UID', '=', $application->APP_UID)->get()->first()->toArray(); + $this->assertArrayHasKey('APP_UID', $appMessage); + $this->assertEquals($appMessage['APP_UID'], $application->APP_UID); + } + + /** + * This test verifies the sending of the notification note with attach files. + * @test + * @covers \AppNotes::sendNoteNotification + */ + public function it_should_test_send_note_notification_with_attach_files() + { + $user = User::where('USR_UID', '=', '00000000000000000000000000000001') + ->get() + ->first(); + $application = factory(Application::class)->create(); + $delegation = factory(Delegation::class)->create([ + 'APP_UID' => $application->APP_UID, + 'USR_UID' => $user->USR_UID + ]); + $appNote = factory(AppNotes::class)->create(); + $appDocument = factory(Documents::class)->create([ + 'APP_UID' => $application->APP_UID, + 'DOC_ID' => $appNote->NOTE_ID + ]); + factory(EmailServerModel::class)->create([ + 'MESS_DEFAULT' => 1 + ]); + + $params = [ + $application->APP_UID, + $user->USR_UID, + '', + $user->USR_UID, + $this->faker->email, + $delegation->DEL_INDEX + ]; + $appNotes = new ModelAppNotes(); + $appNotes->sendNoteNotification(...$params); + + //assert + $appMessage = AppMessage::where('APP_UID', '=', $application->APP_UID)->get()->first()->toArray(); + $this->assertArrayHasKey('APP_UID', $appMessage); + $this->assertEquals($appMessage['APP_UID'], $application->APP_UID); + } + + /** + * This test verify if exists attachment files. + * @test + * @covers \AppNotes::getAttachedFilesFromTheCaseNote + */ + public function it_should_test_get_attached_files_from_the_casenote() + { + $appNote = factory(AppNotes::class)->create(); + $appDocument = factory(Documents::class)->create([ + 'DOC_ID' => $appNote->NOTE_ID + ]); + + $appUid = $appDocument->APP_UID; + $appNotes = new ModelAppNotes(); + $result = $appNotes->getAttachedFilesFromTheCaseNote($appUid); + + $this->assertNotEmpty($result); + } +} diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Model/DocumentsTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Model/DocumentsTest.php index bc882b79d..b1fe83257 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Model/DocumentsTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Model/DocumentsTest.php @@ -1,7 +1,9 @@ getAppFiles($appDoc->APP_UID, Documents::DOC_TYPE_CASE_NOTE); $this->assertNotEmpty($res); } + + /** + * This test verify if exists attachment files. + * @test + * @covers Documents::getAttachedFilesFromTheCaseNote + */ + public function it_should_test_get_attached_files_from_the_casenote() + { + $appNote = factory(AppNotes::class)->create(); + $appDocument = factory(Documents::class)->create([ + 'DOC_ID' => $appNote->NOTE_ID + ]); + + $appUid = $appDocument->APP_UID; + $result = Documents::getAttachedFilesFromTheCaseNote($appUid); + + $this->assertNotEmpty($result); + } } \ No newline at end of file diff --git a/workflow/engine/classes/model/AppNotes.php b/workflow/engine/classes/model/AppNotes.php index 6e99dc408..17c885359 100644 --- a/workflow/engine/classes/model/AppNotes.php +++ b/workflow/engine/classes/model/AppNotes.php @@ -1,6 +1,7 @@ addCaseNote() * @see AppNotes->postNewNote() * @see workflow/engine/src/ProcessMaker/Util/helpers.php::postNote() - */ - public function sendNoteNotification ($appUid, $usrUid, $noteContent, $noteRecipients, $from = '', $delIndex = 0) + */ + public function sendNoteNotification($appUid, $usrUid, $noteContent, $noteRecipients, $from = '', $delIndex = 0) { try { - $configuration = System::getEmailConfiguration(); $msgError = ""; - if (! isset( $configuration['MESS_ENABLED'] ) || $configuration['MESS_ENABLED'] != '1') { + if (!isset($configuration['MESS_ENABLED']) || $configuration['MESS_ENABLED'] != '1') { $msgError = "The default configuration wasn't defined"; $configuration['MESS_ENGINE'] = ''; } @@ -211,20 +211,27 @@ class AppNotes extends BaseAppNotes $cases = new Cases(); $fieldCase = $cases->loadCase($appUid, $delIndex); $configNoteNotification['subject'] = G::LoadTranslation('ID_MESSAGE_SUBJECT_NOTE_NOTIFICATION') . " @#APP_TITLE "; + //Define the body for the notification $configNoteNotification['body'] = $this->getBodyCaseNote($authorName, $noteContent); $body = nl2br(G::replaceDataField($configNoteNotification['body'], $fieldCase, 'mysql', false)); + $attachFileLinks = $this->getAttachedFilesFromTheCaseNote($appUid); + if (!empty($attachFileLinks)) { + $body = $body . "
" . G::LoadTranslation('ID_ATTACHED_FILES') . ": " . implode("
", $attachFileLinks) . "."; + } $users = new Users(); $recipientsArray = explode(",", $noteRecipients); foreach ($recipientsArray as $recipientUid) { $userInfo = $users->load($recipientUid); - $to = ((($userInfo['USR_FIRSTNAME'] != '') || ($userInfo['USR_LASTNAME'] != '')) ? $userInfo['USR_FIRSTNAME'] . ' ' . $userInfo['USR_LASTNAME'] . ' ' : '') . '<' . $userInfo['USR_EMAIL'] . '>'; + $ifUserNameDefined = $userInfo['USR_FIRSTNAME'] != '' || $userInfo['USR_LASTNAME'] != ''; + $to = ($ifUserNameDefined ? $userInfo['USR_FIRSTNAME'] . ' ' . $userInfo['USR_LASTNAME'] . ' ' : '') . '<' . $userInfo['USR_EMAIL'] . '>'; $spool = new SpoolRun(); $spool->setConfig($configuration); - $messageArray = AppMessage::buildMessageRow( + + $parameters = [ '', $appUid, $delIndex, @@ -244,7 +251,8 @@ class AppNotes extends BaseAppNotes (isset($fieldCase['APP_NUMBER'])) ? $fieldCase['APP_NUMBER'] : 0, (isset($fieldCase['PRO_ID'])) ? $fieldCase['PRO_ID'] : 0, (isset($fieldCase['TAS_ID'])) ? $fieldCase['TAS_ID'] : 0 - ); + ]; + $messageArray = AppMessage::buildMessageRow(...$parameters); $spool->create($messageArray); if ($msgError == '') { @@ -252,14 +260,29 @@ class AppNotes extends BaseAppNotes $spool->sendMail(); } } - } - //Send derivation notification - End } catch (Exception $exception) { throw $exception; } } + /** + * Get attached files from the case note, this require appUid. + * @param string $appUid + * @return array + */ + public function getAttachedFilesFromTheCaseNote(string $appUid): array + { + $attachFileLinks = []; + $url = System::getServerMainPath(); + $result = Documents::getAttachedFilesFromTheCaseNote($appUid); + $result->each(function($item) use($url, &$attachFileLinks) { + $href = $url . "/cases/casesShowCaseNotes?a={$item->APP_DOC_UID}=&v={$item->DOC_VERSION}"; + $attachFileLinks[] = "{$item->APP_DOC_FILENAME}"; + }); + return $attachFileLinks; + } + public function addCaseNote($applicationUid, $userUid, $note, $sendMail) { $response = $this->postNewNote($applicationUid, $userUid, $note, false); diff --git a/workflow/engine/content/translations/english/processmaker.en.po b/workflow/engine/content/translations/english/processmaker.en.po index bcdea0a8f..be838ea9b 100644 --- a/workflow/engine/content/translations/english/processmaker.en.po +++ b/workflow/engine/content/translations/english/processmaker.en.po @@ -2575,6 +2575,12 @@ msgstr "Attach" msgid "Attached" msgstr "Attached" +# TRANSLATION +# LABEL/ID_ATTACHED_FILES +#: LABEL/ID_ATTACHED_FILES +msgid "Attached files" +msgstr "Attached files" + # TRANSLATION # LABEL/ID_ATTRIBUTES #: LABEL/ID_ATTRIBUTES diff --git a/workflow/engine/data/mysql/insert.sql b/workflow/engine/data/mysql/insert.sql index df1b025bb..f0e2571f9 100644 --- a/workflow/engine/data/mysql/insert.sql +++ b/workflow/engine/data/mysql/insert.sql @@ -57232,6 +57232,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE ( 'LABEL','ID_ASSIGN_VARIABLES_OUT','en','Assign Variables Out','2014-01-15') , ( 'LABEL','ID_ATTACH','en','Attach','2014-01-15') , ( 'LABEL','ID_ATTACHED_DB','en','Attached','2014-10-08') , +( 'LABEL','ID_ATTACHED_FILES','en','Attached files','2020-06-10') , ( 'LABEL','ID_ATTRIBUTES','en','Attributes','2014-01-15') , ( 'LABEL','ID_ATTRIBUTE_HAS_INVALID_ELEMENT_KEY','en','The attribute {0}, has an invalid element (incorrect keys).','2014-05-20') , ( 'LABEL','ID_AT_RISK','en','At Risk','2014-01-15') , diff --git a/workflow/engine/src/ProcessMaker/Model/Documents.php b/workflow/engine/src/ProcessMaker/Model/Documents.php index 740e7d689..85939198d 100644 --- a/workflow/engine/src/ProcessMaker/Model/Documents.php +++ b/workflow/engine/src/ProcessMaker/Model/Documents.php @@ -93,4 +93,20 @@ class Documents extends Model return $documentList; } + + /** + * Get attached files from the case note. + * @param string $appUid + * @return object + */ + public static function getAttachedFilesFromTheCaseNote(string $appUid) + { + $result = Documents::select('APP_DOCUMENT.APP_DOC_UID', 'APP_DOCUMENT.DOC_VERSION', 'APP_DOCUMENT.APP_DOC_FILENAME') + ->join('APP_NOTES', function($join) use($appUid) { + $join->on('APP_NOTES.NOTE_ID', '=', 'APP_DOCUMENT.DOC_ID') + ->where('APP_DOCUMENT.APP_UID', '=', $appUid); + }) + ->get(); + return $result; + } } From b38daebb9410f3d3b5594bac8d03b4c88e54d424 Mon Sep 17 00:00:00 2001 From: Fabio Guachalla Date: Wed, 10 Jun 2020 16:29:46 -0400 Subject: [PATCH 03/10] PMCORE-1584: Case notes must have the option to download the attached files Correction Download Show a lot of files Large Text and Tooltip Correction Styles --- .../skinEngine/base/css/pmos-xtheme-gray.css | 8 ++++++++ .../neoclassic/css/pmos-xtheme-gray.css | 8 ++++++++ .../uxmodern/css/pmos-xtheme-gray.css | 8 ++++++++ .../skinEngine/uxs/css/pmos-xtheme-gray.css | 8 ++++++++ workflow/engine/templates/app/main.js | 18 ++++++++++-------- 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/workflow/engine/skinEngine/base/css/pmos-xtheme-gray.css b/workflow/engine/skinEngine/base/css/pmos-xtheme-gray.css index 95e5fa4a5..3e6daffd5 100644 --- a/workflow/engine/skinEngine/base/css/pmos-xtheme-gray.css +++ b/workflow/engine/skinEngine/base/css/pmos-xtheme-gray.css @@ -1675,4 +1675,12 @@ white-space:normal; .navPanelBottom .x-toolbar-cell { clear: both; height: 50px; +} +.nav_list li a { + padding: 2px 2px 2px 10px; + overflow: hidden; + text-overflow: ellipsis; + width: 100px; + white-space: nowrap; + display: inline-block; } \ No newline at end of file diff --git a/workflow/engine/skinEngine/neoclassic/css/pmos-xtheme-gray.css b/workflow/engine/skinEngine/neoclassic/css/pmos-xtheme-gray.css index 13a945ac1..c2432451d 100644 --- a/workflow/engine/skinEngine/neoclassic/css/pmos-xtheme-gray.css +++ b/workflow/engine/skinEngine/neoclassic/css/pmos-xtheme-gray.css @@ -1868,3 +1868,11 @@ white-space:normal; clear: both; height: 50px; } +.nav_list li a { + padding: 2px 2px 2px 10px; + overflow: hidden; + text-overflow: ellipsis; + width: 100px; + white-space: nowrap; + display: inline-block; +} \ No newline at end of file diff --git a/workflow/engine/skinEngine/uxmodern/css/pmos-xtheme-gray.css b/workflow/engine/skinEngine/uxmodern/css/pmos-xtheme-gray.css index 18463561a..b2bb36066 100644 --- a/workflow/engine/skinEngine/uxmodern/css/pmos-xtheme-gray.css +++ b/workflow/engine/skinEngine/uxmodern/css/pmos-xtheme-gray.css @@ -1704,4 +1704,12 @@ text-decoration: none; .navPanelBottom .x-toolbar-cell { clear: both; height: 50px; +} +.nav_list li a { + padding: 2px 2px 2px 10px; + overflow: hidden; + text-overflow: ellipsis; + width: 100px; + white-space: nowrap; + display: inline-block; } \ No newline at end of file diff --git a/workflow/engine/skinEngine/uxs/css/pmos-xtheme-gray.css b/workflow/engine/skinEngine/uxs/css/pmos-xtheme-gray.css index e36622302..85f34c690 100644 --- a/workflow/engine/skinEngine/uxs/css/pmos-xtheme-gray.css +++ b/workflow/engine/skinEngine/uxs/css/pmos-xtheme-gray.css @@ -1249,4 +1249,12 @@ td.x-cnotes-label { .navPanelBottom .x-toolbar-cell { clear: both; height: 50px; +} +.nav_list li a { + padding: 2px 2px 2px 10px; + overflow: hidden; + text-overflow: ellipsis; + width: 100px; + white-space: nowrap; + display: inline-block; } \ No newline at end of file diff --git a/workflow/engine/templates/app/main.js b/workflow/engine/templates/app/main.js index cef2996a1..a54f3998a 100644 --- a/workflow/engine/templates/app/main.js +++ b/workflow/engine/templates/app/main.js @@ -39,7 +39,7 @@ function openCaseNotesWindow(appUid1, delIndex, modalSw, appTitle, proUid, taskU url: "../appProxy/getNotesList?appUid=" + appUid + "&delIndex=" + delIndex + "&pro=" + proUid + "&tas=" + taskUid, root: 'notes', totalProperty: 'totalCount', - fields: ['USR_USERNAME','USR_FIRSTNAME','USR_LASTNAME','USR_FULL_NAME','NOTE_DATE','NOTE_CONTENT', 'USR_UID', 'user'], + fields: ['USR_USERNAME','USR_FIRSTNAME','USR_LASTNAME','USR_FULL_NAME','NOTE_DATE','NOTE_CONTENT', 'USR_UID','USR_EMAIL', 'attachments', 'user'], baseParams:{ start:0, limit:startRecord+loadSize @@ -112,12 +112,13 @@ function openCaseNotesWindow(appUid1, delIndex, modalSw, appTitle, proUid, taskU emptyText: _('ID_CASE_NOTES_EMPTY'), cls: 'x-cnotes-view', tpl: '' + - '
' + + '
' + '' + '' + '' + '' + @@ -129,12 +130,13 @@ function openCaseNotesWindow(appUid1, delIndex, modalSw, appTitle, proUid, taskU singleSelect: true, prepareData: function(data){ - //data.shortName = Ext.util.Format.ellipsis(data.name, 15); - //data.sizeString = Ext.util.Format.fileSize(data.size); - //data.dateString = data.lastmod.format("m/d/Y g:i a"); - - data.user = _FNF(data.USR_USERNAME, data.USR_FIRSTNAME, data.USR_LASTNAME); + var i; + data.user = _FNF(data.USR_EMAIL, data.USR_FIRSTNAME, data.USR_LASTNAME); data.NOTE_CONTENT = data.NOTE_CONTENT.replace(/\n/g,'
'); + data.files = ""; + for (i = 0; i < data.attachments.length; i += 1) { + data.files += "" + data.attachments[i].APP_DOC_FILENAME + ""; + } return data; }, From 5e9ee175d873d7832c86c89a7ca0d1c5adfa124d Mon Sep 17 00:00:00 2001 From: Fabio Guachalla Date: Thu, 11 Jun 2020 16:46:49 -0400 Subject: [PATCH 04/10] PMCORE-1584 --- workflow/engine/templates/app/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workflow/engine/templates/app/main.js b/workflow/engine/templates/app/main.js index a54f3998a..0b9fc62e8 100644 --- a/workflow/engine/templates/app/main.js +++ b/workflow/engine/templates/app/main.js @@ -112,7 +112,7 @@ function openCaseNotesWindow(appUid1, delIndex, modalSw, appTitle, proUid, taskU emptyText: _('ID_CASE_NOTES_EMPTY'), cls: 'x-cnotes-view', tpl: '' + - '
'+ '

{user}

'+ - '

{NOTE_CONTENT}

'+ + '

{NOTE_CONTENT}

'+ + '
' + '

'+_('ID_POSTED_AT')+' {NOTE_DATE}

'+ '
' + + '
' + '' + '' + '
'+ @@ -127,7 +127,7 @@ function openCaseNotesWindow(appUid1, delIndex, modalSw, appTitle, proUid, taskU itemSelector: 'div.x-cnotes-source', overClass: 'x-cnotes-over', selectedClass: 'x-cnotes-selected', - singleSelect: true, + singleSelect: false, prepareData: function(data){ var i; From d629ea9d4a1158a26f3cbdc7cb20af88e2fc979e Mon Sep 17 00:00:00 2001 From: Andrea Adamczyk Date: Wed, 10 Jun 2020 17:27:27 -0400 Subject: [PATCH 05/10] PMCORE-1604-A --- .../methods/cases/casesShowCaseNotes.php | 94 +++++++++++++++++++ workflow/public_html/sysGeneric.php | 1 + 2 files changed, 95 insertions(+) create mode 100644 workflow/engine/methods/cases/casesShowCaseNotes.php diff --git a/workflow/engine/methods/cases/casesShowCaseNotes.php b/workflow/engine/methods/cases/casesShowCaseNotes.php new file mode 100644 index 000000000..22e5df7d5 --- /dev/null +++ b/workflow/engine/methods/cases/casesShowCaseNotes.php @@ -0,0 +1,94 @@ +getLastAppDocVersion($_GET['a']); +} else { + $docVersion = $_GET['v']; +} + +$appDocument->fields = $appDocument->load($_GET['a'], $docVersion); + +//Check if the document is a case note document +if ($appDocument->fields['APP_DOC_TYPE'] != 'CASE_NOTE') { + G::header('Location: /errors/error403.php'); + die(); +} + +//Check if the user can be download the input Document +//Send the parameter v = Version +//Send the parameter a = Case UID +if ($RBAC->userCanAccess('PM_FOLDERS_ALL') != 1 && defined('DISABLE_DOWNLOAD_DOCUMENTS_SESSION_VALIDATION') && DISABLE_DOWNLOAD_DOCUMENTS_SESSION_VALIDATION == 0) { + if (!$appDocument->canDownloadInput($_SESSION['USER_LOGGED'], $_GET['a'], $docVersion)) { + G::header('Location: /errors/error403.php'); + die(); + } +} + +//Create the Cases object +$case = new Cases(); +//Get the case information to get the processUid +$processUid = $case->getCaseInfo($appDocument->fields['APP_UID'], $_SESSION['USER_LOGGED'])->pro_uid; +//Get the user authorization +$userCanAccess = $case->userAuthorization( + $_SESSION['USER_LOGGED'], + $processUid, + $appDocument->fields['APP_UID'], + ['PM_ALLCASES'], + ['CASES_NOTES' => 'VIEW'] +); + +//Check if the user has the Case Notes permissions +if ($userCanAccess['objectPermissions']['CASES_NOTES'] != 1) { + G::header('Location: /errors/error403.php'); + die(); +} + +$appDocUid = $appDocument->getAppDocUid(); +$docVersionInformation = $appDocument->getDocVersion(); +$info = pathinfo($appDocument->getAppDocFilename()); +$ext = (isset($info['extension']) ? $info['extension'] : ''); + +$download = true; + +//Get the document path +$appUid = G::getPathFromUID($appDocument->fields['APP_UID']); +$file = G::getPathFromFileUID($appDocument->fields['APP_UID'], $appDocUid); + +$realPath = PATH_DOCUMENT . $appUid . '/' . $file[0] . $file[1] . '_' . $docVersionInformation . '.' . $ext; +$realPath1 = PATH_DOCUMENT . $appUid . '/' . $file[0] . $file[1] . '.' . $ext; +$sw_file_exists = false; +if (file_exists($realPath)) { + $sw_file_exists = true; +} elseif (file_exists($realPath1)) { + $sw_file_exists = true; + $realPath = $realPath1; +} + +if (!$sw_file_exists) { + $error_message = G::LoadTranslation('ID_ERROR_STREAMING_FILE'); + G::SendMessageText($error_message, "ERROR"); + G::header('Location: ' . $_SERVER['HTTP_REFERER']); + die(); +} else { + $nameFile = $appDocument->fields['APP_DOC_FILENAME']; + G::streamFile($realPath, $download, $nameFile); //download +} diff --git a/workflow/public_html/sysGeneric.php b/workflow/public_html/sysGeneric.php index bb5c9eb63..838b097af 100644 --- a/workflow/public_html/sysGeneric.php +++ b/workflow/public_html/sysGeneric.php @@ -976,6 +976,7 @@ if (!defined('EXECUTE_BY_CRON')) { $noLoginFiles[] = 'cases_SaveData'; $noLoginFiles[] = 'cases_Derivate'; $noLoginFiles[] = 'cases_NextStep'; + $noLoginFiles[] = 'casesShowCaseNotes'; $noLoginFiles[] = 'genericAjax'; $noLoginFiles[] = 'casesSaveDataView'; $noLoginFiles[] = 'propelTableAjax'; From b593e2521b9bbb7de6fc91b3b59c78d88d7038b9 Mon Sep 17 00:00:00 2001 From: Rodrigo Quelca Date: Thu, 11 Jun 2020 16:32:26 -0400 Subject: [PATCH 06/10] PMCORE-1583: Case Notes widget must support attach files in web application fix CR notes fix CR notes 2 after user press addNote button all upload fields will be cleaned improve widget add files validations text area with was updated --- .../translations/english/processmaker.en.po | 12 + workflow/engine/data/mysql/insert.sql | 2 + workflow/engine/templates/app/main.js | 241 ++++++++++++------ 3 files changed, 170 insertions(+), 85 deletions(-) diff --git a/workflow/engine/content/translations/english/processmaker.en.po b/workflow/engine/content/translations/english/processmaker.en.po index be838ea9b..e0d1b1379 100644 --- a/workflow/engine/content/translations/english/processmaker.en.po +++ b/workflow/engine/content/translations/english/processmaker.en.po @@ -1993,6 +1993,12 @@ msgstr "Add Data to PM table" msgid "Add field" msgstr "Add field" +# TRANSLATION +# LABEL/ID_ADD_FILE +#: LABEL/ID_ADD_FILE +msgid "Add file" +msgstr "Add file" + # TRANSLATION # LABEL/ID_ADD_HORIZONTAL_LINE #: LABEL/ID_ADD_HORIZONTAL_LINE @@ -2575,6 +2581,12 @@ msgstr "Attach" msgid "Attached" msgstr "Attached" +# TRANSLATION +# LABEL/ID_ATTACH_FILE +#: LABEL/ID_ATTACH_FILE +msgid "Attach file" +msgstr "Attach file" + # TRANSLATION # LABEL/ID_ATTACHED_FILES #: LABEL/ID_ATTACHED_FILES diff --git a/workflow/engine/data/mysql/insert.sql b/workflow/engine/data/mysql/insert.sql index f0e2571f9..0a07360af 100644 --- a/workflow/engine/data/mysql/insert.sql +++ b/workflow/engine/data/mysql/insert.sql @@ -57133,6 +57133,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE ( 'LABEL','ID_ADD_CUSTOM_COLUMN','en','Add Custom Column','2014-01-15') , ( 'LABEL','ID_ADD_DATA_PMTABLE','en','Add Data to PM table','2014-10-10') , ( 'LABEL','ID_ADD_FIELD','en','Add field','2014-01-15') , +( 'LABEL','ID_ADD_FILE','en','Add file','2020-06-11') , ( 'LABEL','ID_ADD_HORIZONTAL_LINE','en','Add horizontal line','2015-02-20') , ( 'LABEL','ID_ADD_LICENSE','en','Please add a new license','2014-01-15') , ( 'LABEL','ID_ADD_MESSAGE','en','Add message','2014-01-15') , @@ -57232,6 +57233,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE ( 'LABEL','ID_ASSIGN_VARIABLES_OUT','en','Assign Variables Out','2014-01-15') , ( 'LABEL','ID_ATTACH','en','Attach','2014-01-15') , ( 'LABEL','ID_ATTACHED_DB','en','Attached','2014-10-08') , +( 'LABEL','ID_ATTACH_FILE','en','Attach file','2020-06-11') , ( 'LABEL','ID_ATTACHED_FILES','en','Attached files','2020-06-10') , ( 'LABEL','ID_ATTRIBUTES','en','Attributes','2014-01-15') , ( 'LABEL','ID_ATTRIBUTE_HAS_INVALID_ELEMENT_KEY','en','The attribute {0}, has an invalid element (incorrect keys).','2014-05-20') , diff --git a/workflow/engine/templates/app/main.js b/workflow/engine/templates/app/main.js index 0b9fc62e8..8d9e79aaf 100644 --- a/workflow/engine/templates/app/main.js +++ b/workflow/engine/templates/app/main.js @@ -4,8 +4,9 @@ var storeNotes; var appUid; var title; var summaryWindowOpened = false; - var toolTipChkSendMail; +var caseNotesForm; +var uploadItemsSize = 5; function closeCaseNotesWindow(){ if(Ext.get("caseNotesWindowPanel")){ @@ -173,12 +174,101 @@ function openCaseNotesWindow(appUid1, delIndex, modalSw, appTitle, proUid, taskU } ] }); + /** + * Factory to create upload files field dinamically + * @return {Object} + */ + function uploadFileFactory () { + return { + xtype: 'fileuploadfield', + emptyText: '', + fieldLabel: _('ID_ATTACH_FILE'), + buttonText: _('ID_SELECT_FILE'), + name: 'filesToUpload[]', + allowBlank: true, + width : '70%', + validator: function (filePath) { + var flag = false; + if (caseNotesWindow.isVisible() === false || filePath === "") { + return true; + } + filePath = filePath.replace(/^\s|\s$/g, ""); //trims string + if (filePath.match(/([^\/\\]+)\.(pdf|gif|jpg|png|doc|docx|xls|xlsx|txt|mp4|mpv|mpeg|mpg|mov)$/i)) { + flag = true; + } else { + messageError = _('ID_ERROR_UPLOADING_IMAGE_TYPE'); + PMExt.notify(_('ID_ERROR'), messageError); + flag = false; + this.setRawValue(null); + } + return flag; + } + }; + }; + // Cases notes form to insert coments and attach files + caseNotesForm = new Ext.FormPanel({ + width: 462, + anchor: '100%', + baseCls: 'x-plain', + fileUpload: true, + items: + [ + { + text : _('ID_NEW_NOTE'), + xtype : 'textarea', + id : 'caseNoteText', + name : 'caseNoteText', + width : '98%', + height : 100, + hideLabel: true, + maxLengthText : 1500, + allowBlank :false, + selectOnFocus :true, + enableKeyEvents: true, + listeners : { + scope : this, + keyup : updateTextCtr, + keydown: updateTextCtr, + 'change': function(field, newVal, oldVal) { + var textAreaValue = newVal.replace(/^\s+/,'').replace(/\s+$/,''); + field.setValue(textAreaValue.trim()); + Ext.getCmp('caseNoteText').focus(false, 200); + } + } + } + ], + buttons: + [ + { + text: _('ID_ADD_FILE'), + id: 'btnAddFile', + type: 'button', + handler: function () { + var uploadFields = caseNotesForm.findByType('fileuploadfield'); + if (uploadFields.length >= 1 && uploadFields.length < uploadItemsSize) { + if (uploadFields[uploadFields.length - 1].getValue() !== "") { + caseNotesForm.add(uploadFileFactory()); + caseNotesForm.doLayout(); + caseNotesWindow.doLayout(); + } else { + messageError = _('ID_PLEASE_SELECT_FILES_TO_UPLOAD'); + PMExt.notify(_('ID_ERROR'), messageError); + } + } + if (uploadFields.length === uploadItemsSize - 1) { + this.setDisabled(true); + } + + } + } + ] + }); caseNotesWindow = new Ext.Window({ title: _('ID_CASES_NOTES'), //Title of the Window id: 'caseNotesWindowPanel', //ID of the Window Panel width: 480, //Width of the Window - resizable: true, //Resize of the Window, if false - it cannot be resized + resizable: false, //Resize of the Window, if false - it cannot be resized closable: true, //Hide close button of the Window modal: modalSw, //When modal:true it make the window modal and mask everything behind it when displayed //iconCls: 'ICON_CASES_NOTES', @@ -205,33 +295,7 @@ function openCaseNotesWindow(appUid1, delIndex, modalSw, appTitle, proUid, taskU } } ], - tbar:[ - new Ext.form.TextArea({ - text : _('ID_NEW_NOTE'), - xtype : 'textarea', - id : 'caseNoteText', - name : 'caseNoteText', - width : 440, - grow : true, - height : 100, - growMin: 100, - growMax: 80, - maxLengthText : 1500, - allowBlank :false, - selectOnFocus :true, - enableKeyEvents: true, - listeners : { - scope : this, - keyup : updateTextCtr, - keydown: updateTextCtr, - 'change': function(field, newVal, oldVal){ - var textAreaValue = newVal.replace(/^\s+/,'').replace(/\s+$/,''); - field.setValue(textAreaValue.trim()); - Ext.getCmp('caseNoteText').focus(false, 200); - } - } - }) - ], + tbar:[caseNotesForm], rowtbar: [ [ { @@ -283,6 +347,9 @@ function openCaseNotesWindow(appUid1, delIndex, modalSw, appTitle, proUid, taskU this.loadMask = new Ext.LoadMask(this.body, { msg:_('ID_LOADING') }); + caseNotesForm.add(uploadFileFactory()); + caseNotesForm.doLayout(); + caseNotesWindow.doLayout(); }, close:function(){ if (typeof(parent.setFlag) != 'undefined') { @@ -322,6 +389,7 @@ function updateTextCtr(body, event) { function newNoteHandler() { + var i; newNoteAreaActive = newNoteAreaActive ? false : true; if (newNoteAreaActive) { Ext.getCmp('addCancelBtn').setText(''); @@ -351,6 +419,14 @@ function newNoteHandler() document.getElementById('countChar').style.display = 'block'; Ext.getCmp('caseNoteText').focus(); Ext.getCmp('caseNoteText').reset(); + uploadFields = caseNotesForm.findByType('fileuploadfield'); + // clean the first upload field + uploadFields[0].setRawValue(null); + for (i = 1; i < uploadFields.length; i += 1) { + caseNotesForm.remove(uploadFields[i]); + } + caseNotesForm.doLayout(); + Ext.getCmp('btnAddFile').setDisabled(false); document.getElementById('countChar').innerHTML = '1500'; caseNotesWindow.doLayout(); } @@ -358,81 +434,76 @@ function newNoteHandler() caseNotesWindow.doLayout(); } -function sendNote() -{ +function sendNote(){ var noteText = Ext.getCmp('caseNoteText').getValue(); - if (noteText == "") { return false; } - newNoteHandler(); - Ext.getCmp('caseNoteText').focus(); Ext.getCmp('caseNoteText').reset(); Ext.getCmp('caseNoteText').setDisabled(true); Ext.getCmp('sendBtn').setDisabled(true); Ext.getCmp('addCancelBtn').setDisabled(true); statusBarMessage( _('ID_CASES_NOTE_POSTING'), true); - Ext.Ajax.request({ - url : '../appProxy/postNote' , - params : { - appUid: appUid, - noteText: noteText, - swSendMail: (Ext.getCmp("chkSendMail").checked == true)? 1 : 0 - }, - success: function ( result, request ) { - var data = Ext.util.JSON.decode(result.responseText); - if(data.success=="success"){ - Ext.getCmp('caseNoteText').setDisabled(false); - Ext.getCmp('sendBtn').setDisabled(false); - Ext.getCmp('addCancelBtn').setDisabled(false); - if (data.message != '') { - Ext.Msg.show({ + + caseNotesForm.getForm().submit({ + clientValidation: true, + url: '../appProxy/postNote', + params: { + appUid: appUid, + noteText: noteText, + swSendMail: (Ext.getCmp("chkSendMail").checked === true) ? 1 : 0 + }, + success: function ( result, request ) { + var data = Ext.util.JSON.decode(request.response.responseText); + if(data.success=="success"){ + Ext.getCmp('caseNoteText').setDisabled(false); + Ext.getCmp('sendBtn').setDisabled(false); + Ext.getCmp('addCancelBtn').setDisabled(false); + if (data.message != '') { + Ext.Msg.show({ + title : _('ID_CASES_NOTE_POST_ERROR'), + msg : data.message, + icon : Ext.MessageBox.WARNING, + buttons : Ext.Msg.OK, + fn : function(btn) { + statusBarMessage( _('ID_CASES_NOTE_POST_SUCCESS'), false,true); + storeNotes.load(); + } + }); + } else { + statusBarMessage( _('ID_CASES_NOTE_POST_SUCCESS'), false,true); + storeNotes.load(); + } + } else if (data.lostSession) { + Ext.Msg.show({ title : _('ID_CASES_NOTE_POST_ERROR'), msg : data.message, - icon : Ext.MessageBox.WARNING, + icon : Ext.MessageBox.ERROR, buttons : Ext.Msg.OK, fn : function(btn) { - statusBarMessage( _('ID_CASES_NOTE_POST_SUCCESS'), false,true); - storeNotes.load(); + try { + prnt = parent.parent; + top.location = top.location; + } catch (err) { + parent.location = parent.location; + } } - }); + }); } else { - statusBarMessage( _('ID_CASES_NOTE_POST_SUCCESS'), false,true); - storeNotes.load(); + Ext.getCmp('caseNoteText').setDisabled(false); + Ext.getCmp('sendBtn').setDisabled(false); + Ext.getCmp('addCancelBtn').setDisabled(false); + statusBarMessage( _('ID_CASES_NOTE_POST_ERROR'), false,false); + Ext.MessageBox.alert(_('ID_CASES_NOTE_POST_ERROR'), data.message); + } - } else if (data.lostSession) { - Ext.Msg.show({ - title : _('ID_CASES_NOTE_POST_ERROR'), - msg : data.message, - icon : Ext.MessageBox.ERROR, - buttons : Ext.Msg.OK, - fn : function(btn) { - try - { - prnt = parent.parent; - top.location = top.location; - } - catch (err) - { - parent.location = parent.location; - } - } - }); - } else { - Ext.getCmp('caseNoteText').setDisabled(false); - Ext.getCmp('sendBtn').setDisabled(false); - Ext.getCmp('addCancelBtn').setDisabled(false); - statusBarMessage( _('ID_CASES_NOTE_POST_ERROR'), false,false); - Ext.MessageBox.alert(_('ID_CASES_NOTE_POST_ERROR'), data.message); - + }, + failure: function ( result, request) { + statusBarMessage( _('ID_CASES_NOTE_POST_FAILED'), false,false); + Ext.MessageBox.alert(_('ID_CASES_NOTE_POST_FAILED'), result.responseText); } - }, - failure: function ( result, request) { - statusBarMessage( _('ID_CASES_NOTE_POST_FAILED'), false,false); - Ext.MessageBox.alert(_('ID_CASES_NOTE_POST_FAILED'), result.responseText); - } }); } From 5dbaae523fe09e0b23d9b1c055cfbb9cb8a36251 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Wed, 10 Jun 2020 12:15:01 -0400 Subject: [PATCH 07/10] PMCORE-1585 --- gulliver/system/class.g.php | 2 - .../engine/classes/model/AppNotesTest.php | 2 +- .../ProcessMaker/BusinessModel/CasesTest.php | 3 +- workflow/engine/classes/model/AppNotes.php | 36 ++++--- workflow/engine/controllers/appProxy.php | 45 ++++++--- .../src/ProcessMaker/BusinessModel/Cases.php | 95 +++++++++++++------ .../src/ProcessMaker/Model/AppNotes.php | 59 ++++++++++++ .../src/ProcessMaker/Model/Documents.php | 40 +++++++- .../engine/src/ProcessMaker/Util/helpers.php | 6 +- 9 files changed, 227 insertions(+), 61 deletions(-) diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index 8e9e9af86..ee129521e 100644 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -2708,8 +2708,6 @@ class G $nameToSave = $filter->validateInput($nameToSave, "path"); @chmod($path . "/" . $nameToSave, $permission); umask($oldumask); - - return true; } catch (Exception $oException) { throw $oException; } diff --git a/tests/unit/workflow/engine/classes/model/AppNotesTest.php b/tests/unit/workflow/engine/classes/model/AppNotesTest.php index 4d8b3feda..b86714211 100644 --- a/tests/unit/workflow/engine/classes/model/AppNotesTest.php +++ b/tests/unit/workflow/engine/classes/model/AppNotesTest.php @@ -219,7 +219,7 @@ class AppNotesTest extends TestCase $appUid = $appDocument->APP_UID; $appNotes = new ModelAppNotes(); - $result = $appNotes->getAttachedFilesFromTheCaseNote($appUid); + $result = $appNotes->getAttachedFilesFromTheCaseNote($appNote->NOTE_ID); $this->assertNotEmpty($result); } diff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/CasesTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/CasesTest.php index 3c7da31c5..aa55a5548 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/CasesTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/CasesTest.php @@ -124,7 +124,8 @@ class CasesTest extends TestCase // Upload the file $case = new Cases(); $result = $case->uploadFilesInCaseNotes('00000000000000000000000000000001', $application->APP_UID, $filesReferences); - $result = head($result); + $this->assertNotEmpty($result['attachments']); + $result = head($result['attachments']); $this->assertNotEmpty($result); $this->assertArrayHasKey('APP_UID', $result); $this->assertEquals($application->APP_UID, $result['APP_UID']); diff --git a/workflow/engine/classes/model/AppNotes.php b/workflow/engine/classes/model/AppNotes.php index 17c885359..e659bab4f 100644 --- a/workflow/engine/classes/model/AppNotes.php +++ b/workflow/engine/classes/model/AppNotes.php @@ -181,6 +181,7 @@ class AppNotes extends BaseAppNotes * @param string $noteRecipients * @param string $from * @param integer $delIndex + * @param integer $noteId * @return void * @throws Exception * @@ -188,7 +189,15 @@ class AppNotes extends BaseAppNotes * @see AppNotes->postNewNote() * @see workflow/engine/src/ProcessMaker/Util/helpers.php::postNote() */ - public function sendNoteNotification($appUid, $usrUid, $noteContent, $noteRecipients, $from = '', $delIndex = 0) + public function sendNoteNotification( + $appUid, + $usrUid, + $noteContent, + $noteRecipients, + $from = '', + $delIndex = 0, + $noteId = 0 + ) { try { $configuration = System::getEmailConfiguration(); @@ -216,9 +225,13 @@ class AppNotes extends BaseAppNotes $configNoteNotification['body'] = $this->getBodyCaseNote($authorName, $noteContent); $body = nl2br(G::replaceDataField($configNoteNotification['body'], $fieldCase, 'mysql', false)); - $attachFileLinks = $this->getAttachedFilesFromTheCaseNote($appUid); + // Get the files related to the specific case note + if ($noteId !== 0) { + $attachFileLinks = $this->getAttachedFilesFromTheCaseNote($noteId); + } + if (!empty($attachFileLinks)) { - $body = $body . "
" . G::LoadTranslation('ID_ATTACHED_FILES') . ": " . implode("
", $attachFileLinks) . "."; + $body = $body . "
" . G::LoadTranslation('ID_ATTACHED_FILES') . ": 
" . implode("
", $attachFileLinks); } $users = new Users(); $recipientsArray = explode(",", $noteRecipients); @@ -267,19 +280,20 @@ class AppNotes extends BaseAppNotes } /** - * Get attached files from the case note, this require appUid. - * @param string $appUid + * Get attached files from a specific case note + * @param int $docId * @return array */ - public function getAttachedFilesFromTheCaseNote(string $appUid): array + public function getAttachedFilesFromTheCaseNote(int $docId): array { $attachFileLinks = []; $url = System::getServerMainPath(); - $result = Documents::getAttachedFilesFromTheCaseNote($appUid); - $result->each(function($item) use($url, &$attachFileLinks) { - $href = $url . "/cases/casesShowCaseNotes?a={$item->APP_DOC_UID}=&v={$item->DOC_VERSION}"; - $attachFileLinks[] = "{$item->APP_DOC_FILENAME}"; - }); + $result = Documents::getFiles($docId); + foreach ($result as $item) { + $href = $url . "/cases/casesShowCaseNotes?a={$item['APP_DOC_UID']}=&v={$item['DOC_VERSION']}"; + $attachFileLinks[] = "{$item['APP_DOC_FILENAME']}"; + } + return $attachFileLinks; } diff --git a/workflow/engine/controllers/appProxy.php b/workflow/engine/controllers/appProxy.php index 3d9f519f4..ab30a6028 100644 --- a/workflow/engine/controllers/appProxy.php +++ b/workflow/engine/controllers/appProxy.php @@ -1,4 +1,17 @@ tas; } + + // Get user logged $usrUid = $_SESSION['USER_LOGGED']; + // Review if the user has the permissions $respView = $case->getAllObjectsFrom($proUid, $appUid, $tasUid, $usrUid, "VIEW", $delIndex); $respBlock = $case->getAllObjectsFrom($proUid, $appUid, $tasUid, $usrUid, "BLOCK", $delIndex); - if ($respView['CASES_NOTES'] == 0 && $respBlock['CASES_NOTES'] == 0) { return [ 'totalCount' => 0, @@ -99,27 +114,30 @@ class AppProxy extends HttpProxyController ]; } - $usrUid = isset($_SESSION['USER_LOGGED']) ? $_SESSION['USER_LOGGED'] : ""; - $appNotes = new AppNotes(); - $response = $appNotes->getNotesList($appUid, '', $httpData->start, $httpData->limit); + // Get the notes + $appNote = new Notes(); + $response = $appNote->getNotes($appUid, $httpData->start, $httpData->limit); $response = AppNotes::applyHtmlentitiesInNotes($response); + // Prepare the response + $documents = new Documents(); $iterator = 0; - foreach ($response['array']['notes'] as $value) { - $response ['array']['notes'][$iterator]['NOTE_DATE'] = DateTime::convertUtcToTimeZone($value['NOTE_DATE']); + foreach ($response['notes'] as $value) { + $response['notes'][$iterator]['NOTE_DATE'] = DateTime::convertUtcToTimeZone($value['NOTE_DATE']); + $response['notes'][$iterator]['attachments'] = $documents->getFiles($value['NOTE_ID']); $iterator++; } require_once("classes/model/Application.php"); - $oApplication = new Application(); - $aApplication = $oApplication->Load($appUid); - $response['array']['appTitle'] = $aApplication['APP_TITLE']; + $application = new Application(); + $appInfo = $application->Load($appUid); + $response['appTitle'] = $appInfo['APP_TITLE']; - return $response['array']; + return $response; } /** - * post Note Action + * Post a note * * @param string $httpData->appUid (optional, if it is not passed try use $_SESSION['APPLICATION']) * @return array containg the case notes @@ -143,9 +161,10 @@ class AppProxy extends HttpProxyController $this->setSendResponse(false); //Add note case - $appNote = new AppNotes(); + $cases = new BmCases(); try { - $response = $appNote->addCaseNote($appUid, $usrUid, $noteContent, intval($httpData->swSendMail)); + $sendMail = intval($httpData->swSendMail); + $response = $cases->addNote($appUid, $usrUid, $noteContent, $sendMail); } catch (Exception $error) { $response = new stdclass(); $response->success = 'success'; diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php index 15727a9c9..571ab3b66 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php @@ -14,6 +14,7 @@ use AppHistoryPeer; use Application; use ApplicationPeer; use Applications; +use AppNotes; use AppNotesPeer; use AppSolr; use BasePeer; @@ -41,7 +42,7 @@ use ProcessMaker\BusinessModel\User as BmUser; use ProcessMaker\Core\System; use ProcessMaker\Exception\UploadException; use ProcessMaker\Model\Application as ModelApplication; -use ProcessMaker\Model\AppNotes; +use ProcessMaker\Model\AppNotes as Notes; use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Documents; use ProcessMaker\Plugins\PluginRegistry; @@ -3869,16 +3870,25 @@ class Cases "NOTE_AVAILABILITY" => "PUBLIC", "NOTE_RECIPIENTS" => "" ]; - $response = AppNotes::create($attributes); + $newNote = Notes::create($attributes); // Get the FK - $noteId = $response->NOTE_ID; + $noteId = $newNote->NOTE_ID; + $attachments = []; // Register the files related to the note - $this->uploadFilesInCaseNotes($userUid, $appUid, $files, $noteId); + if (!empty($files) || !empty($_FILES["filesToUpload"])) { + $filesResponse = $this->uploadFilesInCaseNotes($userUid, $appUid, $files, $noteId); + foreach ($filesResponse['attachments'] as $key => $value) { + $attachments[$key] = []; + $attachments[$key]['APP_DOC_FILENAME'] = $value['APP_DOC_FILENAME']; + $attachments[$key]['LINK'] = "../cases/cases_ShowDocument?a=" . $value["APP_DOC_UID"] . "&v=" . $value["DOC_VERSION"]; + } + + } // Send the email if ($sendMail) { - // @todo refactor this section the files attached need to send in the email + // Get the recipients $case = new ClassesCases(); $p = $case->getUsersParticipatedInCase($appUid, 'ACTIVE'); $noteRecipientsList = []; @@ -3892,9 +3902,19 @@ class Cases $noteRecipients = implode(",", $noteRecipientsList); $note = stripslashes($note); - $note = new \AppNotes(); - $note->sendNoteNotification($appUid, $userUid, $note, $noteRecipients); + // Send the notification + $appNote = new AppNotes(); + $appNote->sendNoteNotification($appUid, $userUid, $note, $noteRecipients, '', 0, $noteId); } + + // Prepare the response + $result = []; + $result['success'] = 'success'; + $result['message'] = ''; + $result['attachments'] = $attachments; + $result['attachment_errors'] = []; + + return $result; } /** @@ -3910,15 +3930,20 @@ class Cases */ public function uploadFilesInCaseNotes($userUid, $appUid, $filesReferences = [], $noteId = 0) { - if (!empty($_FILES["form"]["name"])) { + $files = []; + if (!empty($_FILES["filesToUpload"])) { $upload = true; - // Array from post upload - foreach ($_FILES["form"]["name"] as $fileIndex => $fileName) { - if (!is_array($fileName)) { + // This format is from ext-js multipart + $filesName = !empty($_FILES["filesToUpload"]["name"]) ? $_FILES["filesToUpload"]["name"] : []; + $filesTmpName = !empty($_FILES["filesToUpload"]["tmp_name"]) ? $_FILES["filesToUpload"]["tmp_name"] : []; + $filesError = !empty($_FILES["filesToUpload"]["error"]) ? $_FILES["filesToUpload"]["error"] : []; + + foreach ($filesName as $index => $value) { + if (!empty($value)) { $files[] = [ - 'name' => $_FILES["form"]["name"][$fileIndex], - 'tmp_name' => $_FILES["form"]["tmp_name"][$fileIndex], - 'error' => $_FILES["form"]["error"][$fileIndex] + 'name' => $filesName[$index], + 'tmp_name' => $filesTmpName[$index], + 'error' => $filesError[$index] ]; } } @@ -3941,31 +3966,43 @@ class Cases // We will to register the files in the database $response = []; + $response['attachments'] = []; + $response['attachment_errors'] = []; if (!empty($files)) { $i = 0; + $j = 0; foreach ($files as $fileIndex => $fileName) { // There is no error, the file uploaded with success if ($fileName["error"] === UPLOAD_ERR_OK) { $appDocUid = G::generateUniqueID(); - $attributes = [ - "DOC_ID" => $noteId, - "APP_DOC_UID" => $appDocUid, - "DOC_VERSION" => 1, - "APP_UID" => $appUid, - "DEL_INDEX" => $delIndex, - "USR_UID" => $userUid, - "DOC_UID" => -1, - "APP_DOC_TYPE" => 'CASE_NOTE', - "APP_DOC_CREATE_DATE" => date("Y-m-d H:i:s"), - "APP_DOC_FILENAME" => $fileName["name"] - ]; - Documents::create($attributes); // Upload or move the file $isUploaded = saveAppDocument($fileName, $appUid, $appDocUid, 1, $upload); - // List of files uploaded or copy - $response[$i++] = $attributes; + // If the file was uploaded correctly we will to register in the DB + if ($isUploaded) { + $attributes = [ + "DOC_ID" => $noteId, + "APP_DOC_UID" => $appDocUid, + "DOC_VERSION" => 1, + "APP_UID" => $appUid, + "DEL_INDEX" => $delIndex, + "USR_UID" => $userUid, + "DOC_UID" => -1, + "APP_DOC_TYPE" => 'CASE_NOTE', + "APP_DOC_CREATE_DATE" => date("Y-m-d H:i:s"), + "APP_DOC_FILENAME" => $fileName["name"] + ]; + Documents::create($attributes); + + // List of files uploaded or copy + $response['attachments'][$i++] = $attributes; + } else { + $response['attachment_errors'][$j++] = [ + 'error' => 'error', + 'file' => $fileName["name"] + ]; + } } else { throw new UploadException($fileName['error']); } diff --git a/workflow/engine/src/ProcessMaker/Model/AppNotes.php b/workflow/engine/src/ProcessMaker/Model/AppNotes.php index 402662991..66c00b43b 100644 --- a/workflow/engine/src/ProcessMaker/Model/AppNotes.php +++ b/workflow/engine/src/ProcessMaker/Model/AppNotes.php @@ -44,4 +44,63 @@ class AppNotes extends Model 'NOTE_AFFECTED_OBJ2', 'NOTE_RECIPIENTS' ]; + + /** + * Scope a query to filter an specific case + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param string $appUid + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeAppUid($query, string $appUid) + { + return $query->where('APP_UID', $appUid); + } + + /** + * Return the documents related to the case + * + * @param string $appUid + * @param int $start + * @param int $limit + * @param string $dir + * + * @return array + */ + public static function getNotes(string $appUid, $start = 0, $limit = 25, $dir = 'DESC') + { + $query = AppNotes::query()->select([ + 'NOTE_ID', + 'APP_UID', + 'NOTE_DATE', + 'NOTE_CONTENT', + 'NOTE_TYPE', + 'NOTE_AVAILABILITY', + 'USERS.USR_UID', + 'USERS.USR_USERNAME', + 'USERS.USR_FIRSTNAME', + 'USERS.USR_LASTNAME' + ]); + $query->leftJoin('USERS', function ($join) { + $join->on('USERS.USR_UID', '=', 'APP_NOTES.USR_UID'); + }); + $query->appUid($appUid); + $query->orderBy('NOTE_DATE', $dir); + // Add pagination to the query + $query->offset($start)->limit($limit); + + $results = $query->get(); + $notes = []; + $notes['notes'] = []; + $results->each(function ($item, $key) use (&$notes) { + $row = $item->toArray(); + $row['NOTE_CONTENT'] = stripslashes($row['NOTE_CONTENT']); + $notes['notes'][] = $row; + }); + + // Add the total of rows to return + $notes['totalCount'] = $limit; + + return $notes; + } } diff --git a/workflow/engine/src/ProcessMaker/Model/Documents.php b/workflow/engine/src/ProcessMaker/Model/Documents.php index 85939198d..ec9b45d59 100644 --- a/workflow/engine/src/ProcessMaker/Model/Documents.php +++ b/workflow/engine/src/ProcessMaker/Model/Documents.php @@ -64,7 +64,7 @@ class Documents extends Model * Scope a query to filter an specific case * * @param \Illuminate\Database\Eloquent\Builder $query - * @param string $proUid + * @param string $appUid * @return \Illuminate\Database\Eloquent\Builder */ public function scopeAppUid($query, string $appUid) @@ -72,10 +72,22 @@ class Documents extends Model return $query->where('APP_UID', $appUid); } + /** + * Scope a query to filter an specific reference file + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @param int $docId + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeDocId($query, int $docId) + { + return $query->where('DOC_ID', $docId); + } + /** * Return the documents related to the case * - * @param int $proId + * @param string $appUid * @param string $type * * @return array @@ -96,7 +108,9 @@ class Documents extends Model /** * Get attached files from the case note. + * * @param string $appUid + * * @return object */ public static function getAttachedFilesFromTheCaseNote(string $appUid) @@ -109,4 +123,26 @@ class Documents extends Model ->get(); return $result; } + + /** + * Return the documents related to the specific DOC_ID + * + * @param int $docId + * + * @return array + */ + public static function getFiles(int $docId) + { + $query = Documents::query()->select(['APP_DOC_UID', 'APP_DOC_FILENAME', 'DOC_VERSION']); + $query->docId($docId); + $results = $query->get(); + $documentList = []; + $results->each(function ($item, $key) use (&$documentList) { + $row = $item->toArray(); + $row['LINK'] = "../cases/cases_ShowDocument?a=" . $row["APP_DOC_UID"] . "&v=" . $row["DOC_VERSION"]; + $documentList[] = $row; + }); + + return $documentList; + } } diff --git a/workflow/engine/src/ProcessMaker/Util/helpers.php b/workflow/engine/src/ProcessMaker/Util/helpers.php index a844b2eaa..e63d20a30 100644 --- a/workflow/engine/src/ProcessMaker/Util/helpers.php +++ b/workflow/engine/src/ProcessMaker/Util/helpers.php @@ -617,22 +617,24 @@ function saveAppDocument($file, $appUid, $appDocUid, $version = 1, $upload = tru try { $info = pathinfo($file["name"]); $extension = ((isset($info["extension"])) ? $info["extension"] : ""); - //$pathCase = G::getPathFromUID($appUid); $fileName = $appDocUid . "_" . $version . "." . $extension; $pathCase = PATH_DATA_SITE . 'files' . PATH_SEP . G::getPathFromUID($appUid) . PATH_SEP; $response = false; if ($upload) { - $response = G::uploadFile( + G::uploadFile( $file["tmp_name"], $pathCase, $fileName ); + $response = true; } else { G::verifyPath($pathCase, true); $response = copy($file["tmp_name"], $pathCase . $fileName); } + + return $response; } catch (Exception $e) { throw $e; } From 008ed8a730fdcd59c762b41c05fdbde380f632c1 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Fri, 12 Jun 2020 15:16:11 -0400 Subject: [PATCH 08/10] PMCORE-1585 --- workflow/engine/classes/model/AppNotes.php | 2 +- workflow/engine/src/ProcessMaker/BusinessModel/Cases.php | 2 +- workflow/engine/src/ProcessMaker/Model/Documents.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/workflow/engine/classes/model/AppNotes.php b/workflow/engine/classes/model/AppNotes.php index e659bab4f..823096a79 100644 --- a/workflow/engine/classes/model/AppNotes.php +++ b/workflow/engine/classes/model/AppNotes.php @@ -290,7 +290,7 @@ class AppNotes extends BaseAppNotes $url = System::getServerMainPath(); $result = Documents::getFiles($docId); foreach ($result as $item) { - $href = $url . "/cases/casesShowCaseNotes?a={$item['APP_DOC_UID']}=&v={$item['DOC_VERSION']}"; + $href = $url . "/cases/casesShowCaseNotes?a={$item['APP_DOC_UID']}&v={$item['DOC_VERSION']}"; $attachFileLinks[] = "{$item['APP_DOC_FILENAME']}"; } diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php index 571ab3b66..ab320ad74 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php @@ -3881,7 +3881,7 @@ class Cases foreach ($filesResponse['attachments'] as $key => $value) { $attachments[$key] = []; $attachments[$key]['APP_DOC_FILENAME'] = $value['APP_DOC_FILENAME']; - $attachments[$key]['LINK'] = "../cases/cases_ShowDocument?a=" . $value["APP_DOC_UID"] . "&v=" . $value["DOC_VERSION"]; + $attachments[$key]['LINK'] = "../cases/casesShowCaseNotes?a=" . $value["APP_DOC_UID"] . "&v=" . $value["DOC_VERSION"]; } } diff --git a/workflow/engine/src/ProcessMaker/Model/Documents.php b/workflow/engine/src/ProcessMaker/Model/Documents.php index ec9b45d59..8a42abde3 100644 --- a/workflow/engine/src/ProcessMaker/Model/Documents.php +++ b/workflow/engine/src/ProcessMaker/Model/Documents.php @@ -139,7 +139,7 @@ class Documents extends Model $documentList = []; $results->each(function ($item, $key) use (&$documentList) { $row = $item->toArray(); - $row['LINK'] = "../cases/cases_ShowDocument?a=" . $row["APP_DOC_UID"] . "&v=" . $row["DOC_VERSION"]; + $row['LINK'] = "../cases/casesShowCaseNotes?a=" . $row["APP_DOC_UID"] . "&v=" . $row["DOC_VERSION"]; $documentList[] = $row; }); From 9d9ce52fa8a54673c4d9f6964116b1a66b218e23 Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Fri, 12 Jun 2020 20:59:28 -0400 Subject: [PATCH 09/10] PMCORE-1619 Validations in the upload files related to cases notes before to move appDocument. --- tests/resources/testDocument.pdf | Bin 0 -> 7922 bytes .../ProcessMaker/BusinessModel/CasesTest.php | 51 ++++---- .../ValidationUploadedFilesTest.php | 39 +++++- .../translations/english/processmaker.en.po | 18 +++ workflow/engine/controllers/appProxy.php | 6 + workflow/engine/data/mysql/insert.sql | 3 + .../src/ProcessMaker/BusinessModel/Cases.php | 19 ++- .../Exception/CaseNoteUploadFile.php | 21 ++++ .../Validation/ValidationUploadedFiles.php | 114 ++++++++++++++++++ 9 files changed, 240 insertions(+), 31 deletions(-) create mode 100644 tests/resources/testDocument.pdf create mode 100644 workflow/engine/src/ProcessMaker/Exception/CaseNoteUploadFile.php diff --git a/tests/resources/testDocument.pdf b/tests/resources/testDocument.pdf new file mode 100644 index 0000000000000000000000000000000000000000..08299237a520f6e5f5bdb05ec7efe3e9f0da0efc GIT binary patch literal 7922 zcmai31yqz<*H-BPln@Y57#gV=reKti2I-PUU>G`w0g(_9kZuK$66uf>=?+0aKpF{Y zkPfBwpYh)B=J&1tUF)55&VKjV`J6Lr?aiejD=#Q41P5@nWwq6}y=zMcK!9MNvxOZ% zObn!gcCyCW0HHXF7D(RK0gJ|fehXjwGM*%B=w0dT`&(B_T+&lIk3Ve(e+)xg6; zekXdS?G6OUpQ`j#fDzjlpp%_Qi_i~W?Vgq!K0XS$M;}NCZ}`e;xOZPocxRG^nVxH4 z6zmZ|J!h*X-S@pcM)KV{$ZL2^P+K`9snKRR11nJhdP7Xiv~X8@O<=$JQxhDqU<$$% zK)M52&m_4-1Qn7OmTvbZgX%|P(-7OY?CsIrQNTuRs{+vkt?%Amop9t&SCefIV3S}AM{hY zm859hx;Su&Z63J9qaAD6Pml=$MtwiZR3tddWS9)R6y{bhZ={jO&nLw869n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ff --git a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/CasesTest.php b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/CasesTest.php index aa55a5548..dcea64514 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/CasesTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/BusinessModel/CasesTest.php @@ -7,6 +7,7 @@ use G; use ProcessMaker\Model\Application; use ProcessMaker\Model\Delegation; use ProcessMaker\Model\Documents; +use ProcessMaker\Model\User; use RBAC; use Tests\TestCase; @@ -17,6 +18,21 @@ use Tests\TestCase; */ class CasesTest extends TestCase { + + /** + * Set up method. + */ + public function setUp() + { + parent::setUp(); + Delegation::truncate(); + Documents::truncate(); + Application::truncate(); + User::where('USR_ID', '=', 1) + ->where('USR_ID', '=', 2) + ->delete(); + } + /** * This checks the delete case * @@ -28,11 +44,11 @@ class CasesTest extends TestCase { // Set the RBAC global $RBAC; - $_SESSION['USER_LOGGED'] = '00000000000000000000000000000002'; - $RBAC = RBAC::getSingleton(PATH_DATA, session_id()); + $_SESSION['USER_LOGGED'] = G::generateUniqueID(); + $RBAC = RBAC::getSingleton(); $RBAC->initRBAC(); - $application = factory(Application::class)->create(); + $application = factory(Application::class)->create(['APP_INIT_USER' => G::generateUniqueID()]); // Tried to delete case $case = new Cases(); $case->deleteCase($application->APP_UID, $_SESSION['USER_LOGGED']); @@ -50,7 +66,7 @@ class CasesTest extends TestCase // Set the RBAC global $RBAC; $_SESSION['USER_LOGGED'] = '00000000000000000000000000000001'; - $RBAC = RBAC::getSingleton(PATH_DATA, session_id()); + $RBAC = RBAC::getSingleton(); $RBAC->initRBAC(); $application = factory(Application::class)->create(['APP_STATUS' => 'TO_DO']); @@ -70,38 +86,17 @@ class CasesTest extends TestCase { // Set the RBAC global $RBAC; - $_SESSION['USER_LOGGED'] = '00000000000000000000000000000001'; - $RBAC = RBAC::getSingleton(PATH_DATA, session_id()); + $_SESSION['USER_LOGGED'] = G::generateUniqueID(); + $RBAC = RBAC::getSingleton(); $RBAC->initRBAC(); - $application = factory(Application::class)->create(['APP_INIT_USER' => '00000000000000000000000000000002']); + $application = factory(Application::class)->create(['APP_INIT_USER' => G::generateUniqueID()]); // Tried to delete case $case = new Cases(); $case->deleteCase($application->APP_UID, $_SESSION['USER_LOGGED']); } /** - * Review the upload file related to the case notes, an return an exception when the array is empty - * - * @covers \ProcessMaker\BusinessModel\Cases::uploadFilesInCaseNotes() - * - * @test - * @expectedException Exception - */ - public function it_return_exception_in_upload_files_related_case_note() - { - $application = factory(Application::class)->create(); - factory(Delegation::class)->states('foreign_keys')->create([ - 'APP_NUMBER' => $application->APP_NUMBER, - 'APP_UID' => $application->APP_UID - ]); - // Upload the file - $case = new Cases(); - // Return an exception because the files does not exist - $case->uploadFilesInCaseNotes('00000000000000000000000000000001', $application->APP_UID, $filesReferences = []); - } - - /** * Review the upload file related to the case notes * * @covers \ProcessMaker\BusinessModel\Cases::uploadFilesInCaseNotes() diff --git a/tests/unit/workflow/engine/src/ProcessMaker/Validation/ValidationUploadedFilesTest.php b/tests/unit/workflow/engine/src/ProcessMaker/Validation/ValidationUploadedFilesTest.php index 21cb3b094..d4b8f2edf 100644 --- a/tests/unit/workflow/engine/src/ProcessMaker/Validation/ValidationUploadedFilesTest.php +++ b/tests/unit/workflow/engine/src/ProcessMaker/Validation/ValidationUploadedFilesTest.php @@ -112,6 +112,43 @@ class ValidationUploadedFilesTest extends TestCase $this->assertEquals(0, $result->getStatus()); } + /** + * This test verify validation rules for files post in cases notes. + * @test + * @covers ::runRulesForPostFilesOfNote + */ + public function it_should_test_run_rules_for_post_files_of_note() + { + //assert for file has not exist + $file = [ + 'filename' => 'testDocument.pdf', + 'path' => "testDocument.pdf" + ]; + $validation = new ValidationUploadedFiles(); + $result = $validation->runRulesForPostFilesOfNote($file); + $this->assertTrue($result->fails()); + + //assert for file has not valid extension + $file = [ + 'filename' => 'projectData.json', + 'path' => PATH_TRUNK . "tests/resources/projectData.json" + ]; + $validation = new ValidationUploadedFiles(); + $result = $validation->runRulesForPostFilesOfNote($file); + $this->assertTrue($result->fails()); + + //assert the file exists and has valid extension + $file = [ + 'filename' => 'testDocument.pdf', + 'path' => PATH_TRUNK . "tests/resources/testDocument.pdf" + ]; + $validation = new ValidationUploadedFiles(); + $result = $validation->runRulesForPostFilesOfNote($file); + $this->assertFalse($result->fails()); + $this->assertEmpty($result->getMessage()); + $this->assertEquals(0, $result->getStatus()); + } + /** * It deletes the images created */ @@ -128,4 +165,4 @@ class ValidationUploadedFilesTest extends TestCase unlink(PATH_DATA . '1.PnG'); } } -} \ No newline at end of file +} diff --git a/workflow/engine/content/translations/english/processmaker.en.po b/workflow/engine/content/translations/english/processmaker.en.po index e0d1b1379..3817ab047 100644 --- a/workflow/engine/content/translations/english/processmaker.en.po +++ b/workflow/engine/content/translations/english/processmaker.en.po @@ -25307,6 +25307,12 @@ msgstr "Error: The application {0} is not canceled." msgid "The default configuration was not defined" msgstr "The default configuration was not defined" +# TRANSLATION +# LABEL/ID_THE_FILE_COULDNT_BE_UPLOADED +#: LABEL/ID_THE_FILE_COULDNT_BE_UPLOADED +msgid "The file couldn’t be uploaded please review the allowed files or contact your System Administrator." +msgstr "The file couldn’t be uploaded please review the allowed files or contact your System Administrator." + # TRANSLATION # LABEL/ID_THE_FILE_SIZE_IS_BIGGER_THAN_THE_MAXIMUM_ALLOWED #: LABEL/ID_THE_FILE_SIZE_IS_BIGGER_THAN_THE_MAXIMUM_ALLOWED @@ -27707,6 +27713,12 @@ msgstr "Yesterday" msgid "[LABEL/ID_YES_VALUE] Yes" msgstr "Yes" +# TRANSLATION +# LABEL/ID_YOUR_FILE_HAS_EXCEEDED +#: LABEL/ID_YOUR_FILE_HAS_EXCEEDED +msgid "Your file has exceeded the file maximum size that is {0}." +msgstr "Your file has exceeded the file maximum size that is {0}." + # TRANSLATION # LABEL/ID_YOUR_IMAGE_HAS_BEEN_SUCCESSFULLY #: LABEL/ID_YOUR_IMAGE_HAS_BEEN_SUCCESSFULLY @@ -27761,6 +27773,12 @@ msgstr "You do not select any user to import" msgid "you have an error" msgstr "you have an error" +# TRANSLATION +# LABEL/ID_YOU_UPLOADED_AN_UNSUPPORTED_FILE_EXTENSION +#: LABEL/ID_YOU_UPLOADED_AN_UNSUPPORTED_FILE_EXTENSION +msgid "You uploaded an unsupported file extension, please review the permitted files uploaded in the wiki of ProcessMaker for the cases notes." +msgstr "You uploaded an unsupported file extension, please review the permitted files uploaded in the wiki of ProcessMaker for the cases notes." + # TRANSLATION # LABEL/ID_ZIP_CODE #: LABEL/ID_ZIP_CODE diff --git a/workflow/engine/controllers/appProxy.php b/workflow/engine/controllers/appProxy.php index ab30a6028..f105d3b71 100644 --- a/workflow/engine/controllers/appProxy.php +++ b/workflow/engine/controllers/appProxy.php @@ -10,6 +10,7 @@ */ use ProcessMaker\BusinessModel\Cases as BmCases; +use ProcessMaker\Exception\CaseNoteUploadFile; use ProcessMaker\Model\AppNotes as Notes; use ProcessMaker\Model\Documents; use ProcessMaker\Util\DateTime; @@ -165,6 +166,11 @@ class AppProxy extends HttpProxyController try { $sendMail = intval($httpData->swSendMail); $response = $cases->addNote($appUid, $usrUid, $noteContent, $sendMail); + } catch (CaseNoteUploadFile $e) { + $response = new stdclass(); + $response->success = 'success'; + $response->message = $e->getMessage(); + die(G::json_encode($response)); } catch (Exception $error) { $response = new stdclass(); $response->success = 'success'; diff --git a/workflow/engine/data/mysql/insert.sql b/workflow/engine/data/mysql/insert.sql index 0a07360af..c34c84ad4 100644 --- a/workflow/engine/data/mysql/insert.sql +++ b/workflow/engine/data/mysql/insert.sql @@ -61109,6 +61109,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE ( 'LABEL','ID_THERE_PROBLEM_SENDING_EMAIL','en','There was a problem sending the email to','2016-04-08') , ( 'LABEL','ID_THE_APPLICATION_IS_NOT_CANCELED','en','Error: The application {0} is not canceled.','2016-06-15') , ( 'LABEL','ID_THE_DEFAULT_CONFIGURATION','en','The default configuration was not defined','2016-11-16') , +( 'LABEL','ID_THE_FILE_COULDNT_BE_UPLOADED','en','The file couldn’t be uploaded please review the allowed files or contact your System Administrator.','2020-06-12') , ( 'LABEL','ID_THE_FILE_SIZE_IS_BIGGER_THAN_THE_MAXIMUM_ALLOWED','en','The file size is bigger than the maximum allowed, the maximum size allowed is {0} Mbytes.','2019-02-26') , ( 'LABEL','ID_THE_MAXIMUM_VALUE_OF_THIS_FIELD_IS','en','The maximum value of this field is {0}.','2019-02-26') , ( 'LABEL','ID_THE_MIMETYPE_EXTENSION_ERROR','en','The mime type does not correspond to the permitted extension, please verify your file.','2018-10-02') , @@ -61519,6 +61520,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE ( 'LABEL','ID_YES','en','Yes','2014-01-15') , ( 'LABEL','ID_YESTERDAY','en','Yesterday','2014-01-15') , ( 'LABEL','ID_YES_VALUE','en','Yes','2014-01-15') , +( 'LABEL','ID_YOUR_FILE_HAS_EXCEEDED','en','Your file has exceeded the file maximum size that is 10MB.','2020-06-12') , ( 'LABEL','ID_YOUR_IMAGE_HAS_BEEN_SUCCESSFULLY','en','Your image has been successfully uploaded','2014-01-15') , ( 'LABEL','ID_YOUR_LICENSE','en','Your license','2014-09-18') , ( 'LABEL','ID_YOUR_PASSWORD_IS','en','Your password is','2014-01-15') , @@ -61528,6 +61530,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE ( 'LABEL','ID_YOU_DO_NOT_HAVE_PERMISSION','en','Error: You do not have permission.','2016-06-15') , ( 'LABEL','ID_YOU_DO_NOT_SELECT_ANY_USER_TO_IMPORT','en','You do not select any user to import','2015-09-15') , ( 'LABEL','ID_YOU_HAVE_ERROR','en','you have an error','2014-01-15') , +( 'LABEL','ID_YOU_UPLOADED_AN_UNSUPPORTED_FILE_EXTENSION','en','You uploaded an unsupported file extension, please review the permitted files uploaded in the wiki of ProcessMaker for the cases notes.','2020-06-12') , ( 'LABEL','ID_ZIP_CODE','en','Zip Code','2014-01-15') , ( 'LABEL','IMAGE_DETAIL','en','Image detail','2014-01-15') , ( 'LABEL','IMPORT_LANGUAGE_ERR_NO_WRITABLE','en','The XML forms directory is not writable','2014-01-15') , diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php index 571ab3b66..1182c5177 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php @@ -41,6 +41,7 @@ use ProcessMaker\BusinessModel\Task as BmTask; use ProcessMaker\BusinessModel\User as BmUser; use ProcessMaker\Core\System; use ProcessMaker\Exception\UploadException; +use ProcessMaker\Exception\CaseNoteUploadFile; use ProcessMaker\Model\Application as ModelApplication; use ProcessMaker\Model\AppNotes as Notes; use ProcessMaker\Model\Delegation; @@ -49,6 +50,7 @@ use ProcessMaker\Plugins\PluginRegistry; use ProcessMaker\Services\OAuth2\Server; use ProcessMaker\Util\DateTime as UtilDateTime; use ProcessMaker\Validation\ExceptionRestApi; +use ProcessMaker\Validation\ValidationUploadedFiles; use ProcessMaker\Validation\Validator as FileValidator; use ProcessPeer; use ProcessUser; @@ -3960,6 +3962,21 @@ class Cases } } + //rules validation + foreach ($files as $key => $value) { + $entry = [ + "filename" => $value['name'], + "path" => $value['tmp_name'] + ]; + $validator = ValidationUploadedFiles::getValidationUploadedFiles() + ->runRulesForPostFilesOfNote($entry); + if ($validator->fails()) { + Notes::where('NOTE_ID', '=', $noteId)->delete(); + $messageError = G::LoadTranslation('ID_THE_FILE_COULDNT_BE_UPLOADED'); + throw new CaseNoteUploadFile($messageError . ' ' . $validator->getMessage()); + } + } + // Get the delIndex related to the case $cases = new ClassesCases(); $delIndex = $cases->getCurrentDelegation($appUid); @@ -4007,8 +4024,6 @@ class Cases throw new UploadException($fileName['error']); } } - } else { - throw new Exception(G::LoadTranslation('ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR')); } return $response; diff --git a/workflow/engine/src/ProcessMaker/Exception/CaseNoteUploadFile.php b/workflow/engine/src/ProcessMaker/Exception/CaseNoteUploadFile.php new file mode 100644 index 000000000..246a1ea66 --- /dev/null +++ b/workflow/engine/src/ProcessMaker/Exception/CaseNoteUploadFile.php @@ -0,0 +1,21 @@ +validate(); } + /** + * Check if the loaded files comply with the validation rules, add here if you + * want more validation rules. + * Accept per argument an array or object that contains a "filename" and "path" values. + * The rules are verified in the order in which they have been added. + * + * @param array|object $file + * @return Validator + */ + public function runRulesForPostFilesOfNote($file) + { + $validator = new Validator(); + + //rule: file exists + $rule = $validator->addRule(); + $rule->validate($file, function($file) use($rule) { + $path = isset($file->path) ? $file->path : ""; + $filesystem = new Filesystem(); + if (!$filesystem->exists($path)) { + $rule->message(G::LoadTranslation('ID_NOT_EXISTS_FILE')); + return self::INVALID; + } + return self::VALID; + }) + ->status(400) + ->log(function($rule) { + /** + * Levels supported by MonologProvider is: + * 100 "DEBUG" + * 200 "INFO" + * 250 "NOTICE" + * 300 "WARNING" + * 400 "ERROR" + * 500 "CRITICAL" + * 550 "ALERT" + * 600 "EMERGENCY" + */ + Bootstrap::registerMonologPhpUploadExecution('phpUpload', $rule->getStatus(), $rule->getMessage(), $rule->getData()->filename); + }); + + //rule: extensions + $rule = $validator->addRule(); + $rule->validate($file, function($file) use($rule) { + $filesystem = new Filesystem(); + $extension = strtolower($filesystem->extension($file->filename)); + $extensions = [ + 'pdf', 'gif', 'jpg', 'png', 'doc', 'docx', 'xls', 'xlsx', 'txt', 'mp4', 'mpv', 'mpeg', 'mpg', 'mov' + ]; + if (!in_array($extension, $extensions)) { + $rule->message(G::LoadTranslation('ID_YOU_UPLOADED_AN_UNSUPPORTED_FILE_EXTENSION')); + return self::INVALID; + } + return self::VALID; + }) + ->status(400) + ->log(function($rule) { + /** + * Levels supported by MonologProvider is: + * 100 "DEBUG" + * 200 "INFO" + * 250 "NOTICE" + * 300 "WARNING" + * 400 "ERROR" + * 500 "CRITICAL" + * 550 "ALERT" + * 600 "EMERGENCY" + */ + Bootstrap::registerMonologPhpUploadExecution('phpUpload', $rule->getStatus(), $rule->getMessage(), $rule->getData()->filename); + }); + + //rule: file size + $rule = $validator->addRule(); + $rule->validate($file, function($file) use($rule) { + $path = isset($file->path) ? $file->path : ""; + $filesystem = new Filesystem(); + $limitSize = '10M'; + $size = $filesystem->size($path); + $phpShorthandByte = new PhpShorthandByte(); + $postMaxSizeBytes = $phpShorthandByte->valueToBytes($limitSize); + if ($size > $postMaxSizeBytes) { + $rule->message(G::LoadTranslation('ID_YOUR_FILE_HAS_EXCEEDED', [$limitSize])); + return self::INVALID; + } + return self::VALID; + }) + ->status(400) + ->log(function($rule) { + /** + * Levels supported by MonologProvider is: + * 100 "DEBUG" + * 200 "INFO" + * 250 "NOTICE" + * 300 "WARNING" + * 400 "ERROR" + * 500 "CRITICAL" + * 550 "ALERT" + * 600 "EMERGENCY" + */ + Bootstrap::registerMonologPhpUploadExecution('phpUpload', $rule->getStatus(), $rule->getMessage(), $rule->getData()->filename); + }); + + return $validator->validate(); + } + /** * Get the first error and call the argument function. * From b821c2ee85ce9af1a5fa2ce63e9db26249baab23 Mon Sep 17 00:00:00 2001 From: Paula Quispe Date: Fri, 12 Jun 2020 21:07:20 -0400 Subject: [PATCH 10/10] PMCORE-1388 --- database/factories/DocumentsFactory.php | 2 +- workflow/engine/classes/WsBase.php | 3 ++- workflow/engine/classes/model/AppNotes.php | 2 +- workflow/engine/src/ProcessMaker/BusinessModel/Cases.php | 3 +-- workflow/engine/src/ProcessMaker/Util/helpers.php | 1 + 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/database/factories/DocumentsFactory.php b/database/factories/DocumentsFactory.php index acfafb0ce..f4ef0429f 100644 --- a/database/factories/DocumentsFactory.php +++ b/database/factories/DocumentsFactory.php @@ -28,7 +28,7 @@ $factory->define(\ProcessMaker\Model\Documents::class, function (Faker $faker) { ]; }); -// Create a dynaform with the foreign keys +// Create a document related to the case notes $factory->state(\ProcessMaker\Model\Documents::class, 'case_notes', function (Faker $faker) { return [ 'APP_DOC_UID' => G::generateUniqueID(), diff --git a/workflow/engine/classes/WsBase.php b/workflow/engine/classes/WsBase.php index 48330d1cd..dd84fcc3c 100644 --- a/workflow/engine/classes/WsBase.php +++ b/workflow/engine/classes/WsBase.php @@ -1,6 +1,7 @@ addNote($caseUid, $userUid, $note, $sendMail, $files); //Response diff --git a/workflow/engine/classes/model/AppNotes.php b/workflow/engine/classes/model/AppNotes.php index 823096a79..4ecece2d9 100644 --- a/workflow/engine/classes/model/AppNotes.php +++ b/workflow/engine/classes/model/AppNotes.php @@ -231,7 +231,7 @@ class AppNotes extends BaseAppNotes } if (!empty($attachFileLinks)) { - $body = $body . "
" . G::LoadTranslation('ID_ATTACHED_FILES') . ": 
" . implode("
", $attachFileLinks); + $body = $body . "
" . G::LoadTranslation('ID_ATTACHED_FILES') . ": 
" . implode("
", $attachFileLinks); } $users = new Users(); $recipientsArray = explode(",", $noteRecipients); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php index 372ac5b14..b021baa02 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Cases.php @@ -3858,7 +3858,6 @@ class Cases * @param array $files * * @return array - * @throws Exception */ public function addNote($appUid, $userUid, $note, $sendMail = false, $files = []) { @@ -3925,7 +3924,7 @@ class Cases * @param string $userUid * @param string $appUid * @param array $filesReferences - * @param string $appDocUid + * @param int $noteId * * @return array * @throws Exception diff --git a/workflow/engine/src/ProcessMaker/Util/helpers.php b/workflow/engine/src/ProcessMaker/Util/helpers.php index e63d20a30..dac3f1644 100644 --- a/workflow/engine/src/ProcessMaker/Util/helpers.php +++ b/workflow/engine/src/ProcessMaker/Util/helpers.php @@ -609,6 +609,7 @@ function getMysqlVersion() * @param string $appUid * @param string $appDocUid * @param int $version + * @param bool $upload * * @return string */