mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2024-11-22 18:09:06 +01:00
LSldapObject: clean updata/validate form data code to fix handling just check mode
This commit is contained in:
parent
e05f0df20d
commit
a25b1e8c10
1 changed files with 154 additions and 131 deletions
|
@ -292,7 +292,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
* _updateData() protected method.
|
||||
*
|
||||
* @param[in] $idForm Form ID
|
||||
* @param[in] $justValidate Boolean to enable just validation mode
|
||||
* @param[in] $justCheck Boolean to enable just check mode
|
||||
*
|
||||
* @see _updateData()
|
||||
*
|
||||
|
@ -300,7 +300,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
*
|
||||
* @retval boolean true if object data was updated, false otherwise
|
||||
*/
|
||||
public function updateData($idForm=NULL,$justValidate=False) {
|
||||
public function updateData($idForm=NULL, $justCheck=False) {
|
||||
if($idForm!=NULL) {
|
||||
if(isset($this -> forms[$idForm]))
|
||||
$LSform = $this -> forms[$idForm][0];
|
||||
|
@ -323,8 +323,8 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
}
|
||||
}
|
||||
$new_data = $LSform -> exportValues();
|
||||
self :: log_debug($this. "->updateData($idForm, $justValidate): new data=".varDump($new_data));
|
||||
return $this -> _updateData($new_data,$idForm,$justValidate);
|
||||
self :: log_debug($this. "->updateData($idForm, $justCheck): new data=".varDump($new_data));
|
||||
return $this -> _updateData($new_data, $idForm, $justCheck);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -335,7 +335,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
*
|
||||
* @param[in] $new_data Array of object data
|
||||
* @param[in] $idForm Form ID
|
||||
* @param[in] $justValidate Boolean to enable just validation mode
|
||||
* @param[in] $justCheck Boolean to enable just check mode
|
||||
*
|
||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||
*
|
||||
|
@ -345,7 +345,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
* @see validateAttrsData()
|
||||
* @see submitChange()
|
||||
*/
|
||||
protected function _updateData($new_data,$idForm=null,$justValidate=False) {
|
||||
protected function _updateData($new_data, $idForm=null, $justCheck=False) {
|
||||
if(!is_array($new_data)) {
|
||||
return;
|
||||
}
|
||||
|
@ -354,9 +354,9 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
$this -> attrs[$attr_name] -> setUpdateData($attr_val);
|
||||
}
|
||||
}
|
||||
if($this -> validateAttrsData($idForm)) {
|
||||
if($this -> validateAttrsData($idForm, $justCheck)) {
|
||||
self :: log_debug($this."->_updateData(): Update data are validated");
|
||||
if ($justValidate) {
|
||||
if ($justCheck) {
|
||||
self :: log_debug($this."->_updateData(): Just validate mode");
|
||||
return True;
|
||||
}
|
||||
|
@ -398,15 +398,16 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
}
|
||||
|
||||
/**
|
||||
* Valide les données retournées par un formulaire
|
||||
* Validate data returned by form
|
||||
*
|
||||
* @param[in] $idForm Identifiant du formulaire d'origine
|
||||
* @param[in] $idForm string The source LSform ID
|
||||
* @param[in] $justCheck Boolean to enable just check mode (do not validate data using LDAP search)
|
||||
*
|
||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||
*
|
||||
* @retval boolean true si les données sont valides, false sinon
|
||||
* @retval boolean True if form data are valid, False otherwise
|
||||
*/
|
||||
public function validateAttrsData($idForm=null) {
|
||||
public function validateAttrsData($idForm=null, $justCheck=False) {
|
||||
$retval = true;
|
||||
if ($idForm) {
|
||||
$LSform=$this -> forms[$idForm][0];
|
||||
|
@ -418,14 +419,14 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
$attr_values = $attr -> getValue();
|
||||
if (!$attr -> isValidate()) {
|
||||
if($attr -> isUpdate()) {
|
||||
if (!$this -> validateAttrData($LSform, $attr)) {
|
||||
if (!$this -> validateAttrData($LSform, $attr, $justCheck)) {
|
||||
$retval = false;
|
||||
}
|
||||
}
|
||||
else if( (empty($attr_values)) && ($attr -> isRequired()) ) {
|
||||
if ( $attr -> canBeGenerated()) {
|
||||
if ($attr -> generateValue()) {
|
||||
if (!$this -> validateAttrData($LSform, $attr)) {
|
||||
if (!$this -> validateAttrData($LSform, $attr, $justCheck)) {
|
||||
LSerror :: addErrorCode('LSattribute_08',$attr -> getLabel());
|
||||
$retval = false;
|
||||
}
|
||||
|
@ -450,23 +451,34 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
}
|
||||
|
||||
/**
|
||||
* Valide les données d'un attribut
|
||||
* Validate one attribute's data returned by form
|
||||
*
|
||||
* @param[in] $LSForm Formulaire d'origine
|
||||
* @param[in] &$attr Attribut à valider
|
||||
* @param[in] $idForm string The source LSform ID
|
||||
* @param[in] &$attr LSattribute The attribute to validate
|
||||
* @param[in] $justCheck Boolean to enable just check mode (do not validate data using LDAP search)
|
||||
*
|
||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||
*
|
||||
* @retval boolean true si les données sont valides, false sinon
|
||||
* @retval boolean True if form data for this attribute are valid, False otherwise
|
||||
*/
|
||||
public function validateAttrData(&$LSform,&$attr) {
|
||||
public function validateAttrData(&$LSform, &$attr, $justCheck=false) {
|
||||
$retval = true;
|
||||
|
||||
$vconfig = $attr -> getValidateConfig();
|
||||
|
||||
// Validate attribute values
|
||||
if ($justCheck) {
|
||||
self :: log_trace(
|
||||
"validateAttrData(".$LSform->idForm.", ".$attr->name."): ".
|
||||
"just check mode: do not validate attribute data using LDAP search"
|
||||
);
|
||||
}
|
||||
else {
|
||||
foreach($attr -> getConfig('validation', array(), 'array') as $test) {
|
||||
self :: log_trace("validateAttrData(".$LSform->idForm.", ".$attr->name."): run validation with following config:\n".varDump($test));
|
||||
self :: log_trace(
|
||||
"validateAttrData(".$LSform->idForm.", ".$attr->name."): ".
|
||||
"run validation with following config:\n".varDump($test)
|
||||
);
|
||||
|
||||
// Generate error message
|
||||
$msg_error = LSconfig :: get('msg', null, 'string', $test);
|
||||
|
@ -480,7 +492,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
// Iter on attribute values to check all of it
|
||||
foreach(ensureIsArray($attr -> getUpdateData()) as $val) {
|
||||
// Validation using LDAP search
|
||||
if((isset($test['filter'])||isset($test['basedn']))&&(isset($test['result']))) {
|
||||
if((isset($test['filter']) || isset($test['basedn'])) && isset($test['result'])) {
|
||||
$this -> other_values['val'] = $val;
|
||||
$sparams = array(
|
||||
'scope' => LSconfig :: get('scope', 'sub', 'string', $test),
|
||||
|
@ -492,7 +504,7 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
if ($sfilter_user) {
|
||||
$sfilter_user = $this -> getFData($test['filter']);
|
||||
// Check if filter format is surronded by '()'
|
||||
if ($sfilter_user[0]!='(')
|
||||
if ($sfilter_user[0] != '(')
|
||||
$sfilter_user = "($sfilter_user)";
|
||||
$sfilter_user = Net_LDAP2_Filter::parse($sfilter_user);
|
||||
}
|
||||
|
@ -514,7 +526,8 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
$sbasedn = $this -> getFData($sbasedn);
|
||||
|
||||
// If except_current_object (and not create form), list matching objets to exclude current one
|
||||
if (LSconfig :: get('except_current_object', false, 'bool', $test) && $LSform -> idForm != 'create') {
|
||||
if (LSconfig :: get('except_current_object', false, 'bool', $test) &&
|
||||
$LSform -> idForm != 'create') {
|
||||
$sret = LSldap :: search($sfilter, $sbasedn, $sparams);
|
||||
$dn = $this->getDn();
|
||||
$ret = 0;
|
||||
|
@ -588,23 +601,36 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate values of dependent attributes
|
||||
$dependsAttrs = $attr->getDependsAttrs();
|
||||
if (!empty($dependsAttrs)) {
|
||||
if (empty($dependsAttrs)) {
|
||||
self :: log_trace(
|
||||
"validateAttrData(".$LSform->idForm.", ".$attr->name."): ".
|
||||
"no dependent attribute"
|
||||
);
|
||||
}
|
||||
else {
|
||||
foreach($dependsAttrs as $dependAttr) {
|
||||
if(!isset($this -> attrs[$dependAttr])){
|
||||
LSerror :: addErrorCode('LSldapObject_14',array('attr_depend' => $dependAttr, 'attr' => $attr -> getLabel()));
|
||||
LSerror :: addErrorCode(
|
||||
'LSldapObject_14',
|
||||
array('attr_depend' => $dependAttr, 'attr' => $attr -> getLabel())
|
||||
);
|
||||
continue;
|
||||
}
|
||||
self :: log_debug('Attribute '.$attr->name.' updated: generate new value for attribute '.$dependAttr);
|
||||
self :: log_debug(
|
||||
"validateAttrData(".$LSform->idForm.", ".$attr->name."): ".
|
||||
'Attribute '.$attr->name.' updated: generate new value for attribute '.$dependAttr
|
||||
);
|
||||
if($this -> attrs[$dependAttr] -> canBeGenerated()) {
|
||||
if (!$this -> attrs[$dependAttr] -> generateValue()) {
|
||||
LSerror :: addErrorCode('LSattribute_07',$this -> attrs[$dependAttr] -> getLabel());
|
||||
LSerror :: addErrorCode('LSattribute_07', $this -> attrs[$dependAttr] -> getLabel());
|
||||
$retval = false;
|
||||
}
|
||||
elseif (!$this -> validateAttrData($LSform,$this -> attrs[$dependAttr])) {
|
||||
LSerror :: addErrorCode('LSattribute_08',$this -> attrs[$dependAttr] -> getLabel());
|
||||
elseif (!$this -> validateAttrData($LSform, $this -> attrs[$dependAttr], $justCheck)) {
|
||||
LSerror :: addErrorCode('LSattribute_08', $this -> attrs[$dependAttr] -> getLabel());
|
||||
$retval = false;
|
||||
}
|
||||
}
|
||||
|
@ -614,9 +640,6 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
self :: log_trace("validateAttrData(".$LSform->idForm.", ".$attr->name."): no dependent attribute");
|
||||
}
|
||||
|
||||
$attr -> validate();
|
||||
unset($this -> other_values['val']);
|
||||
|
@ -624,13 +647,13 @@ class LSldapObject extends LSlog_staticLoggerClass {
|
|||
}
|
||||
|
||||
/**
|
||||
* Met à jour les données modifiés dans l'annuaire
|
||||
* Submit changes made to LDAP directory
|
||||
*
|
||||
* @param[in] $idForm Identifiant du formulaire d'origine
|
||||
* @param[in] $idForm string The source LSform ID
|
||||
*
|
||||
* @author Benjamin Renard <brenard@easter-eggs.com>
|
||||
*
|
||||
* @retval boolean true si la mise à jour a réussi, false sinon
|
||||
* @retval boolean True if changes are successfully push to LDAP directory, False otherwise
|
||||
*/
|
||||
public function submitChange($idForm) {
|
||||
$submitData=array();
|
||||
|
|
Loading…
Reference in a new issue