GI-162 Corregir obser. code Review Pmdrive/Gmail SOLVED

- Add validation error_log, return

Change validate array_search == null to === false

Change setTimeout 36000 to 60000
This commit is contained in:
Marco A. Nina Mena
2015-11-27 10:09:02 -04:00
parent 9691cfad4c
commit c8bef4c68d
7 changed files with 104 additions and 85 deletions

View File

@@ -2302,14 +2302,14 @@ class Cases
break; break;
} }
if(array_key_exists('gmail',$_SESSION) || (array_key_exists('gmail',$_GET) && $_GET['gmail'] == 1)){ if(array_key_exists('gmail',$_SESSION) || (array_key_exists('gmail',$_GET) && $_GET['gmail'] == 1)){
$aNextStep = array( $aNextStep = array(
'TYPE' => $oStep->getStepTypeObj(), 'TYPE' => $oStep->getStepTypeObj(),
'UID' => $oStep->getStepUidObj(), 'UID' => $oStep->getStepUidObj(),
'POSITION' => $oStep->getStepPosition(), 'POSITION' => $oStep->getStepPosition(),
'PAGE' => 'cases_Step?TYPE=' . $oStep->getStepTypeObj() . '&UID=' . 'PAGE' => 'cases_Step?TYPE=' . $oStep->getStepTypeObj() . '&UID=' .
$oStep->getStepUidObj() . '&POSITION=' . $oStep->getStepPosition() . $oStep->getStepUidObj() . '&POSITION=' . $oStep->getStepPosition() .
'&ACTION=' . $sAction . '&ACTION=' . $sAction .
'&gmail=1' '&gmail=1'
); );
} else{ } else{
$aNextStep = array( $aNextStep = array(
@@ -2336,11 +2336,11 @@ class Cases
'PAGE' => 'cases_Step?TYPE=ASSIGN_TASK&UID=-1&POSITION=10000&ACTION=ASSIGN&gmail=1' 'PAGE' => 'cases_Step?TYPE=ASSIGN_TASK&UID=-1&POSITION=10000&ACTION=ASSIGN&gmail=1'
); );
}else { }else {
$aNextStep = array( $aNextStep = array(
'TYPE' => 'DERIVATION', 'TYPE' => 'DERIVATION',
'UID' => -1, 'UID' => -1,
'POSITION' => ($iLastStep + 1), 'POSITION' => ($iLastStep + 1),
'PAGE' => 'cases_Step?TYPE=ASSIGN_TASK&UID=-1&POSITION=10000&ACTION=ASSIGN' 'PAGE' => 'cases_Step?TYPE=ASSIGN_TASK&UID=-1&POSITION=10000&ACTION=ASSIGN'
); );
} }
} }
@@ -3980,7 +3980,7 @@ class Cases
if ($row['TU_RELATION'] == 1) { if ($row['TU_RELATION'] == 1) {
//users //users
$dataUser = $user->load($row['USR_UID']); $dataUser = $user->load($row['USR_UID']);
if (array_search($dataUser['USR_EMAIL'], $userPermission) == null) { if (array_search($dataUser['USR_EMAIL'], $userPermission) === false) {
$objectPermissions = $this->getAllObjects($row['PRO_UID'], $applicationUid, $row['TAS_UID'], $objectPermissions = $this->getAllObjects($row['PRO_UID'], $applicationUid, $row['TAS_UID'],
$row['USR_UID']); $row['USR_UID']);
$userPermission[] = $dataUser['USR_EMAIL']; $userPermission[] = $dataUser['USR_EMAIL'];
@@ -3997,7 +3997,7 @@ class Cases
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($oDataset->next()) { while ($oDataset->next()) {
$aRow = $oDataset->getRow(); $aRow = $oDataset->getRow();
if (array_search($aRow['USR_EMAIL'], $userPermission) == null) { if (array_search($aRow['USR_EMAIL'], $userPermission) === false) {
$objectPermissions = $this->getAllObjects($row['PRO_UID'], $applicationUid, $objectPermissions = $this->getAllObjects($row['PRO_UID'], $applicationUid,
$row['TAS_UID'], $aRow['USR_UID']); $row['TAS_UID'], $aRow['USR_UID']);
$userPermission[] = $aRow['USR_EMAIL']; $userPermission[] = $aRow['USR_EMAIL'];

View File

@@ -7,6 +7,7 @@
* *
*/ */
G::LoadClass( "pmGoogleApi" ); G::LoadClass( "pmGoogleApi" );
class PMDrive extends PMGoogleApi class PMDrive extends PMGoogleApi
{ {
private $folderIdPMDrive = ''; private $folderIdPMDrive = '';
@@ -102,18 +103,18 @@ class PMDrive extends PMGoogleApi
$service = $this->serviceDrive(); $service = $this->serviceDrive();
try { try {
$rows = array();
$parameters['q'] = "'" . $fileId . "' in parents and trashed = false"; $parameters['q'] = "'" . $fileId . "' in parents and trashed = false";
$parents = $service->files->listFiles($parameters); $parents = $service->files->listFiles($parameters);
$rows = array();
foreach ($parents->getItems() as $parent) { foreach ($parents->getItems() as $parent) {
//echo 'File Id: ' . $parent->getId() . '<br>';
$rows = $parent; $rows = $parent;
} }
return $rows;
} catch (Exception $e) { } catch (Exception $e) {
return G::LoadTranslation("ID_MSG_AJAX_FAILURE") . $e->getMessage(); error_log( G::LoadTranslation("ID_MSG_AJAX_FAILURE") . $e->getMessage());
} }
return $rows;
} }
/** /**
@@ -141,10 +142,11 @@ class PMDrive extends PMGoogleApi
try { try {
$createdFolder = $service->files->insert($file); $createdFolder = $service->files->insert($file);
return $createdFolder;
} catch (Exception $e) { } catch (Exception $e) {
return "An error occurred: " . $e->getMessage(); $createdFolder = null;
error_log ( "An error occurred: " . $e->getMessage());
} }
return $createdFolder;
} }
/** /**
@@ -157,7 +159,6 @@ class PMDrive extends PMGoogleApi
*/ */
public function uploadFile($mime, $src, $name, $parentId = null) public function uploadFile($mime, $src, $name, $parentId = null)
{ {
//$this->validateFolderPMDrive();
$this->setScope('https://www.googleapis.com/auth/drive.file'); $this->setScope('https://www.googleapis.com/auth/drive.file');
$service = $this->serviceDrive(); $service = $this->serviceDrive();
@@ -185,10 +186,10 @@ class PMDrive extends PMGoogleApi
) )
); );
return $createdFile;
} catch (Exception $e) { } catch (Exception $e) {
return "An error occurred: " . $e->getMessage(); error_log( "An error occurred: " . $e->getMessage());
} }
return $createdFile;
} }
/** /**
@@ -199,7 +200,6 @@ class PMDrive extends PMGoogleApi
*/ */
public function downloadFile($fileId) public function downloadFile($fileId)
{ {
//$this->validateFolderPMDrive();
$this->setScope('https://www.googleapis.com/auth/drive'); $this->setScope('https://www.googleapis.com/auth/drive');
$this->setScope('https://www.googleapis.com/auth/drive.appdata'); $this->setScope('https://www.googleapis.com/auth/drive.appdata');
$this->setScope('https://www.googleapis.com/auth/drive.apps.readonly'); $this->setScope('https://www.googleapis.com/auth/drive.apps.readonly');
@@ -211,24 +211,24 @@ class PMDrive extends PMGoogleApi
try { try {
$file = $service->files->get($fileId); $file = $service->files->get($fileId);
$response = null;
$downloadUrl = $file->getDownloadUrl(); $downloadUrl = $file->getDownloadUrl();
if ($downloadUrl) { if ($downloadUrl) {
$request = new Google_Http_Request($downloadUrl, 'GET', null, null); $request = new Google_Http_Request($downloadUrl, 'GET', null, null);
$httpRequest = $service->getClient()->getAuth()->authenticatedRequest($request); $httpRequest = $service->getClient()->getAuth()->authenticatedRequest($request);
if ($httpRequest->getResponseHttpCode() == 200) { if ($httpRequest->getResponseHttpCode() == 200) {
return $httpRequest->getResponseBody(); $response = $httpRequest->getResponseBody();
} else { } else {
// An error occurred. error_log( "An error occurred. ");
return null;
} }
} else { } else {
// The file doesn't have any content stored on Drive. error_log( "The file doesn't have any content stored on Drive.");
return null;
} }
} catch (Exception $e) { } catch (Exception $e) {
print "An error occurred: " . $e->getMessage(); error_log( "An error occurred: " . $e->getMessage());
} }
return $response;
} }
/** /**
@@ -261,10 +261,9 @@ class PMDrive extends PMGoogleApi
) )
); );
return $permission;
} catch (Exception $e) { } catch (Exception $e) {
error_log('permission error: ' . $e->getMessage()); error_log('permission error: ' . $e->getMessage());
return "An error occurred: " . $e->getMessage();
} }
return $permission;
} }
} }

View File

@@ -181,7 +181,12 @@ class PMGoogleApi
{ {
$client = null; $client = null;
if ($this->typeAuthentication == 'webApplication') { if ($this->typeAuthentication == 'webApplication') {
$credential = file_get_contents(PATH_DATA_SITE . $this->accountJson); if (file_exists(PATH_DATA_SITE . $this->accountJson)) {
$credential = file_get_contents(PATH_DATA_SITE . $this->accountJson);
} else {
throw new Exception(G::LoadTranslation('ID_GOOGLE_FILE_JSON_ERROR'));
}
$client = new Google_Client(); $client = new Google_Client();
$client->setAuthConfig($credential); $client->setAuthConfig($credential);
@@ -206,7 +211,12 @@ class PMGoogleApi
die; die;
} }
} else if ($this->typeAuthentication == 'serviceAccount') { } else if ($this->typeAuthentication == 'serviceAccount') {
$key = file_get_contents(PATH_DATA_SITE . $this->serviceAccountP12);
if (file_exists(PATH_DATA_SITE . $this->serviceAccountP12)) {
$key = file_get_contents(PATH_DATA_SITE . $this->serviceAccountP12);
} else {
throw new Exception(G::LoadTranslation('ID_GOOGLE_FILE_P12_ERROR'));
}
$assertionCredentials = new Google_Auth_AssertionCredentials( $assertionCredentials = new Google_Auth_AssertionCredentials(
$this->serviceAccountEmail, $this->serviceAccountEmail,
@@ -244,7 +254,12 @@ class PMGoogleApi
); );
if ($credentials->typeAuth == 'webApplication') { if ($credentials->typeAuth == 'webApplication') {
$credential = file_get_contents($credentials->pathFileJson);
if (file_exists($credentials->pathFileJson)) {
$credential = file_get_contents($credentials->pathFileJson);
} else {
throw new Exception(G::LoadTranslation('ID_GOOGLE_FILE_JSON_ERROR'));
}
$client = new Google_Client(); $client = new Google_Client();
$client->setAuthConfig($credential); $client->setAuthConfig($credential);
@@ -267,7 +282,12 @@ class PMGoogleApi
die; die;
} }
} else { } else {
$key = file_get_contents($credentials->pathServiceAccountP12);
if (file_exists($credentials->pathServiceAccountP12)) {
$key = file_get_contents($credentials->pathServiceAccountP12);
} else {
throw new Exception(G::LoadTranslation('ID_GOOGLE_FILE_P12_ERROR'));
}
$assertionCredentials = new Google_Auth_AssertionCredentials( $assertionCredentials = new Google_Auth_AssertionCredentials(
$credentials->emailServiceAccount, $credentials->emailServiceAccount,
$scope, $scope,

View File

@@ -412,7 +412,7 @@ try {
if ($row['TU_RELATION'] == 1) { if ($row['TU_RELATION'] == 1) {
//users //users
$dataUser = $user->load($row['USR_UID']); $dataUser = $user->load($row['USR_UID']);
if (array_search($dataUser['USR_EMAIL'], $userPermission) == null) { if (array_search($dataUser['USR_EMAIL'], $userPermission) === false) {
$userPermission[] = $dataUser['USR_EMAIL']; $userPermission[] = $dataUser['USR_EMAIL'];
} }
} else { } else {
@@ -427,7 +427,7 @@ try {
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($dataset->next()) { while ($dataset->next()) {
$aRow = $oDataset->getRow(); $aRow = $oDataset->getRow();
if (array_search($aRow['USR_EMAIL'], $userPermission) == null) { if (array_search($aRow['USR_EMAIL'], $userPermission) === false) {
$userPermission[] = $aRow['USR_EMAIL']; $userPermission[] = $aRow['USR_EMAIL'];
} }

View File

@@ -1,38 +1,38 @@
<?php <?php
if (!isset($_SESSION['USER_LOGGED'])) { if (!isset($_SESSION['USER_LOGGED'])) {
G::SendTemporalMessage( 'ID_LOGIN_AGAIN', 'warning', 'labels' ); G::SendTemporalMessage( 'ID_LOGIN_AGAIN', 'warning', 'labels' );
die( '<script type="text/javascript"> die( '<script type="text/javascript">
try try
{ {
var olink = document.location.href; var olink = document.location.href;
if(olink.search("gmail") == -1){ if(olink.search("gmail") == -1){
prnt = parent.parent; prnt = parent.parent;
top.location = top.location; top.location = top.location;
} else { } else {
var data = olink.split("?"); var data = olink.split("?");
var odata = data[1].split("&"); var odata = data[1].split("&");
var appUid = odata[1].split("="); var appUid = odata[1].split("=");
var proUid = odata[0].split("="); var proUid = odata[0].split("=");
var dataToSend = { var dataToSend = {
"action": "credentials", "action": "credentials",
"operation": "refreshPmSession", "operation": "refreshPmSession",
"type": "processCall", "type": "processCall",
"funParams": [ "funParams": [
appUid[1], appUid[1],
proUid[1] proUid[1]
], ],
}; };
var x = parent.postMessage(JSON.stringify(dataToSend), "*"); var x = parent.postMessage(JSON.stringify(dataToSend), "*");
if (x == undefined){ if (x == undefined){
x = parent.parent.postMessage(JSON.stringify(dataToSend), "*"); x = parent.parent.postMessage(JSON.stringify(dataToSend), "*");
} }
} }
}catch (err) }catch (err)
{ {
parent.location = parent.location; parent.location = parent.location;
} }
</script>'); </script>');
} }
require_once 'classes/model/AppDelegation.php'; require_once 'classes/model/AppDelegation.php';
@@ -82,9 +82,9 @@ switch ($RBAC->userCanAccess( 'PM_CASES' )) {
die(); die();
break; break;
} }
if(array_key_exists('gmail',$_GET) && $_GET['gmail'] == 1){ if(array_key_exists('gmail',$_GET) && $_GET['gmail'] == 1){
$_SESSION['gmail'] = 1; $_SESSION['gmail'] = 1;
} }
if ((int) $_SESSION['INDEX'] < 1) { if ((int) $_SESSION['INDEX'] < 1) {
@@ -705,10 +705,10 @@ try {
if ($row['TU_RELATION'] == 1) { if ($row['TU_RELATION'] == 1) {
//users //users
$dataUser = $user->load($row['USR_UID']); $dataUser = $user->load($row['USR_UID']);
if (array_search($dataUser['USR_EMAIL'], $userPermission) == null) { if (array_search($dataUser['USR_EMAIL'], $userPermission) === false) {
$objectPermissions = $case->getAllObjects($row['PRO_UID'], $applicationUid, $objectPermissions = $case->getAllObjects($row['PRO_UID'], $applicationUid,
$row['TAS_UID'], $row['USR_UID']); $row['TAS_UID'], $row['USR_UID']);
if (array_search($appDocUid, $objectPermissions['OUTPUT_DOCUMENTS']) != null) { if (array_search($appDocUid, $objectPermissions['OUTPUT_DOCUMENTS']) !== false) {
$userPermission[] = $dataUser['USR_EMAIL']; $userPermission[] = $dataUser['USR_EMAIL'];
} }
} }
@@ -724,11 +724,11 @@ try {
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($oDataset->next()) { while ($oDataset->next()) {
$aRow = $oDataset->getRow(); $aRow = $oDataset->getRow();
if (array_search($aRow['USR_EMAIL'], $userPermission) == null) { if (array_search($aRow['USR_EMAIL'], $userPermission) === false) {
$objectPermissions = $case->getAllObjects($row['PRO_UID'], $applicationUid, $objectPermissions = $case->getAllObjects($row['PRO_UID'], $applicationUid,
$row['TAS_UID'], $aRow['USR_UID']); $row['TAS_UID'], $aRow['USR_UID']);
if (array_search($appDocUid, if (array_search($appDocUid,
$objectPermissions['OUTPUT_DOCUMENTS']) != null $objectPermissions['OUTPUT_DOCUMENTS']) !== false
) { ) {
$userPermission[] = $aRow['USR_EMAIL']; $userPermission[] = $aRow['USR_EMAIL'];
} }

View File

@@ -462,10 +462,10 @@ class OutputDocument
if ($row['TU_RELATION'] == 1) { if ($row['TU_RELATION'] == 1) {
//users //users
$dataUser = $user->load($row['USR_UID']); $dataUser = $user->load($row['USR_UID']);
if (array_search($dataUser['USR_EMAIL'], $userPermission) == null) { if (array_search($dataUser['USR_EMAIL'], $userPermission) === false) {
$objectPermissions = $case->getAllObjects($row['PRO_UID'], $applicationUid, $objectPermissions = $case->getAllObjects($row['PRO_UID'], $applicationUid,
$row['TAS_UID'], $row['USR_UID']); $row['TAS_UID'], $row['USR_UID']);
if (array_search($appDocUid, $objectPermissions['OUTPUT_DOCUMENTS']) != null) { if (array_search($appDocUid, $objectPermissions['OUTPUT_DOCUMENTS']) !== false) {
$userPermission[] = $dataUser['USR_EMAIL']; $userPermission[] = $dataUser['USR_EMAIL'];
} }
} }
@@ -482,10 +482,10 @@ class OutputDocument
while ( $oDataset->next()) { while ( $oDataset->next()) {
$aRow = $oDataset->getRow(); $aRow = $oDataset->getRow();
if (array_search($aRow['USR_EMAIL'], $userPermission) == null) { if (array_search($aRow['USR_EMAIL'], $userPermission) === false) {
$objectPermissions = $case->getAllObjects($row['PRO_UID'], $applicationUid, $objectPermissions = $case->getAllObjects($row['PRO_UID'], $applicationUid,
$row['TAS_UID'], $aRow['USR_UID']); $row['TAS_UID'], $aRow['USR_UID']);
if (array_search($appDocUid, $objectPermissions['OUTPUT_DOCUMENTS']) != null) { if (array_search($appDocUid, $objectPermissions['OUTPUT_DOCUMENTS']) !== false) {
$userPermission[] = $aRow['USR_EMAIL']; $userPermission[] = $aRow['USR_EMAIL'];
} }
} }

View File

@@ -360,7 +360,7 @@ var testSettings = function ()
url : '../pmGmail/testConfigPmGmail', url : '../pmGmail/testConfigPmGmail',
waitMsg : _('ID_TEST_CONNECTION'), waitMsg : _('ID_TEST_CONNECTION'),
waitTitle : "&nbsp;", waitTitle : "&nbsp;",
timeout : 36000, timeout : 60000,
success : function(obj, resp) { success : function(obj, resp) {
Ext.getCmp('testPMGmail').show(); Ext.getCmp('testPMGmail').show();
Ext.getCmp('listUsers').show(); Ext.getCmp('listUsers').show();
@@ -392,7 +392,7 @@ var saveSettings = function ()
url : '../pmGmail/saveConfigPmGmail', url : '../pmGmail/saveConfigPmGmail',
waitMsg : _('ID_SAVING_PROCESS'), waitMsg : _('ID_SAVING_PROCESS'),
waitTitle : "&nbsp;", waitTitle : "&nbsp;",
timeout : 36000, timeout : 60000,
success : function(obj, resp) { success : function(obj, resp) {
var response = Ext.decode(resp.response.responseText); var response = Ext.decode(resp.response.responseText);
parent.PMExt.notify(_('ID_INFO'),_('ID_SAVED_SUCCESSFULLY')); parent.PMExt.notify(_('ID_INFO'),_('ID_SAVED_SUCCESSFULLY'));