From bd4c9a64a868f17b58c37a26a7333377e5a0b601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sat, 7 Sep 2019 14:48:25 +0200 Subject: [PATCH] wip --- htdocs/comm/action/class/actioncomm.class.php | 3 +- .../action/class/api_agendaevents.class.php | 33 ++++++++++--------- htdocs/contact/class/contact.class.php | 3 +- htdocs/contrat/class/api_contracts.class.php | 2 +- htdocs/societe/class/api_contacts.class.php | 7 ++-- .../societe/class/api_thirdparties.class.php | 7 ++-- htdocs/societe/class/societe.class.php | 3 +- 7 files changed, 35 insertions(+), 23 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 12926f9b360..4da7686b0a2 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1637,7 +1637,7 @@ class ActionComm extends CommonObject * Used to build previews or test instances. * id must be 0 if object instance is a specimen. * - * @return void + * @return int >0 if ok */ public function initAsSpecimen() { @@ -1669,6 +1669,7 @@ class ActionComm extends CommonObject $this->userownerid=$user->id; $this->userassigned[$user->id]=array('id'=>$user->id, 'transparency'=> 1); + return 1; } /** diff --git a/htdocs/comm/action/class/api_agendaevents.class.php b/htdocs/comm/action/class/api_agendaevents.class.php index 833f97b3b6b..1109112284a 100644 --- a/htdocs/comm/action/class/api_agendaevents.class.php +++ b/htdocs/comm/action/class/api_agendaevents.class.php @@ -64,25 +64,28 @@ class AgendaEvents extends DolibarrApi public function get($id) { if (! DolibarrApiAccess::$user->rights->agenda->myactions->read) { - throw new RestException(401, "Insuffisant rights to read an event"); + throw new RestException(401, "Insufficient rights to read an event"); + } + if ($id == 0) { + $result = $this->actioncomm->initAsSpecimen(); + } else { + $result = $this->actioncomm->fetch($id); + if ($result) { + $this->actioncomm->fetch_optionals(); + $this->actioncomm->fetchObjectLinked(); + } } - - $result = $this->actioncomm->fetch($id); if ( ! $result ) { throw new RestException(404, 'Agenda Events not found'); } if (! DolibarrApiAccess::$user->rights->agenda->allactions->read && $this->actioncomm->ownerid != DolibarrApiAccess::$user->id) { - throw new RestException(401, "Insuffisant rights to read event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id); + throw new RestException(401, "Insufficient rights to read event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id); } if ( ! DolibarrApi::_checkAccessToResource('agenda', $this->actioncomm->id, 'actioncomm', '', 'fk_soc', 'id')) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - - $result = $this->actioncomm->fetch_optionals(); - - $this->actioncomm->fetchObjectLinked(); return $this->_cleanObjectDatas($this->actioncomm); } @@ -106,7 +109,7 @@ class AgendaEvents extends DolibarrApi $obj_ret = array(); if (! DolibarrApiAccess::$user->rights->agenda->myactions->read) { - throw new RestException(401, "Insuffisant rights to read events"); + throw new RestException(401, "Insufficient rights to read events"); } // case of external user @@ -191,10 +194,10 @@ class AgendaEvents extends DolibarrApi public function post($request_data = null) { if (! DolibarrApiAccess::$user->rights->agenda->myactions->create) { - throw new RestException(401, "Insuffisant rights to create your Agenda Event"); + throw new RestException(401, "Insufficient rights to create your Agenda Event"); } if (! DolibarrApiAccess::$user->rights->agenda->allactions->create && DolibarrApiAccess::$user->id != $request_data['userownerid']) { - throw new RestException(401, "Insuffisant rights to create an Agenda Event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id); + throw new RestException(401, "Insufficient rights to create an Agenda Event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id); } // Check mandatory fields @@ -230,10 +233,10 @@ class AgendaEvents extends DolibarrApi public function put($id, $request_data = null) { if (! DolibarrApiAccess::$user->rights->agenda->myactions->create) { - throw new RestException(401, "Insuffisant rights to create your Agenda Event"); + throw new RestException(401, "Insufficient rights to create your Agenda Event"); } if (! DolibarrApiAccess::$user->rights->agenda->allactions->create && DolibarrApiAccess::$user->id != $request_data['userownerid']) { - throw new RestException(401, "Insuffisant rights to create an Agenda Event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id); + throw new RestException(401, "Insufficient rights to create an Agenda Event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id); } $result = $this->actioncomm->fetch($id); @@ -266,13 +269,13 @@ class AgendaEvents extends DolibarrApi public function delete($id) { if(! DolibarrApiAccess::$user->rights->agenda->myactions->delete) { - throw new RestException(401, "Insuffisant rights to delete your Agenda Event"); + throw new RestException(401, "Insufficient rights to delete your Agenda Event"); } $result = $this->actioncomm->fetch($id); if(! DolibarrApiAccess::$user->rights->agenda->allactions->delete && DolibarrApiAccess::$user->id != $this->actioncomm->userownerid) { - throw new RestException(401, "Insuffisant rights to delete an Agenda Event of owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id); + throw new RestException(401, "Insufficient rights to delete an Agenda Event of owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id); } if( ! $result ) { diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index ebfafa698b7..177f2dd2e93 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -1288,7 +1288,7 @@ class Contact extends CommonObject * Used to build previews or test instances. * id must be 0 if object instance is a specimen. * - * @return void + * @return int >0 if ok */ public function initAsSpecimen() { @@ -1325,6 +1325,7 @@ class Contact extends CommonObject $this->socid = $socid; $this->statut=1; + return 1; } /** diff --git a/htdocs/contrat/class/api_contracts.class.php b/htdocs/contrat/class/api_contracts.class.php index 194e145210f..d49214dfb4d 100644 --- a/htdocs/contrat/class/api_contracts.class.php +++ b/htdocs/contrat/class/api_contracts.class.php @@ -187,7 +187,7 @@ class Contracts extends DolibarrApi public function post($request_data = null) { if(! DolibarrApiAccess::$user->rights->contrat->creer) { - throw new RestException(401, "Insuffisant rights"); + throw new RestException(401, "Insufficient rights"); } // Check mandatory fields $result = $this->_validate($request_data); diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index 38dfdf71fd8..b2adc8ce5ff 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -74,8 +74,11 @@ class Contacts extends DolibarrApi { throw new RestException(401, 'No permission to read contacts'); } - - $result = $this->contact->fetch($id); + if ($id ==0) { + $result = $this->contact->intiAsSpecimen(); + } else { + $result = $this->contact->fetch($id); + } if (!$result) { diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index ddb19c563fe..919961b4f8f 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -76,8 +76,11 @@ class Thirdparties extends DolibarrApi if(! DolibarrApiAccess::$user->rights->societe->lire) { throw new RestException(401); } - - $result = $this->company->fetch($id); + if ($id ==0) { + $result = $this->company->intiAsSpecimen(); + } else { + $result = $this->company->fetch($id); + } if( ! $result ) { throw new RestException(404, 'Thirdparty not found'); } diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 26ad0c6bed9..86408c482cc 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3539,7 +3539,7 @@ class Societe extends CommonObject * Used to build previews or test instances. * id must be 0 if object instance is a specimen. * - * @return void + * @return int >0 if ok */ public function initAsSpecimen() { @@ -3586,6 +3586,7 @@ class Societe extends CommonObject $this->idprof4='idprof4'; $this->idprof5='idprof5'; $this->idprof6='idprof6'; + return 1; } /**