Skip to content

Commit

Permalink
check for access entity and prevent purge from API
Browse files Browse the repository at this point in the history
  • Loading branch information
stonebuzz committed Nov 19, 2024
1 parent b0c2f05 commit deb0d5d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions inc/abstractcontainerinstance.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ abstract class PluginFieldsAbstractContainerInstance extends CommonDBTM
{
public function canViewItem()
{
//check if current user have access to the main item entity
$item = new $this->fields['itemtype']();
$item->getFromDB($this->fields['item_id']);
if (!Session::haveAccessToEntity($item->getEntityID(), $item->isRecursive())) {
return false;
}

$right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $this->fields['plugin_fields_containers_id']);
if ($right < READ) {
return false;
Expand All @@ -41,13 +48,29 @@ public function canViewItem()

public function canUpdateItem()
{
//check if current user have access to the main item entity
$item = new $this->fields['itemtype']();
$item->getFromDB($this->fields['item_id']);
if (!Session::haveAccessToEntity($item->getEntityID(), $item->isRecursive())) {
return false;
}

$right = PluginFieldsProfile::getRightOnContainer($_SESSION['glpiactiveprofile']['id'], $this->fields['plugin_fields_containers_id']);
if ($right > READ) {
return true;
}
return false;
}

public function canPurgeItem()
{
if (isAPI()) {
return false;
}
return true;
}


public static function getSpecificValueToSelect($field, $name = '', $values = '', array $options = [])
{
if (!is_array($values)) {
Expand Down

0 comments on commit deb0d5d

Please sign in to comment.