Skip to content

Commit

Permalink
Fix for issue #371 (#445)
Browse files Browse the repository at this point in the history
* Fix for issue #371

* Edited as per requested

* Corrected issues with automated checks

* Updated changelog

* Update CHANGELOG.md

Co-authored-by: Stanislas <[email protected]>

---------

Co-authored-by: Stanislas <[email protected]>
  • Loading branch information
PlaneNuts and stonebuzz authored Dec 10, 2024
1 parent 6987172 commit abe9757
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- Fix default entity insertion for a user
- Fixed `SQL` error when creating new injection model

## [2.14.0] - 2024-10-10

Expand Down
42 changes: 21 additions & 21 deletions inc/model.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1340,29 +1340,29 @@ public static function checkRightOnModel($models_id)
/** @var DBmysql $DB */
global $DB;

$model = new self();
$model->getFromDB($models_id);

$continue = true;

$query = "(SELECT `itemtype`
FROM `glpi_plugin_datainjection_models`
WHERE `id` = '" . $models_id . "')
UNION (SELECT DISTINCT `itemtype`
FROM `glpi_plugin_datainjection_mappings`
WHERE `models_id` = '" . $models_id . "')
UNION (SELECT DISTINCT `itemtype`
FROM `glpi_plugin_datainjection_infos`
WHERE `models_id` = '" . $models_id . "')";
foreach ($DB->request($query) as $data) {
if ($data['itemtype'] != PluginDatainjectionInjectionType::NO_VALUE) {
if (class_exists($data['itemtype'])) {
$item = new $data['itemtype']();
$item->fields['itemtype'] = $model->fields['itemtype'];

if (!($item instanceof CommonDBRelation) && !$item->canCreate()) {
$continue = false;
break;
$model = new self();
if ($model->getFromDB($models_id)) {
$query = "(SELECT `itemtype`
FROM `glpi_plugin_datainjection_models`
WHERE `id` = '" . $models_id . "')
UNION (SELECT DISTINCT `itemtype`
FROM `glpi_plugin_datainjection_mappings`
WHERE `models_id` = '" . $models_id . "')
UNION (SELECT DISTINCT `itemtype`
FROM `glpi_plugin_datainjection_infos`
WHERE `models_id` = '" . $models_id . "')";
foreach ($DB->request($query) as $data) {
if ($data['itemtype'] != PluginDatainjectionInjectionType::NO_VALUE) {
if (class_exists($data['itemtype'])) {
$item = new $data['itemtype']();
$item->fields['itemtype'] = $model->fields['itemtype'];

if (!($item instanceof CommonDBRelation) && !$item->canCreate()) {
$continue = false;
break;
}
}
}
}
Expand Down

0 comments on commit abe9757

Please sign in to comment.