This commit is contained in:
jonathan Quispe
2017-09-15 11:54:39 +00:00
committed by Paula Quispe
parent 94d9fb2b3d
commit 4a9c1b2d39
10 changed files with 340 additions and 181 deletions

View File

@@ -141,6 +141,7 @@ def generateEnviromentVariables()
file = File.read('./config/enviromentvariables.json')
dataUser = JSON.parse(file)
content = content + "__env.USER_GUEST = " + JSON.generate(dataUser['constants']['userguest'])
content = content + "; __env.pmVariable = " + JSON.generate(dataUser['validation']['pmVariable'])
dir = "vendor/colosa/MichelangeloFE/src/enviroment/"
# create a directory enviroment
FileUtils.mkdir_p(dir)

10
config/constants.php Normal file
View File

@@ -0,0 +1,10 @@
<?php
return [
'validation' => [
'pmVariable' => [
'regEx' => '/^[a-zA-Z\_]{1}\w+$/'
]
]
];

View File

@@ -8,5 +8,10 @@
"lastname": "Guest",
"username": "guest"
}
},
"validation": {
"pmVariable": {
"regEx": "/^[a-zA-Z\\_]{1}\\w+$/"
}
}
}

View File

@@ -471,6 +471,37 @@ gulp.task('clean', function () {
cleanDirectory('workflow/public_html/lib');
});
/**
* Exports from the config/constants.php the configuration constants to the
* enviromentvariables.json file
*/
gulp.task('exportBackendConstants', function () {
var runner = require('child_process');
gutil.log(gutil.colors.green('Export ProcessMaker constants...'));
var envVarsJsonFile = 'config/enviromentvariables.json';
var code = 'require_once "gulliver/system/class.g.php";' +
'require_once "bootstrap/autoload.php";' +
'require_once "bootstrap/app.php";' +
'app()->make(Illuminate\\Foundation\\Http\\Kernel::class)->bootstrap();' +
'print(json_encode(config("constants", JSON_UNESCAPED_SLASHES)));';
runner.exec(
'php -r \'' + code + '\'',
function (err, stdout, stderr) {
var pmConstants = JSON.parse(stdout);
var envVar = JSON.parse(fs.readFileSync(envVarsJsonFile));
for (var attr in pmConstants) {
envVar[attr] = pmConstants[attr];
}
fs.writeFileSync(envVarsJsonFile, JSON.stringify(envVar, null, 2));
return pmConstants;
});
});
/**
* This scheduled task is to be able to create the guest user constants
*/
@@ -490,7 +521,7 @@ gulp.task('__env', function (cb) {
);
});
gulp.task('default', ['clean', '__env'], function (cb) {
gulp.task('default', ['clean', 'exportBackendConstants', '__env'], function (cb) {
var i, tasks = [];
gutil.log(gutil.colors.green('Initializing ProcessMaker building...'));
@@ -499,4 +530,5 @@ gulp.task('default', ['clean', '__env'], function (cb) {
tasks.push(_.bind(processTask, config[i]));
}
executeSequence(tasks, cb);
});
});

View File

@@ -8945,6 +8945,12 @@ msgstr "No skins to display"
msgid "No users to display"
msgstr "No users to display"
# TRANSLATION
# LABEL/ID_GRID_VARIABLE_NAME_ERROR
#: LABEL/ID_GRID_VARIABLE_NAME_ERROR
msgid "A valid variable starts with a letter or underscore, followed by any number of letters, numbers, or underscores. Variables with wrong names: {0}"
msgstr "A valid variable starts with a letter or underscore, followed by any number of letters, numbers, or underscores. Variables with wrong names: {0}"
# TRANSLATION
# LABEL/ID_GRID_WIZARD
#: LABEL/ID_GRID_WIZARD
@@ -20675,6 +20681,12 @@ msgstr "File \"{0}\" imported but with errors:"
msgid "The following fields cannot be created because they contain the reserved words \"{0}\""
msgstr "The following fields cannot be created because they contain the reserved words \"{0}\""
# TRANSLATION
# LABEL/ID_PMTABLE_INVALID_FIELD_NAME_VARIABLE
#: LABEL/ID_PMTABLE_INVALID_FIELD_NAME_VARIABLE
msgid "There is a conflict with some field names: \"{0}\", please rename them avoiding the use of numbers and considering that underscores are ignored when validating unique field names."
msgstr "There is a conflict with some field names: \"{0}\", please rename them avoiding the use of numbers and considering that underscores are ignored when validating unique field names."
# TRANSLATION
# LABEL/ID_PMTABLE_INVALID_FILE
#: LABEL/ID_PMTABLE_INVALID_FILE

View File

@@ -58318,6 +58318,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_GRID_PAGE_NO_ROWS_MESSAGE','en','No rows to display','2014-01-15') ,
( 'LABEL','ID_GRID_PAGE_NO_SKIN_MESSAGE','en','No skins to display','2014-01-15') ,
( 'LABEL','ID_GRID_PAGE_NO_USERS_MESSAGE','en','No users to display','2014-01-15') ,
( 'LABEL','ID_GRID_VARIABLE_NAME_ERROR','en','A valid variable starts with a letter or underscore, followed by any number of letters, numbers, or underscores. Variables with wrong names: {0}','2017-11-16') ,
( 'LABEL','ID_GRID_WIZARD','en','ProcessMaker Grid Wizard','2014-01-15') ,
( 'LABEL','ID_GROUP','en','Group','2014-01-15') ,
( 'LABEL','ID_GROUPS','en','Groups','2014-01-15') ,
@@ -60295,6 +60296,7 @@ INSERT INTO TRANSLATION (TRN_CATEGORY,TRN_ID,TRN_LANG,TRN_VALUE,TRN_UPDATE_DATE
( 'LABEL','ID_PMTABLE_IMPORT_SUCCESS','en','File "{0}" imported successfully.','2014-01-15') ,
( 'LABEL','ID_PMTABLE_IMPORT_WITH_ERRORS','en','File "{0}" imported but with errors:','2016-02-18') ,
( 'LABEL','ID_PMTABLE_INVALID_FIELD_NAME','en','The following fields cannot be created because they contain the reserved words "{0}"','2014-10-21') ,
( 'LABEL','ID_PMTABLE_INVALID_FIELD_NAME_VARIABLE','en','There is a conflict with some field names: "{0}", please rename them avoiding the use of numbers and considering that underscores are ignored when validating unique field names.','2018-04-03') ,
( 'LABEL','ID_PMTABLE_INVALID_FILE','en','Invalid PM table(s) file, import aborted!','2014-01-15') ,
( 'LABEL','ID_PMTABLE_INVALID_NAME','en','Could not create the table with the name "{0}" because it is a reserved word.','2014-01-15') ,
( 'LABEL','ID_PMTABLE_NOT_FOUND','en','The PM Table associated with this DynaForm could not be found.','2014-11-12') ,

View File

@@ -2,7 +2,11 @@
namespace ProcessMaker\BusinessModel;
use AdditionalTables;
use DynaformHandler;
use Exception;
use G;
use PmDynaform;
class DynaForm
{
@@ -407,6 +411,8 @@ class DynaForm
$this->throwExceptionIfExistsTitle($processUid, $arrayData["DYN_TITLE"], $this->arrayFieldNameForException["dynaFormTitle"]);
$this->throwExceptionIfTheColumnIdentifierIsNotValid($arrayData);
//Create
$dynaForm = new \Dynaform();
@@ -461,6 +467,8 @@ class DynaForm
$this->throwExceptionIfExistsTitle($processUid, $arrayData["DYN_TITLE"], $this->arrayFieldNameForException["dynaFormTitle"], $dynaFormUid);
}
$this->throwExceptionIfTheColumnIdentifierIsNotValid($arrayData);
//Update
$arrayData["DYN_UID"] = $dynaFormUid;
@@ -1131,4 +1139,74 @@ class DynaForm
throw $e;
}
}
/**
* Validates if the grid columns tha will be stored have valid names, otherwise
* it throws an exception.
*
* @param array $arrayData, form data that will be saved
*
* @throws Exception
*/
public function throwExceptionIfTheColumnIdentifierIsNotValid($arrayData)
{
if (isset($arrayData['DYN_CONTENT'])) {
$oldDynaform = $this->getDynaFormRecordByPk($arrayData['DYN_UID'], []);
$oldGrids = PmDynaform::getGridsAndFields($oldDynaform['DYN_CONTENT']);
$oldColumns = $this->getColumnsOfArrayGrids($oldGrids);
$grids = PmDynaform::getGridsAndFields($arrayData['DYN_CONTENT']);
$columns = $this->getColumnsOfArrayGrids($grids);
foreach ($oldColumns as $oldField) {
foreach ($columns as $key => $field) {
if ($oldField->id === $field->id) {
unset($columns[$key]);
break;
}
}
}
$invalids = [];
$identicals = [];
foreach ($columns as $column) {
try {
Validator::isValidVariableName($column->id);
} catch (Exception $e) {
$invalids[] = $column->id;
}
foreach ($oldColumns as $oldColumn) {
if (strtolower(AdditionalTables::getPHPName($column->id)) === strtolower(AdditionalTables::getPHPName($oldColumn->id))) {
$identicals[] = "'" . $column->id . "' - '" . $oldColumn->id . "'";
}
}
}
if (count($invalids) > 0) {
throw (new Exception(G::LoadTranslation("ID_GRID_VARIABLE_NAME_ERROR", [implode(', ', $invalids)])));
}
if (count($identicals) > 0) {
throw (new Exception(G::LoadTranslation("DYNAFIELD_PHPNAME_ALREADY_EXIST", [implode(', ', $identicals)])));
}
}
}
/**
* Gets a list of all columns of the grid array.
*
* @param array $grids
*
* @return array
*/
private function getColumnsOfArrayGrids($grids)
{
$columns = [];
foreach ($grids as $grid) {
if (isset($grid->columns)) {
$columns = array_merge($columns, $grid->columns);
}
}
return $columns;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -405,6 +405,7 @@ class Variable
if (isset($aData["VAR_NAME"])) {
Validator::isString($aData['VAR_NAME'], '$var_name');
Validator::isNotEmpty($aData['VAR_NAME'], '$var_name');
Validator::isValidVariableName($aData['VAR_NAME']);
}
if (isset($aData["VAR_FIELD_TYPE"])) {
Validator::isString($aData['VAR_FIELD_TYPE'], '$var_field_type');
@@ -462,7 +463,7 @@ class Variable
if ($variableName === $row["VAR_NAME"]) {
throw new Exception(G::LoadTranslation("DYNAFIELD_ALREADY_EXIST"));
}
if (AdditionalTables::getPHPName($variableName) === AdditionalTables::getPHPName($row["VAR_NAME"])) {
if (strtolower(AdditionalTables::getPHPName($variableName)) === strtolower(AdditionalTables::getPHPName($row["VAR_NAME"]))) {
throw new Exception(G::LoadTranslation("DYNAFIELD_PHPNAME_ALREADY_EXIST", array($row["VAR_NAME"])));
}
}