PMCORE-490

This commit is contained in:
Paula Quispe
2020-01-06 14:30:41 -04:00
parent 8c4c329abe
commit 26bde68123
12 changed files with 278 additions and 79 deletions

View File

@@ -40,6 +40,7 @@ use ProcessMaker\BusinessModel\Task as BmTask;
use ProcessMaker\BusinessModel\User as BmUser;
use ProcessMaker\Core\System;
use ProcessMaker\Exception\UploadException;
use ProcessMaker\Model\Application as ModelApplication;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Plugins\PluginRegistry;
use ProcessMaker\Services\OAuth2\Server;
@@ -1114,35 +1115,37 @@ class Cases
* Delete case
*
* @access public
* @param string $app_uid, Uid for case
* @param string $usr_uid, Uid user
* @param string $appUid, Uid for case
* @param string $usrUid, Uid user
*
* @return void
* @throws Exception
*/
public function deleteCase($app_uid, $usr_uid)
public function deleteCase($appUid, $usrUid)
{
Validator::isString($app_uid, '$app_uid');
Validator::appUid($app_uid, '$app_uid');
Validator::isString($appUid, '$app_uid');
Validator::appUid($appUid, '$app_uid');
$criteria = new Criteria();
$criteria->addSelectColumn(ApplicationPeer::APP_STATUS);
$criteria->addSelectColumn(ApplicationPeer::APP_INIT_USER);
$criteria->add(ApplicationPeer::APP_UID, $app_uid, Criteria::EQUAL);
$dataset = ApplicationPeer::doSelectRS($criteria);
$dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$dataset->next();
$aRow = $dataset->getRow();
if ($aRow['APP_STATUS'] != 'DRAFT') {
throw (new Exception(G::LoadTranslation("ID_DELETE_CASE_NO_STATUS")));
// Review the permission for delete case
global $RBAC;
if ($RBAC->userCanAccess('PM_DELETECASE') != 1) {
throw new Exception(G::LoadTranslation('ID_NOT_ABLE_DELETE_CASES'));
}
if ($aRow['APP_INIT_USER'] != $usr_uid) {
throw (new Exception(G::LoadTranslation("ID_DELETE_CASE_NO_OWNER")));
// Review the status and user
$caseInfo = ModelApplication::getCase($appUid);
if (!empty($caseInfo)){
// Review the status
if ($caseInfo['APP_STATUS'] != 'DRAFT') {
throw new Exception(G::LoadTranslation("ID_DELETE_CASE_NO_STATUS"));
}
// Review the user requester
if ($caseInfo['APP_INIT_USER'] != $usrUid) {
throw new Exception(G::LoadTranslation("ID_DELETE_CASE_NO_OWNER"));
}
}
$case = new ClassesCases();
$case->removeCase($app_uid);
$case->removeCase($appUid);
}
/**

View File

@@ -27,24 +27,23 @@ class Application extends Model
}
/**
* Get Applications by PRO_UID, ordered by APP_NUMBER.
* @param string $proUid
* @return object
* @see ReportTables->populateTable()
* Scope for query to get the application by APP_UID.
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $appUid
* @return \Illuminate\Database\Eloquent\Builder
*/
public static function getByProUid($proUid)
public function scopeAppUid($query, $appUid)
{
$query = Application::query()
->select()
->proUid($proUid)
->orderBy('APP_NUMBER', 'ASC');
return $query->get();
$result = $query->where('APP_UID', '=', $appUid);
return $result;
}
/**
* Scope for query to get the applications by PRO_UID.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $proUid
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeProUid($query, $proUid)
@@ -52,4 +51,38 @@ class Application extends Model
$result = $query->where('PRO_UID', '=', $proUid);
return $result;
}
/**
* Get Applications by PRO_UID, ordered by APP_NUMBER.
*
* @param string $proUid
*
* @return object
* @see ReportTables->populateTable()
*/
public static function getByProUid($proUid)
{
$query = Application::query()
->select()
->proUid($proUid)
->orderBy('APP_NUMBER', 'ASC');
return $query->get();
}
/**
* Get information related to the created case
*
* @param string $appUid
*
* @return array|bool
*/
public static function getCase($appUid)
{
$query = Application::query()->select(['APP_STATUS', 'APP_INIT_USER']);
$query->appUid($appUid);
$result = $query->get()->toArray();
$firstElement = head($result);
return $firstElement;
}
}