mirror of
https://gitlab.easter-eggs.com/ee/ldapsaisie.git
synced 2025-04-01 17:31:35 +02:00
LSrelation: check relation is correctly configured before using it
To avoid some unreal warnings in case of misconfigured relation
This commit is contained in:
parent
88d8d7f026
commit
14bccc1e17
2 changed files with 46 additions and 6 deletions
src/includes
|
@ -71,6 +71,9 @@ class LSrelation extends LSlog_staticLoggerClass {
|
||||||
* @retval mixed The configuration parameter value or default value if not set
|
* @retval mixed The configuration parameter value or default value if not set
|
||||||
**/
|
**/
|
||||||
public function getConfig($param, $default=null, $cast=null) {
|
public function getConfig($param, $default=null, $cast=null) {
|
||||||
|
// Check relation is correctly configured
|
||||||
|
if (!$this -> correctly_configured)
|
||||||
|
return false;
|
||||||
return LSconfig :: get($param, $default, $cast, $this -> config);
|
return LSconfig :: get($param, $default, $cast, $this -> config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +88,8 @@ class LSrelation extends LSlog_staticLoggerClass {
|
||||||
switch ($key) {
|
switch ($key) {
|
||||||
case 'name':
|
case 'name':
|
||||||
return $this -> name;
|
return $this -> name;
|
||||||
|
case 'correctly_configured':
|
||||||
|
return boolval($this -> config);
|
||||||
case 'LSobject':
|
case 'LSobject':
|
||||||
case 'linkAttribute':
|
case 'linkAttribute':
|
||||||
case 'linkAttributeValue':
|
case 'linkAttributeValue':
|
||||||
|
@ -257,6 +262,10 @@ class LSrelation extends LSlog_staticLoggerClass {
|
||||||
* @retval array|false An array of related objects (LSldapObject), of false in case of error
|
* @retval array|false An array of related objects (LSldapObject), of false in case of error
|
||||||
*/
|
*/
|
||||||
public function listRelatedObjects() {
|
public function listRelatedObjects() {
|
||||||
|
// Check relation is correctly configured
|
||||||
|
if (!$this -> correctly_configured)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Load related object type
|
// Load related object type
|
||||||
if (!LSsession :: loadLSobject($this -> LSobject)) {
|
if (!LSsession :: loadLSobject($this -> LSobject)) {
|
||||||
LSerror :: addErrorCode(
|
LSerror :: addErrorCode(
|
||||||
|
@ -320,6 +329,10 @@ class LSrelation extends LSlog_staticLoggerClass {
|
||||||
* @retval array List of value of the link attribute
|
* @retval array List of value of the link attribute
|
||||||
*/
|
*/
|
||||||
public function getRelatedKeyValue() {
|
public function getRelatedKeyValue() {
|
||||||
|
// Check relation is correctly configured
|
||||||
|
if (!$this -> correctly_configured)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Load related object type
|
// Load related object type
|
||||||
if (!LSsession :: loadLSobject($this -> LSobject)) {
|
if (!LSsession :: loadLSobject($this -> LSobject)) {
|
||||||
LSerror :: addErrorCode(
|
LSerror :: addErrorCode(
|
||||||
|
@ -384,6 +397,10 @@ class LSrelation extends LSlog_staticLoggerClass {
|
||||||
* @retval boolean True if user can edit the relation with the specified object, false otherwise
|
* @retval boolean True if user can edit the relation with the specified object, false otherwise
|
||||||
*/
|
*/
|
||||||
public function canEditRelationWithObject(&$objRel) {
|
public function canEditRelationWithObject(&$objRel) {
|
||||||
|
// Check relation is correctly configured
|
||||||
|
if (!$this -> correctly_configured)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (!$this -> canEdit()) return;
|
if (!$this -> canEdit()) return;
|
||||||
|
|
||||||
// Use canEdit_function
|
// Use canEdit_function
|
||||||
|
@ -432,6 +449,10 @@ class LSrelation extends LSlog_staticLoggerClass {
|
||||||
* @retval boolean True if relation removed, false otherwise
|
* @retval boolean True if relation removed, false otherwise
|
||||||
*/
|
*/
|
||||||
public function removeRelationWithObject(&$objRel) {
|
public function removeRelationWithObject(&$objRel) {
|
||||||
|
// Check relation is correctly configured
|
||||||
|
if (!$this -> correctly_configured)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Use remove_function
|
// Use remove_function
|
||||||
if ($this -> remove_function) {
|
if ($this -> remove_function) {
|
||||||
if (method_exists($this -> LSobject, $this -> remove_function)) {
|
if (method_exists($this -> LSobject, $this -> remove_function)) {
|
||||||
|
@ -478,6 +499,10 @@ class LSrelation extends LSlog_staticLoggerClass {
|
||||||
* @retval boolean True if relation rename, false otherwise
|
* @retval boolean True if relation rename, false otherwise
|
||||||
*/
|
*/
|
||||||
public function renameRelationWithObject(&$objRel, $oldKeyValue) {
|
public function renameRelationWithObject(&$objRel, $oldKeyValue) {
|
||||||
|
// Check relation is correctly configured
|
||||||
|
if (!$this -> correctly_configured)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Use rename_function
|
// Use rename_function
|
||||||
if ($this -> rename_function) {
|
if ($this -> rename_function) {
|
||||||
if (method_exists($objRel,$this -> rename_function)) {
|
if (method_exists($objRel,$this -> rename_function)) {
|
||||||
|
@ -526,6 +551,10 @@ class LSrelation extends LSlog_staticLoggerClass {
|
||||||
* @retval boolean True if relations updated, false otherwise
|
* @retval boolean True if relations updated, false otherwise
|
||||||
*/
|
*/
|
||||||
public function updateRelations($listDns) {
|
public function updateRelations($listDns) {
|
||||||
|
// Check relation is correctly configured
|
||||||
|
if (!$this -> correctly_configured)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Load related objects type
|
// Load related objects type
|
||||||
if (!LSsession :: loadLSobject($this -> LSobject)) {
|
if (!LSsession :: loadLSobject($this -> LSobject)) {
|
||||||
LSerror :: addErrorCode(
|
LSerror :: addErrorCode(
|
||||||
|
@ -653,6 +682,8 @@ class LSrelation extends LSlog_staticLoggerClass {
|
||||||
'objectDn' => $object -> getDn(),
|
'objectDn' => $object -> getDn(),
|
||||||
);
|
);
|
||||||
$relation = new LSrelation($object, $relationName);
|
$relation = new LSrelation($object, $relationName);
|
||||||
|
if (!$relation -> correctly_configured)
|
||||||
|
continue;
|
||||||
|
|
||||||
if ($relation -> canEdit()) {
|
if ($relation -> canEdit()) {
|
||||||
$return['actions'][] = array(
|
$return['actions'][] = array(
|
||||||
|
@ -761,6 +792,10 @@ class LSrelation extends LSlog_staticLoggerClass {
|
||||||
// Instanciate relation
|
// Instanciate relation
|
||||||
$relation = new LSrelation($object, $conf['relationName']);
|
$relation = new LSrelation($object, $conf['relationName']);
|
||||||
|
|
||||||
|
// Check relation is correctly configured
|
||||||
|
if (!$relation -> correctly_configured)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Check user access to it relation
|
// Check user access to it relation
|
||||||
if (!$relation -> canEdit()) {
|
if (!$relation -> canEdit()) {
|
||||||
LSerror :: addErrorCode('LSsession_11');
|
LSerror :: addErrorCode('LSsession_11');
|
||||||
|
|
|
@ -855,14 +855,19 @@ function handle_LSobject_create($request) {
|
||||||
if ($obj -> loadData(urldecode($_GET['relatedLSobjectDN']))) {
|
if ($obj -> loadData(urldecode($_GET['relatedLSobjectDN']))) {
|
||||||
if (LSrelation :: exists($_GET['relatedLSobject'], $_GET['LSrelation'])) {
|
if (LSrelation :: exists($_GET['relatedLSobject'], $_GET['LSrelation'])) {
|
||||||
$relation = new LSrelation($obj, $_GET['LSrelation']);
|
$relation = new LSrelation($obj, $_GET['LSrelation']);
|
||||||
$attr = $relation -> relatedEditableAttribute;
|
if ($relation -> correctly_configured) {
|
||||||
if (isset($object -> attrs[$attr])) {
|
$attr = $relation -> relatedEditableAttribute;
|
||||||
$value = $relation -> getRelatedKeyValue();
|
if (isset($object -> attrs[$attr])) {
|
||||||
if (is_array($value)) $value=$value[0];
|
$value = $relation -> getRelatedKeyValue();
|
||||||
$object -> attrs[$attr] -> data = array($value);
|
if (is_array($value)) $value=$value[0];
|
||||||
|
$object -> attrs[$attr] -> data = array($value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LSerror :: addErrorCode('LSrelation_06',array('relation' => $relation -> getName(),'LSobject' => $obj -> getType()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LSerror :: addErrorCode('LSrelation_06',array('relation' => $relation -> getName(),'LSobject' => $obj -> getType()));
|
LSlog :: warning("Relation '".$_GET['LSrelation']."' of object type '".$_GET['relatedLSobject']."' is not correctly configured.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue