Fix: better check and security
This commit is contained in:
parent
78d5520741
commit
9410466d72
@ -63,20 +63,20 @@ class AgendaEvents extends DolibarrApi
|
|||||||
*/
|
*/
|
||||||
function get($id)
|
function get($id)
|
||||||
{
|
{
|
||||||
if(! DolibarrApiAccess::$user->rights->agenda->myactions->read) {
|
if (! DolibarrApiAccess::$user->rights->agenda->myactions->read) {
|
||||||
throw new RestException(401, "Insuffisant rights to read an event");
|
throw new RestException(401, "Insuffisant rights to read an event");
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->actioncomm->fetch($id);
|
$result = $this->actioncomm->fetch($id);
|
||||||
if( ! $result ) {
|
if ( ! $result ) {
|
||||||
throw new RestException(404, 'Agenda Events not found');
|
throw new RestException(404, 'Agenda Events not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(! DolibarrApiAccess::$user->rights->agenda->allactions->read && $this->actioncomm->ownerid != DolibarrApiAccess::$user->id) {
|
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, "Insuffisant rights to read event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! DolibarrApi::_checkAccessToResource('agenda',$this->actioncomm->id)) {
|
if ( ! DolibarrApi::_checkAccessToResource('agenda',$this->actioncomm->id)) {
|
||||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,6 +102,10 @@ class AgendaEvents extends DolibarrApi
|
|||||||
|
|
||||||
$obj_ret = array();
|
$obj_ret = array();
|
||||||
|
|
||||||
|
if (! DolibarrApiAccess::$user->rights->agenda->myactions->read) {
|
||||||
|
throw new RestException(401, "Insuffisant rights to read events");
|
||||||
|
}
|
||||||
|
|
||||||
// case of external user
|
// case of external user
|
||||||
$socid = 0;
|
$socid = 0;
|
||||||
if (! empty(DolibarrApiAccess::$user->socid)) $socid = DolibarrApiAccess::$user->socid;
|
if (! empty(DolibarrApiAccess::$user->socid)) $socid = DolibarrApiAccess::$user->socid;
|
||||||
@ -155,7 +159,7 @@ class AgendaEvents extends DolibarrApi
|
|||||||
{
|
{
|
||||||
$obj = $db->fetch_object($result);
|
$obj = $db->fetch_object($result);
|
||||||
$actioncomm_static = new ActionComm($db);
|
$actioncomm_static = new ActionComm($db);
|
||||||
if($actioncomm_static->fetch($obj->rowid)) {
|
if ($actioncomm_static->fetch($obj->rowid)) {
|
||||||
$obj_ret[] = $this->_cleanObjectDatas($actioncomm_static);
|
$obj_ret[] = $this->_cleanObjectDatas($actioncomm_static);
|
||||||
}
|
}
|
||||||
$i++;
|
$i++;
|
||||||
@ -164,7 +168,7 @@ class AgendaEvents extends DolibarrApi
|
|||||||
else {
|
else {
|
||||||
throw new RestException(503, 'Error when retrieve Agenda Event list : '.$db->lasterror());
|
throw new RestException(503, 'Error when retrieve Agenda Event list : '.$db->lasterror());
|
||||||
}
|
}
|
||||||
if( ! count($obj_ret)) {
|
if ( ! count($obj_ret)) {
|
||||||
throw new RestException(404, 'No Agenda Event found');
|
throw new RestException(404, 'No Agenda Event found');
|
||||||
}
|
}
|
||||||
return $obj_ret;
|
return $obj_ret;
|
||||||
@ -178,10 +182,10 @@ class AgendaEvents extends DolibarrApi
|
|||||||
*/
|
*/
|
||||||
function post($request_data = NULL)
|
function post($request_data = NULL)
|
||||||
{
|
{
|
||||||
if(! DolibarrApiAccess::$user->rights->agenda->myactions->create) {
|
if (! DolibarrApiAccess::$user->rights->agenda->myactions->create) {
|
||||||
throw new RestException(401, "Insuffisant rights to create your Agenda Event");
|
throw new RestException(401, "Insuffisant rights to create your Agenda Event");
|
||||||
}
|
}
|
||||||
if(! DolibarrApiAccess::$user->rights->agenda->allactions->create && DolibarrApiAccess::$user->id != $request_data['userownerid']) {
|
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, "Insuffisant rights to create an Agenda Event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,19 +220,19 @@ class AgendaEvents extends DolibarrApi
|
|||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
function put($id, $request_data = NULL) {
|
function put($id, $request_data = NULL) {
|
||||||
if(! DolibarrApiAccess::$user->rights->agenda->myactions->create) {
|
if (! DolibarrApiAccess::$user->rights->agenda->myactions->create) {
|
||||||
throw new RestException(401, "Insuffisant rights to create your Agenda Event");
|
throw new RestException(401, "Insuffisant rights to create your Agenda Event");
|
||||||
}
|
}
|
||||||
if(! DolibarrApiAccess::$user->rights->agenda->allactions->create && DolibarrApiAccess::$user->id != $request_data['userownerid']) {
|
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, "Insuffisant rights to create an Agenda Event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->expensereport->fetch($id);
|
$result = $this->expensereport->fetch($id);
|
||||||
if( ! $result ) {
|
if ( ! $result ) {
|
||||||
throw new RestException(404, 'expensereport not found');
|
throw new RestException(404, 'expensereport not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
|
if ( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) {
|
||||||
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
|
||||||
}
|
}
|
||||||
foreach($request_data as $field => $value) {
|
foreach($request_data as $field => $value) {
|
||||||
@ -236,7 +240,7 @@ class AgendaEvents extends DolibarrApi
|
|||||||
$this->expensereport->$field = $value;
|
$this->expensereport->$field = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->expensereport->update($id, DolibarrApiAccess::$user,1,'','','update'))
|
if ($this->expensereport->update($id, DolibarrApiAccess::$user,1,'','','update'))
|
||||||
return $this->get($id);
|
return $this->get($id);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -314,7 +318,6 @@ class AgendaEvents extends DolibarrApi
|
|||||||
|
|
||||||
unset($object->import_key);
|
unset($object->import_key);
|
||||||
unset($object->array_options);
|
unset($object->array_options);
|
||||||
unset($object->linkedObjectsIds);
|
|
||||||
unset($object->context);
|
unset($object->context);
|
||||||
unset($object->canvas);
|
unset($object->canvas);
|
||||||
unset($object->fk_project);
|
unset($object->fk_project);
|
||||||
|
|||||||
@ -403,9 +403,9 @@ function checkUserAccessToObject($user, $featuresarray, $objectid=0, $tableandsh
|
|||||||
else if (in_array($feature,$checksoc)) // We check feature = checksoc
|
else if (in_array($feature,$checksoc)) // We check feature = checksoc
|
||||||
{
|
{
|
||||||
// If external user: Check permission for external users
|
// If external user: Check permission for external users
|
||||||
if ($user->societe_id > 0)
|
if ($user->socid > 0)
|
||||||
{
|
{
|
||||||
if ($user->societe_id <> $objectid) return false;
|
if ($user->socid <> $objectid) return false;
|
||||||
}
|
}
|
||||||
// If internal user: Check permission for internal users that are restricted on their objects
|
// If internal user: Check permission for internal users that are restricted on their objects
|
||||||
else if (! empty($conf->societe->enabled) && ($user->rights->societe->lire && ! $user->rights->societe->client->voir))
|
else if (! empty($conf->societe->enabled) && ($user->rights->societe->lire && ! $user->rights->societe->client->voir))
|
||||||
|
|||||||
@ -43,7 +43,8 @@ class Contacts extends DolibarrApi
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
function __construct() {
|
function __construct()
|
||||||
|
{
|
||||||
global $db, $conf;
|
global $db, $conf;
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
$this->contact = new Contact($this->db);
|
$this->contact = new Contact($this->db);
|
||||||
@ -59,7 +60,8 @@ class Contacts extends DolibarrApi
|
|||||||
*
|
*
|
||||||
* @throws RestException
|
* @throws RestException
|
||||||
*/
|
*/
|
||||||
function get($id) {
|
function get($id)
|
||||||
|
{
|
||||||
if (!DolibarrApiAccess::$user->rights->societe->contact->lire)
|
if (!DolibarrApiAccess::$user->rights->societe->contact->lire)
|
||||||
{
|
{
|
||||||
throw new RestException(401, 'No permission to read contacts');
|
throw new RestException(401, 'No permission to read contacts');
|
||||||
@ -105,7 +107,7 @@ class Contacts extends DolibarrApi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// case of external user, $thirdparty_ids param is ignored and replaced by user's socid
|
// case of external user, $thirdparty_ids param is ignored and replaced by user's socid
|
||||||
$socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $thirdparty_ids;
|
$socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids;
|
||||||
|
|
||||||
// If the internal user must only see his customers, force searching by him
|
// If the internal user must only see his customers, force searching by him
|
||||||
$search_sale = 0;
|
$search_sale = 0;
|
||||||
@ -171,7 +173,7 @@ class Contacts extends DolibarrApi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new RestException(503, 'Error when retreive contacts : ' . $sql);
|
throw new RestException(503, 'Error when retrieve contacts : ' . $sql);
|
||||||
}
|
}
|
||||||
if (!count($obj_ret))
|
if (!count($obj_ret))
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user