diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index b06f7c261..3e889b8b1 100755 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -5169,7 +5169,7 @@ function getDirectorySize($path,$maxmtime=0) * * @author Erik Amaru Ortiz */ - public function dispatchRestService($uri) + public function dispatchRestService($uri, $config = array()) { require_once 'restler/restler.php'; @@ -5177,9 +5177,9 @@ function getDirectorySize($path,$maxmtime=0) $rest->setSupportedFormats('JsonFormat', 'XmlFormat'); // getting all services class - $srvClasses = glob(PATH_SERVICES_REST . '*.php'); + $srvClasses = glob(PATH_SERVICES_REST . '*.php'); $crudClasses = glob(PATH_SERVICES_REST . 'crud/*.php'); - $srvClasses = array_merge($srvClasses, $crudClasses); + $srvClasses = array_merge($srvClasses, $crudClasses); // hook to get rest api classes from plugins if ( class_exists( 'PMPluginRegistry' ) ) { @@ -5219,22 +5219,44 @@ function getDirectorySize($path,$maxmtime=0) // resolving the class for current request $uriPart = explode('/', $uri); $requestedClass = ''; + if (isset($uriPart[1])) { $requestedClass = ucfirst($uriPart[1]); } - if (class_exists('Services_Rest_' . $requestedClass)) { $namespace = 'Services_Rest_'; } elseif (class_exists('Plugin_Services_Rest_' . $requestedClass)) { $namespace = 'Plugin_Services_Rest_'; } else { - $namespace = ''; + $namespace = ''; } // end resolv. + // Send additional headers (if exists) configured on rest-config.ini + if (array_key_exists('HEADERS', $config)) { + foreach ($config['HEADERS'] as $name => $value) { + header("$name: $value"); + } + } + + // to handle a request with "OPTIONS" method + if (! empty($namespace) && $_SERVER['REQUEST_METHOD'] === 'OPTIONS') { + $reflClass = new ReflectionClass($namespace . $requestedClass); + + // if the rest class has not a "options" method + if (! $reflClass->hasMethod('options')) { + header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS, HEADERS'); + header('Access-Control-Allow-Headers: authorization, content-type'); + header("Access-Control-Allow-Credentials", "false"); + header('Access-Control-Max-Age: 60'); + exit(); + } + } + // override global REQUEST_URI to pass to Restler library $_SERVER['REQUEST_URI'] = '/' . strtolower($namespace) . ltrim($uri, '/'); + // handle the rest request $rest->handle(); } } diff --git a/workflow/engine/bin/rest-gen b/workflow/engine/bin/rest-gen index efa8abee5..aa2135bc2 100755 --- a/workflow/engine/bin/rest-gen +++ b/workflow/engine/bin/rest-gen @@ -9,63 +9,91 @@ * @author Erik Amaru Ortiz */ -include dirname(__FILE__) . '/../../../gulliver/core/Bootstrap.php'; -include dirname(__FILE__) . '/../../../workflow/engine/PmBootstrap.php'; +$basePath = realpath(dirname(__FILE__) . '/../../../'); +include $basePath . '/gulliver/core/Bootstrap.php'; +include $basePath . '/workflow/engine/PmBootstrap.php'; -$config = array( - 'path_trunk' => realpath(dirname(__FILE__) . '/../../../') -); - -$bootstrap = new PmBootstrap($config); +$bootstrap = new PmBootstrap(array('path_trunk' => $basePath)); $bootstrap->registerClasses(); $bootstrap->configure(); if (! isset($argv[1])) { - $help = '$>' . $argv[0] . " [option] [plugin-name]\n"; - $help .= "Avalaibles options:\n"; - $help .= " build-api : Build Crud Rest API from ProcessMaker or a plugin.\n"; - $help .= " gen-ini : Generates the rest config ini file.\n"; - $help .= "* [plugin-name] : (Optional) to specify create crud api for a determiated plugin.\n\n"; + $help = <<] [-w ] + +Options: + build-crud : Task, build Rest Crud API. + gen-ini : Task, generates the rest config ini file. + -p : Especify a plugin to set as enviroment to perform the tasks. + -w : Especify a workspace to set as enviroment to perform the tasks. + +EOT; echo $help; exit(0); } $restTool = new Service_Rest_RestTool(); +$restTool->setBasePath(PATH_CORE); try { switch ($argv[1]) { - case 'build-api': - if (isset($argv[2])) { - // attemp create rest api from a plugin - if (! is_dir(PATH_PLUGINS . $argv[2])) { - throw new Exception(sprintf("Plugin '%s' doesn't exist.", $argv[2])); - } - - $restTool->setBasePath(PATH_PLUGINS . $argv[2] . PATH_SEP); - } - - $restTool->buildApi(); - break; - + case 'build-crud': case 'gen-ini': - if (file_exists(PATH_CONFIG . '/rest-config.ini')) { - echo "The file 'rest-config.ini' already exits, overwrite (Y/n)? "; - $resp = trim(fgets(STDIN)); + if (isset($argv[2])) { + if (! isset($argv[3])) { + throw new Exception("Missing option, need especify a valid argument after option '{$argv[2]}'"); + } - if (strtolower($resp) != 'y') { - echo "Skipped\n"; - exit(0); + switch ($argv[2]) { + case '-p': + // attempt create rest api from a plugin + if (! is_dir(PATH_PLUGINS . $argv[3])) { + throw new Exception(sprintf("Plugin '%s' doesn't exist.", $argv[3])); + } + + $restTool->setBasePath($optPath = PATH_PLUGINS . $argv[3] . PATH_SEP); + break; + + case '-w': + // attempt create rest api from a plugin + if (! is_dir(PATH_DATA . 'sites' . PATH_SEP . $argv[3])) { + throw new Exception(sprintf("Workspace '%s' doesn't exist.", $argv[3])); + } + + $path = PATH_DATA . 'sites' . PATH_SEP . $argv[3] . PATH_SEP; + $restTool->setBasePath($path); + $restTool->setConfigFile($path . 'rest-config.ini'); + $restTool->setDbXmlSchemaFile(PATH_CONFIG . 'schema.xml'); + break; + + default: + throw new Exception(sprintf("Invalid option '%s'", $argv[2])); } } - echo "Generating config ini file ... "; + $restTool->init(); - $genFile = $restTool->buildConfigIni(); + if ($argv[1] == 'build-crud') { + $restTool->buildCrudApi(); + } else { + if (file_exists(PATH_CONFIG . '/rest-config.ini')) { + echo "The file 'rest-config.ini' already exits, overwrite (Y/n)? "; + $resp = trim(fgets(STDIN)); - echo "DONE!\n"; - echo "File generated: $genFile\n\n"; + if (strtolower($resp) != 'y') { + echo "Skipped\n"; + exit(0); + } + } + echo "Generating config ini file ... "; + + $genFile = $restTool->buildConfigIni(); + + echo "DONE!\n"; + echo "File generated: $genFile\n\n"; + } break; default: @@ -73,5 +101,5 @@ try { break; } } catch (Exception $e) { - echo $e->getMessage() . "\n"; + Service_Rest_RestTool::out($e->getMessage(), 'error'); } diff --git a/workflow/engine/classes/class.processMap.php b/workflow/engine/classes/class.processMap.php index 9474b5ab4..1e69195ad 100755 --- a/workflow/engine/classes/class.processMap.php +++ b/workflow/engine/classes/class.processMap.php @@ -3551,29 +3551,39 @@ class processMap { * @return boolean true */ function newObjectPermission($sProcessUID) { - $aUsersGroups = array(); - $aUsersGroups [] = array('UID' => 'char', 'LABEL' => 'char'); + $usersGroups = ''; $aAllObjects = array(); $aAllObjects [] = array('UID' => 'char', 'LABEL' => 'char'); $aAllDynaforms = array(); @@ -3617,7 +3627,6 @@ class processMap { } global $_DBArray; $_DBArray = (isset($_SESSION ['_DBArray']) ? $_SESSION ['_DBArray'] : ''); - $_DBArray ['usersGroups'] = $aUsersGroups; $_DBArray ['allObjects'] = $aAllObjects; $_DBArray ['allDynaforms'] = $aAllDynaforms; $_DBArray ['allInputs'] = $aAllInputs; @@ -3625,7 +3634,7 @@ class processMap { $_SESSION ['_DBArray'] = $_DBArray; global $G_PUBLISH; $G_PUBLISH = new Publisher ( ); - $G_PUBLISH->AddContent('xmlform', 'xmlform', 'processes/processes_NewObjectPermission', '', array('LANG' => SYS_LANG, 'PRO_UID' => $sProcessUID, 'ID_DELETE' => G::LoadTranslation('ID_DELETE')), 'processes_SaveObjectPermission'); + $G_PUBLISH->AddContent('xmlform', 'xmlform', 'processes/processes_NewObjectPermission', '', array('GROUP_USER' => $usersGroups, 'LANG' => SYS_LANG, 'PRO_UID' => $sProcessUID, 'ID_DELETE' => G::LoadTranslation('ID_DELETE')), 'processes_SaveObjectPermission'); G::RenderPage('publish', 'raw'); return true; } @@ -3661,7 +3670,6 @@ class processMap { $aFields ['PRO_UID'] = $aRows ['PRO_UID']; $aFields ['OP_CASE_STATUS'] = $aRows ['OP_CASE_STATUS']; $aFields ['TAS_UID'] = $aRows ['TAS_UID']; - $aFields ['GROUP_USER'] = $user; $aFields ['OP_TASK_SOURCE'] = $aRows ['OP_TASK_SOURCE']; $aFields ['OP_PARTICIPATE'] = $aRows ['OP_PARTICIPATE']; $aFields ['OP_OBJ_TYPE'] = $aRows ['OP_OBJ_TYPE']; @@ -3682,8 +3690,7 @@ class processMap { break; } - $aUsersGroups = array(); - $aUsersGroups [] = array('UID' => 'char', 'LABEL' => 'char'); + $usersGroups = ' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{$form.TITLE}
{$form.PRO_UID}
{$form.OP_UID}
{$OP_CASE_STATUS}{$form.OP_CASE_STATUS}
{$TAS_UID}{$form.TAS_UID}
{$GROUP_USER}{$form.GROUP_USER_DROPDOWN}
{$OP_TASK_SOURCE}{$form.OP_TASK_SOURCE}
{$OP_PARTICIPATE}{$form.OP_PARTICIPATE}
{$OP_OBJ_TYPE}{$form.OP_OBJ_TYPE}
{$ALL}{$form.ALL}
{$DYNAFORMS}{$form.DYNAFORMS}
{$INPUTS}{$form.INPUTS}
{$OUTPUTS}{$form.OUTPUTS}
{$OP_ACTION}{$form.OP_ACTION}
{$form.CREATE}
+ + + + +
+ + + \ No newline at end of file diff --git a/workflow/engine/xmlform/processes/processes_EditObjectPermission.xml b/workflow/engine/xmlform/processes/processes_EditObjectPermission.xml index 51636b081..ce37257b1 100755 --- a/workflow/engine/xmlform/processes/processes_EditObjectPermission.xml +++ b/workflow/engine/xmlform/processes/processes_EditObjectPermission.xml @@ -1,8 +1,8 @@ - + <en>Edit Specific Permission</en> -<es><![CDATA[Nuevo permiso especĂ­fico]]></es> + @@ -13,109 +13,201 @@ - - Estado del Caso - - + + -Target Task + + + Target Task + + - -SELECT * FROM usersGroups + Group or User -Origin Task + + + + Origin Task Participation required? - Type - - - - + + + + + -SELECT * FROM allObjects - Object + SELECT * FROM allObjects + Object + + -SELECT * FROM allDynaforms + SELECT * FROM allDynaforms DynaForm -SELECT * FROM allInputs + SELECT * FROM allInputs Input Document -SELECT * FROM allOutputs + SELECT * FROM allOutputs Output Document - Permission + Permission + Save +
@@ -17,57 +17,57 @@ {$OP_CASE_STATUS} - {$form.OP_CASE_STATUS} + {$form.OP_CASE_STATUS} {$TAS_UID} - {$form.TAS_UID} + {$form.TAS_UID} {$GROUP_USER} - {$form.GROUP_USER} + {$form.GROUP_USER_DROPDOWN} {$OP_TASK_SOURCE} - {$form.OP_TASK_SOURCE} + {$form.OP_TASK_SOURCE} {$OP_PARTICIPATE} - {$form.OP_PARTICIPATE} + {$form.OP_PARTICIPATE} {$OP_OBJ_TYPE} - {$form.OP_OBJ_TYPE} + {$form.OP_OBJ_TYPE} {$ALL} - {$form.ALL} + {$form.ALL} {$DYNAFORMS} - {$form.DYNAFORMS} + {$form.DYNAFORMS} {$INPUTS} - {$form.INPUTS} + {$form.INPUTS} {$OUTPUTS} - {$form.OUTPUTS} + {$form.OUTPUTS} {$OP_ACTION} - {$form.OP_ACTION} + {$form.OP_ACTION}
{$form.CREATE}   {$form.BTN_CANCEL} @@ -82,4 +82,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/workflow/engine/xmlform/processes/processes_NewObjectPermission.xml b/workflow/engine/xmlform/processes/processes_NewObjectPermission.xml index 03aa118bf..785ef8ae9 100755 --- a/workflow/engine/xmlform/processes/processes_NewObjectPermission.xml +++ b/workflow/engine/xmlform/processes/processes_NewObjectPermission.xml @@ -6,12 +6,14 @@ + - Status Case - - - - + Status Case + + + + + @@ -21,11 +23,13 @@ - - SELECT * FROM usersGroups + + Group or User + + Origin Task @@ -69,7 +73,7 @@ Create -CreateCriar + - \ No newline at end of file + \ No newline at end of file diff --git a/workflow/public_html/sysGeneric.php b/workflow/public_html/sysGeneric.php index 0666a2fd4..055b0f5dc 100755 --- a/workflow/public_html/sysGeneric.php +++ b/workflow/public_html/sysGeneric.php @@ -423,6 +423,28 @@ define('SERVER_NAME', $_SERVER ['SERVER_NAME']); define('SERVER_PORT', $_SERVER ['SERVER_PORT']); + // verify configuration for rest service + if ($isRestRequest) { + // disable until confirm that rest is enabled & configured on rest-config.ini file + $isRestRequest = false; + $confFile = ''; + + // try load and getting rest configuration + if (file_exists(PATH_DATA_SITE . 'rest-config.ini')) { + $confFile = PATH_DATA_SITE . 'rest-config.ini'; + } elseif (file_exists(PATH_CONFIG . 'rest-config.ini')) { + $confFile = PATH_CONFIG . 'rest-config.ini'; + } + + if (! empty($confFile) && $restConfig = @parse_ini_file($confFile, true)) { + if (array_key_exists('enable_service', $restConfig)) { + if ($restConfig['enable_service'] == 'true' || $restConfig['enable_service'] == '1') { + $isRestRequest = true; // rest service enabled + } + } + } + } + // load Plugins base class G::LoadClass('plugin'); @@ -575,10 +597,6 @@ $isControllerCall = true; } } - // var_dump(SYS_SYS); - // var_dump(SYS_TARGET); - // var_dump($isRestRequest); - // die; if (!$isControllerCall && ! file_exists($phpFile) && ! $isRestRequest) { $_SESSION['phpFileNotFound'] = $_SERVER['REQUEST_URI']; @@ -707,7 +725,7 @@ $controller->setHttpRequestData($_REQUEST); $controller->call($controllerAction); } elseif ($isRestRequest) { - G::dispatchRestService(SYS_TARGET); + G::dispatchRestService(SYS_TARGET, $restConfig); } else { require_once $phpFile; }