Skip to content

Commit

Permalink
another try
Browse files Browse the repository at this point in the history
  • Loading branch information
stonebuzz committed Nov 21, 2024
1 parent 176f34e commit f775950
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions inc/abstractcontainerinstance.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,12 @@
abstract class PluginFieldsAbstractContainerInstance extends CommonDBTM
{

/**
* Checks if the HTTP request targets an object with an ID.
*
* This function determines whether the path contains an ID as the last segment
* (i.e., a number after the final '/').
*
* @param string $path The HTTP request path (e.g., $_SERVER['PATH_INFO']).
* @return mixed Returns ID if is present in the path, null otherwise.
*/
public static function hasRequestedObjectId(string $path): ?int
{
if (preg_match('#/(\d+)$#', $path, $matches)) {
return (int)$matches[1];
}
return null;
}

public static function canView()
{
$want_all = self::hasRequestedObjectId($_SERVER['PATH_INFO']);
if (isAPI() && ($want_all == null)) {
return false;
}

return parent::canView();
}

public function canViewItem()
{
//check if current user have access to the main item entity
$item = new $this->fields['itemtype']();
$item->getFromDB($this->fields['items_id']);
if (!Session::haveAccessToEntity($item->getEntityID(), $item->isRecursive())) {
if ($item->isEntityAssign() && !Session::haveAccessToEntity($item->getEntityID(), $item->isRecursive())) {
return false;
}
$right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $this->fields['plugin_fields_containers_id']);
Expand All @@ -78,7 +51,7 @@ public function canUpdateItem()
//check if current user have access to the main item entity
$item = new $this->fields['itemtype']();
$item->getFromDB($this->fields['items_id']);
if (!Session::haveAccessToEntity($item->getEntityID(), $item->isRecursive())) {
if ($item->isEntityAssign() && !Session::haveAccessToEntity($item->getEntityID(), $item->isRecursive())) {
return false;
}
$right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $this->fields['plugin_fields_containers_id']);
Expand Down

0 comments on commit f775950

Please sign in to comment.