Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed

- Redesign the mappings, additional information, file preview, injection log and profile rights screens
- Show the mapped and link fields counters, and warn when a field is used both by a mapping and an additional information
- `PluginDatainjectionInjectionType::dropdownLinkedTypes()`, `dropdownFields()` and `showMandatoryCheckbox()` are removed, and `PluginDatainjectionModelcsv::showSample()` returns a response instead of displaying the file

## [2.15.13] - 2026-11-13

### Fixed
Expand Down
40 changes: 0 additions & 40 deletions ajax/dropdownChooseField.php

This file was deleted.

40 changes: 0 additions & 40 deletions ajax/dropdownMandatory.php

This file was deleted.

78 changes: 78 additions & 0 deletions ajax/fieldsChoices.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

/**
* -------------------------------------------------------------------------
* DataInjection plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of DataInjection.
*
* DataInjection is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* DataInjection is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DataInjection. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2007-2023 by DataInjection plugin team.
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/pluginsGLPI/datainjection
* -------------------------------------------------------------------------
*/
use Glpi\Exception\Http\BadRequestHttpException;
use Symfony\Component\HttpFoundation\JsonResponse;

use function Safe\json_decode;

Html::header_nocache();

Session::checkRight('plugin_datainjection_model', READ);

$itemtype = (string) ($_POST['itemtype'] ?? PluginDatainjectionInjectionType::NO_VALUE);
$primary_type = (string) ($_POST['primary_type'] ?? '');
$called_by = (string) ($_POST['called_by'] ?? '');

try {
$mapping_or_info = json_decode((string) ($_POST['mapping_or_info'] ?? ''), true);
} catch (JsonException) {
throw new BadRequestHttpException();
}

if (
!is_a($primary_type, CommonDBTM::class, true)
|| ($itemtype !== PluginDatainjectionInjectionType::NO_VALUE && !is_a($itemtype, CommonDBTM::class, true))
|| !in_array($called_by, [PluginDatainjectionMapping::class, PluginDatainjectionInfo::class], true)
|| !isset($mapping_or_info['models_id'], $mapping_or_info['value'])
) {
throw new BadRequestHttpException();
}

// Reads the session only: release it so that the calls of a tab run in parallel
Session::writeClose();

$choices = PluginDatainjectionInjectionType::getFieldsChoices([
'itemtype' => $itemtype,
'primary_type' => $primary_type,
'called_by' => $called_by,
'mapping_or_info' => $mapping_or_info,
'need_decode' => false,
]);
Comment on lines +41 to +67

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A missing or broken mapping_or_info currently ends in PHP warnings; rejecting it with the other checks returns a clean 400:

Suggested change
$called_by = (string) ($_POST['called_by'] ?? '');
if (
!is_a($primary_type, CommonDBTM::class, true)
|| ($itemtype !== PluginDatainjectionInjectionType::NO_VALUE && !is_a($itemtype, CommonDBTM::class, true))
|| !in_array($called_by, [PluginDatainjectionMapping::class, PluginDatainjectionInfo::class], true)
) {
throw new BadRequestHttpException();
}
Session::checkCentralAccess();
// Reads the session only: release it so that the calls of a tab run in parallel
Session::writeClose();
PluginDatainjectionInjectionType::showMandatoryCheckbox($_POST);
$choices = PluginDatainjectionInjectionType::getFieldsChoices([
'itemtype' => $itemtype,
'primary_type' => $primary_type,
'called_by' => $called_by,
'mapping_or_info' => (string) ($_POST['mapping_or_info'] ?? '{}'),
]);
$called_by = (string) ($_POST['called_by'] ?? '');
try {
$mapping_or_info = \Safe\json_decode((string) ($_POST['mapping_or_info'] ?? ''), true);
} catch (JsonException) {
throw new BadRequestHttpException();
}
if (
!is_a($primary_type, CommonDBTM::class, true)
|| ($itemtype !== PluginDatainjectionInjectionType::NO_VALUE && !is_a($itemtype, CommonDBTM::class, true))
|| !in_array($called_by, [PluginDatainjectionMapping::class, PluginDatainjectionInfo::class], true)
|| !isset($mapping_or_info['models_id'], $mapping_or_info['value'])
) {
throw new BadRequestHttpException();
}
// Reads the session only: release it so that the calls of a tab run in parallel
Session::writeClose();
$choices = PluginDatainjectionInjectionType::getFieldsChoices([
'itemtype' => $itemtype,
'primary_type' => $primary_type,
'called_by' => $called_by,
'mapping_or_info' => $mapping_or_info,
'need_decode' => false,
]);


// Use a list of pairs to keep the options order on client side
$fields = [];
foreach ($choices['fields'] as $key => $label) {
$fields[] = [$key, $label];
}

return new JsonResponse([
'fields' => $fields,
'value' => $choices['value'],
]);
5 changes: 2 additions & 3 deletions ajax/inject_batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@
* @link https://github.com/pluginsGLPI/datainjection
* -------------------------------------------------------------------------
*/
use function Safe\json_encode;
use Symfony\Component\HttpFoundation\JsonResponse;

header("Content-Type: application/json; charset=UTF-8");
Html::header_nocache();

Session::checkRight(PluginDatainjectionClientInjection::$rightname, READ);

$offset = (int) ($_POST['offset'] ?? 0);
$batch_size = (int) ($_POST['batch_size'] ?? 10);

echo json_encode(
return new JsonResponse(
PluginDatainjectionClientInjection::processBatch($offset, $batch_size),
);
2 changes: 1 addition & 1 deletion front/info.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
PluginDatainjectionInfo::manageInfos($_POST['models_id'], $_POST);
} elseif (isset($_POST["delete"])) {
$info = new PluginDatainjectionInfo();
foreach ($_POST["item"] as $key => $val) {
foreach ($_POST["item"] ?? [] as $key => $val) {
$input = ['id' => $key];
if ($val == 1) {
$info->check($key, UPDATE);
Expand Down
3 changes: 1 addition & 2 deletions front/model.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@
$model->check($_GET['sample'], READ);
$modeltype = PluginDatainjectionModel::getInstance($model->getField('filetype'));
$modeltype->getFromDBByModelID($model->getField('id'));
$modeltype->showSample($model);
return;
return $modeltype->showSample($model);
}

Html::header(
Expand Down
3 changes: 1 addition & 2 deletions inc/clientinjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public static function showUploadFileForm($options = [])
'url' => $url,
'models_id' => $options['models_id'] ?? null,
'confirm' => $confirm,
'warn_override' => $options['warn_override'] ?? true,
'submit_label' => $options['submit'] ?? __('Launch the import', 'datainjection'),
'file_encoding_values' => PluginDatainjectionDropdown::getFileEncodingValue(),
];
Expand Down Expand Up @@ -177,8 +178,6 @@ public static function showInjectionForm(PluginDatainjectionModel $model, $entit
'result_url' => $result_url,
'plugin_url' => plugin_datainjection_geturl(),
]);

echo "<span id='span_injection' name='span_injection'></span>";
}


Expand Down
Loading