Merged in bugfix/PMCORE-1751 (pull request #7473)
PMCORE-1751 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com>
This commit is contained in:
committed by
Julio Cesar Laura Avendaño
commit
9533307f0f
@@ -56,6 +56,7 @@ define('PATH_SMARTY_CACHE', PATH_TRUNK . 'shared/compiled/smarty/cache');
|
|||||||
define('PATH_THIRDPARTY', PATH_TRUNK . 'thirdparty/');
|
define('PATH_THIRDPARTY', PATH_TRUNK . 'thirdparty/');
|
||||||
define("URL_KEY", 'c0l0s40pt1mu59r1m3');
|
define("URL_KEY", 'c0l0s40pt1mu59r1m3');
|
||||||
define("PATH_XMLFORM", PATH_CORE . "xmlform" . PATH_SEP);
|
define("PATH_XMLFORM", PATH_CORE . "xmlform" . PATH_SEP);
|
||||||
|
define('PATH_DOCUMENT', PATH_WORKSPACE . '/files/');
|
||||||
|
|
||||||
// Set Time Zone
|
// Set Time Zone
|
||||||
$_SESSION['__SYSTEM_UTC_TIME_ZONE__'] = (int) (env('MAIN_SYSTEM_UTC_TIME_ZONE', 'workflow')) == 1;
|
$_SESSION['__SYSTEM_UTC_TIME_ZONE__'] = (int) (env('MAIN_SYSTEM_UTC_TIME_ZONE', 'workflow')) == 1;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace ProcessMaker\BusinessModel;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use G;
|
use G;
|
||||||
|
use ProcessMaker\BusinessModel\Cases;
|
||||||
use ProcessMaker\Model\Application;
|
use ProcessMaker\Model\Application;
|
||||||
use ProcessMaker\Model\Delegation;
|
use ProcessMaker\Model\Delegation;
|
||||||
use ProcessMaker\Model\Documents;
|
use ProcessMaker\Model\Documents;
|
||||||
@@ -29,8 +30,8 @@ class CasesTest extends TestCase
|
|||||||
Documents::truncate();
|
Documents::truncate();
|
||||||
Application::truncate();
|
Application::truncate();
|
||||||
User::where('USR_ID', '=', 1)
|
User::where('USR_ID', '=', 1)
|
||||||
->where('USR_ID', '=', 2)
|
->where('USR_ID', '=', 2)
|
||||||
->delete();
|
->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,4 +133,104 @@ class CasesTest extends TestCase
|
|||||||
// Remove the path created
|
// Remove the path created
|
||||||
G::rm_dir($pathCase);
|
G::rm_dir($pathCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It tests the uploadFiles method
|
||||||
|
*
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases::uploadFiles()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_should_test_upload_files_method()
|
||||||
|
{
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
$application = factory(Application::class)->create([
|
||||||
|
'APP_CUR_USER' => $user->USR_UID
|
||||||
|
]);
|
||||||
|
$delegation = factory(Delegation::class)->create([
|
||||||
|
'APP_UID' => $application->APP_UID
|
||||||
|
]);
|
||||||
|
$varName = "/tmp/test.pdf";
|
||||||
|
fopen($varName, "w");
|
||||||
|
$_FILES = ["form" =>
|
||||||
|
[
|
||||||
|
"name" => ["test"],
|
||||||
|
"type" => ["application/pdf"],
|
||||||
|
"tmp_name" => ["/tmp/test.pdf"],
|
||||||
|
"error" => [0],
|
||||||
|
"size" => [0]
|
||||||
|
]];
|
||||||
|
|
||||||
|
$case = new Cases();
|
||||||
|
|
||||||
|
// Call the uploadFiles method, sending the delIndex
|
||||||
|
$res = $case->uploadFiles($user->USR_UID, $application->APP_UID, $varName, -1, null, $delegation->DEL_INDEX);
|
||||||
|
// Asserts the result is not empy
|
||||||
|
$this->assertNotEmpty($res);
|
||||||
|
|
||||||
|
//Call the uploadFiles method, without the delIndex
|
||||||
|
$res = $case->uploadFiles($user->USR_UID, $application->APP_UID, $varName);
|
||||||
|
// Asserts the result is not empy
|
||||||
|
$this->assertNotEmpty($res);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It tests the exception in the uploadFiles method
|
||||||
|
*
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases::uploadFiles()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_should_test_exception_in_upload_files_method()
|
||||||
|
{
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
$application = factory(Application::class)->create([
|
||||||
|
'APP_CUR_USER' => $user->USR_UID
|
||||||
|
]);
|
||||||
|
factory(Delegation::class)->create([
|
||||||
|
'APP_UID' => $application->APP_UID
|
||||||
|
]);
|
||||||
|
$varName = "/tmp/test.pdf";
|
||||||
|
fopen($varName, "w");
|
||||||
|
|
||||||
|
$_FILES = [];
|
||||||
|
$case = new Cases();
|
||||||
|
|
||||||
|
// Asserts an exception is expected
|
||||||
|
$this->expectExceptionMessage("**ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR**");
|
||||||
|
// Call the uploadFiles method
|
||||||
|
$case->uploadFiles($user->USR_UID, $application->APP_UID, $varName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* It tests the exception in uploadFiles method
|
||||||
|
*
|
||||||
|
* @covers \ProcessMaker\BusinessModel\Cases::uploadFiles()
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function it_should_test_the_exception_in_upload_files_method()
|
||||||
|
{
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
$application = factory(Application::class)->create([
|
||||||
|
'APP_CUR_USER' => $user->USR_UID
|
||||||
|
]);
|
||||||
|
$delegation = factory(Delegation::class)->create([
|
||||||
|
'APP_UID' => $application->APP_UID
|
||||||
|
]);
|
||||||
|
$varName = "/tmp/test.pdf";
|
||||||
|
fopen($varName, "w");
|
||||||
|
$_FILES = ["form" =>
|
||||||
|
[
|
||||||
|
"name" => ["test"],
|
||||||
|
"type" => ["application/pdf"],
|
||||||
|
"tmp_name" => ["/tmp/test.pdf"],
|
||||||
|
"error" => [UPLOAD_ERR_INI_SIZE],
|
||||||
|
"size" => [0]
|
||||||
|
]];
|
||||||
|
|
||||||
|
$case = new Cases();
|
||||||
|
|
||||||
|
// Asserts there is an exception for the file
|
||||||
|
$this->expectExceptionMessage("The uploaded file exceeds the upload_max_filesize directive in php.ini");
|
||||||
|
// Call the uploadFiles method
|
||||||
|
$case->uploadFiles($user->USR_UID, $application->APP_UID, $varName, -1, null, $delegation->DEL_INDEX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ use Luracast\Restler\Defaults;
|
|||||||
use Luracast\Restler\HumanReadableCache;
|
use Luracast\Restler\HumanReadableCache;
|
||||||
use Luracast\Restler\RestException;
|
use Luracast\Restler\RestException;
|
||||||
use Maveriks\Extension\Restler;
|
use Maveriks\Extension\Restler;
|
||||||
|
use ProcessMaker\Model\Application;
|
||||||
|
use ProcessMaker\Model\Delegation;
|
||||||
|
use ProcessMaker\Model\User;
|
||||||
use ProcessMaker\Services\Api\Cases;
|
use ProcessMaker\Services\Api\Cases;
|
||||||
use RBAC;
|
use RBAC;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
@@ -213,4 +216,74 @@ class CasesTest extends TestCase
|
|||||||
|
|
||||||
$this->assertTrue($expected);
|
$this->assertTrue($expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the uploadDocumentToCase method
|
||||||
|
*
|
||||||
|
* @covers ProcessMaker\Services\Api\Cases::uploadDocumentToCase
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function test_upload_document_to_case_method()
|
||||||
|
{
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
$application = factory(Application::class)->create([
|
||||||
|
'APP_CUR_USER' => $user->USR_UID
|
||||||
|
]);
|
||||||
|
$delegation = factory(Delegation::class)->create([
|
||||||
|
'APP_UID' => $application->APP_UID
|
||||||
|
]);
|
||||||
|
$varName = "/tmp/test.pdf";
|
||||||
|
|
||||||
|
$varName = "/tmp/test.pdf";
|
||||||
|
fopen($varName, "w");
|
||||||
|
$_FILES = ["form" =>
|
||||||
|
[
|
||||||
|
"name" => ["test"],
|
||||||
|
"type" => ["application/pdf"],
|
||||||
|
"tmp_name" => ["/tmp/test.pdf"],
|
||||||
|
"error" => [0],
|
||||||
|
"size" => [0]
|
||||||
|
]];
|
||||||
|
|
||||||
|
$case = new Cases();
|
||||||
|
|
||||||
|
//Call the uploadDocumentToCase method without a post delindex
|
||||||
|
$res = $case->uploadDocumentToCase($application->APP_UID, $varName);
|
||||||
|
//Asserts the result is not empty
|
||||||
|
$this->assertNotEmpty($res);
|
||||||
|
$_POST['delIndex'] = $delegation->DEL_INDEX;
|
||||||
|
//Call the uploadDocumentToCase method with a post delindex
|
||||||
|
$res = $case->uploadDocumentToCase($application->APP_UID, $varName, -1, null, $delegation->DEL_INDEX);
|
||||||
|
//Asserts the result is not empty
|
||||||
|
$this->assertNotEmpty($res);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the exception in the uploadDocumentToCase method
|
||||||
|
*
|
||||||
|
* @covers ProcessMaker\Services\Api\Cases::uploadDocumentToCase
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function test_exception_upload_document_to_case_method()
|
||||||
|
{
|
||||||
|
$user = factory(User::class)->create();
|
||||||
|
$application = factory(Application::class)->create([
|
||||||
|
'APP_CUR_USER' => $user->USR_UID
|
||||||
|
]);
|
||||||
|
$delegation = factory(Delegation::class)->create([
|
||||||
|
'APP_UID' => $application->APP_UID
|
||||||
|
]);
|
||||||
|
$varName = "/tmp/test.pdf";
|
||||||
|
|
||||||
|
$varName = "/tmp/test.pdf";
|
||||||
|
fopen($varName, "w");
|
||||||
|
$_FILES = [];
|
||||||
|
|
||||||
|
$case = new Cases();
|
||||||
|
|
||||||
|
//Asserts the expected exception
|
||||||
|
$this->expectExceptionMessage("**ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR**");
|
||||||
|
//Call the uploadDocumentToCase method without a post delindex
|
||||||
|
$res = $case->uploadDocumentToCase($application->APP_UID, $varName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3783,17 +3783,22 @@ class Cases
|
|||||||
* @param string $varName
|
* @param string $varName
|
||||||
* @param mixed $inpDocUid
|
* @param mixed $inpDocUid
|
||||||
* @param string $appDocUid
|
* @param string $appDocUid
|
||||||
|
* @param int $delegationIndex
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function uploadFiles($userUid, $appUid, $varName, $inpDocUid = -1, $appDocUid = null)
|
public function uploadFiles($userUid, $appUid, $varName, $inpDocUid = -1, $appDocUid = null, $delegationIndex = null)
|
||||||
{
|
{
|
||||||
$response = [];
|
$response = [];
|
||||||
if (isset($_FILES["form"]["name"]) && count($_FILES["form"]["name"]) > 0) {
|
if (isset($_FILES["form"]["name"]) && count($_FILES["form"]["name"]) > 0) {
|
||||||
// Get the delIndex related to the case
|
// Get the delIndex related to the case
|
||||||
$cases = new ClassesCases();
|
$cases = new ClassesCases();
|
||||||
$delIndex = $cases->getCurrentDelegation($appUid, $userUid);
|
if (!empty($delegationIndex)) {
|
||||||
|
$delIndex = $delegationIndex;
|
||||||
|
} else {
|
||||||
|
$delIndex = $cases->getCurrentDelegation($appUid, $userUid);
|
||||||
|
}
|
||||||
// Get information about the user
|
// Get information about the user
|
||||||
$user = new ModelUsers();
|
$user = new ModelUsers();
|
||||||
$userCreator = $user->loadDetailed($userUid)['USR_FULLNAME'];
|
$userCreator = $user->loadDetailed($userUid)['USR_FULLNAME'];
|
||||||
|
|||||||
@@ -1409,6 +1409,7 @@ class Cases extends Api
|
|||||||
* @param string $var_name
|
* @param string $var_name
|
||||||
* @param string $doc_uid
|
* @param string $doc_uid
|
||||||
* @param string $app_doc_uid
|
* @param string $app_doc_uid
|
||||||
|
* @param int $delIndex {@from body}
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
@@ -1416,12 +1417,16 @@ class Cases extends Api
|
|||||||
* @access protected
|
* @access protected
|
||||||
* @class AccessControl {@permission PM_CASES}
|
* @class AccessControl {@permission PM_CASES}
|
||||||
*/
|
*/
|
||||||
public function uploadDocumentToCase($app_uid, $var_name, $doc_uid = '-1', $app_doc_uid = null)
|
public function uploadDocumentToCase($app_uid, $var_name, $doc_uid = '-1', $app_doc_uid = null, $delIndex = null)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$userUid = $this->getUserId();
|
$userUid = $this->getUserId();
|
||||||
$case = new BmCases();
|
$case = new BmCases();
|
||||||
$response = $case->uploadFiles($userUid, $app_uid, $var_name, $doc_uid, $app_doc_uid);
|
if (isset($delIndex)) {
|
||||||
|
$response = $case->uploadFiles($userUid, $app_uid, $var_name, $doc_uid, $app_doc_uid, $delIndex);
|
||||||
|
} else {
|
||||||
|
$response = $case->uploadFiles($userUid, $app_uid, $var_name, $doc_uid, $app_doc_uid);
|
||||||
|
}
|
||||||
} catch (ExceptionRestApi $e) {
|
} catch (ExceptionRestApi $e) {
|
||||||
throw new RestException($e->getCode(), $e->getMessage());
|
throw new RestException($e->getCode(), $e->getMessage());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user