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
This commit is contained in:
Benjamin Renard 2021-06-30 18:11:26 +02:00
parent 6bc1e46afb
commit 3c7ec2890a
3 changed files with 12 additions and 12 deletions

View file

@ -315,11 +315,13 @@ class LSattribute extends LSlog_staticLoggerClass {
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
* *
* @param[in] $form LSform The LSform object * @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 * @retval boolean True on succes, False otherwise
*/ */
public function addToView(&$form) { public function addToView(&$form, $api_mode=false) {
if (!$this -> getConfig('view', false, 'bool') || ($this -> myRights() == 'n') ) if ((!$api_mode && !$this -> getConfig('view', false, 'bool')) || ($this -> myRights() == 'n') )
return true; return true;
$element = $this -> _addToForm($form, 'view'); $element = $this -> _addToForm($form, 'view');
if ($element) { if ($element) {

View file

@ -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 * This method create a LSform in view mode from the object and its attributes configurations.
* et de chaque attribut.
* *
* @param[in] $idForm [<b>required</b>] Identifiant du formulaire a créer * @param[in] $api_mode boolean Enable API mode (defaut: false)
* @param[in] $config Configuration spécifique pour le formulaire
* *
* @author Benjamin Renard <brenard@easter-eggs.com> * @author Benjamin Renard <brenard@easter-eggs.com>
* *
* @retval LSform Le formulaire crée * @retval LSform The created LSform object
*/ */
public function getView() { public function getView($api_mode=false) {
LSsession :: loadLSclass('LSform'); 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) { 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; $this -> view -> can_validate = false;
return $this -> view; return $this -> view;

View file

@ -1845,7 +1845,7 @@ function handle_api_LSobject_show($request) {
'relations' => array(), 'relations' => array(),
); );
$view = $object -> getView(); $view = $object -> getView(true); // get view in API
foreach($view -> elements as $element) { foreach($view -> elements as $element) {
$data['attributes'][$element -> name] = $element -> getApiValue($data['details']); $data['attributes'][$element -> name] = $element -> getApiValue($data['details']);
} }