From 3c7ec2890ab7052acde5f8672ee641194981d90e Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 30 Jun 2021 18:11:26 +0200 Subject: [PATCH] API / Show an object: make API return all accessible attribute The method now return all accessible attributes and not only thow who are configured to be displayed in view --- src/includes/class/class.LSattribute.php | 6 ++++-- src/includes/class/class.LSldapObject.php | 16 +++++++--------- src/includes/routes.php | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/includes/class/class.LSattribute.php b/src/includes/class/class.LSattribute.php index 82c716a9..85b0fa68 100644 --- a/src/includes/class/class.LSattribute.php +++ b/src/includes/class/class.LSattribute.php @@ -315,11 +315,13 @@ class LSattribute extends LSlog_staticLoggerClass { * @author Benjamin Renard * * @param[in] $form LSform The LSform object + * @param[in] $api_mode boolean True if it's a view in API mode (=all accessible attributes present, + * optional, default: false) * * @retval boolean True on succes, False otherwise */ - public function addToView(&$form) { - if (!$this -> getConfig('view', false, 'bool') || ($this -> myRights() == 'n') ) + public function addToView(&$form, $api_mode=false) { + if ((!$api_mode && !$this -> getConfig('view', false, 'bool')) || ($this -> myRights() == 'n') ) return true; $element = $this -> _addToForm($form, 'view'); if ($element) { diff --git a/src/includes/class/class.LSldapObject.php b/src/includes/class/class.LSldapObject.php index 6ed56c00..f2ae9627 100644 --- a/src/includes/class/class.LSldapObject.php +++ b/src/includes/class/class.LSldapObject.php @@ -242,23 +242,21 @@ class LSldapObject extends LSlog_staticLoggerClass { } /** - * Construit un formulaire de l'objet + * Constuct a view for this object * - * Cette méthode construit un formulaire LSform à partir de la configuration de l'objet - * et de chaque attribut. + * This method create a LSform in view mode from the object and its attributes configurations. * - * @param[in] $idForm [required] Identifiant du formulaire a créer - * @param[in] $config Configuration spécifique pour le formulaire + * @param[in] $api_mode boolean Enable API mode (defaut: false) * * @author Benjamin Renard * - * @retval LSform Le formulaire crée + * @retval LSform The created LSform object */ - public function getView() { + public function getView($api_mode=false) { LSsession :: loadLSclass('LSform'); - $this -> view = new LSform($this,'view'); + $this -> view = new LSform($this, 'view', null, $api_mode); foreach($this -> attrs as $attr_name => $attr) { - $this -> attrs[$attr_name] -> addToView($this -> view); + $this -> attrs[$attr_name] -> addToView($this -> view, $api_mode); } $this -> view -> can_validate = false; return $this -> view; diff --git a/src/includes/routes.php b/src/includes/routes.php index 384accfe..f3576f74 100644 --- a/src/includes/routes.php +++ b/src/includes/routes.php @@ -1845,7 +1845,7 @@ function handle_api_LSobject_show($request) { 'relations' => array(), ); - $view = $object -> getView(); + $view = $object -> getView(true); // get view in API foreach($view -> elements as $element) { $data['attributes'][$element -> name] = $element -> getApiValue($data['details']); }