Repository navigation
Conversation
Rom1-B
left a comment
There was a problem hiding this comment.
Thanks, this looks good in my tests. Since it touches a lot of files, I'd rather wait until the other open PRs are merged, then rebase this one and do the full review.
bde8770 to
b78c1b0
Compare
- Mappings and additional information forms share a mapping table component: the field dropdown is refreshed client side (ajax/fieldsChoices.php) instead of reloading the rows through dropdownChooseField.php / dropdownMandatory.php - Show the mapped / link fields counters and the fields used both by a mapping and an additional information - Twig templates for the profile rights, the file preview and the injection log - Model dropdown rendered with Dropdown::showFromArray() - Sample CSV and batch injection return Symfony responses - Only warn about mappings override when the model already has mappings - Remove the CSS and JS of the old wizard, unused
b78c1b0 to
a881784
Compare
Rom1-B
left a comment
There was a problem hiding this comment.
dropdownLinkedTypes(), dropdownFields() and showMandatoryCheckbox() (in inc/injectiontype.class.php) are public and removed here, and showSample() now returns a Response instead of echoing. Do you know of any third-party plugin relying on them? If not, a line in the CHANGELOG would be enough.
| public static function getRow($mapping_or_info, $primary_type) | ||
| { | ||
| $id = $mapping_or_info->fields['id']; | ||
| $itemtype = $mapping_or_info->fields['itemtype'] ?: self::NO_VALUE; |
There was a problem hiding this comment.
A stored itemtype that is no longer injectable (e.g. Fields plugin disabled) now breaks the whole tab:
| $itemtype = $mapping_or_info->fields['itemtype'] ?: self::NO_VALUE; | |
| $itemtype = $mapping_or_info->fields['itemtype']; | |
| // The stored itemtype may no longer be injectable (e.g. a Fields container of a disabled plugin) | |
| if (!isset(self::getLinkedTypes($primary_type)[$itemtype])) { | |
| $itemtype = self::NO_VALUE; | |
| } |
Can you add a test for a row whose itemtype is not a linked type?
| $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'] ?? '{}'), | ||
| ]); |
There was a problem hiding this comment.
A missing or broken mapping_or_info currently ends in PHP warnings; rejecting it with the other checks returns a clean 400:
| $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, | |
| ]); |
| {% if type == 'textarea' %} | ||
| {{ inputs.textarea(name, value, {'rows': 5}) }} | ||
| {% elseif type == 'password' %} | ||
| {{ inputs.password(name, '', {'additional_attributes': {'autocomplete': 'off'}}) }} | ||
| {% else %} | ||
| {{ inputs.text(name, value) }} | ||
| {% endif %} |
There was a problem hiding this comment.
The label from htmlField points to an id the input doesn't have; %id% gets replaced with the label's id:
| {% if type == 'textarea' %} | |
| {{ inputs.textarea(name, value, {'rows': 5}) }} | |
| {% elseif type == 'password' %} | |
| {{ inputs.password(name, '', {'additional_attributes': {'autocomplete': 'off'}}) }} | |
| {% else %} | |
| {{ inputs.text(name, value) }} | |
| {% endif %} | |
| {% if type == 'textarea' %} | |
| {{ inputs.textarea(name, value, {'id': '%id%', 'rows': 5}) }} | |
| {% elseif type == 'password' %} | |
| {{ inputs.password(name, '', {'id': '%id%', 'additional_attributes': {'autocomplete': 'off'}}) }} | |
| {% else %} | |
| {{ inputs.text(name, value, {'id': '%id%'}) }} | |
| {% endif %} |
…mapping, label of the info inputs
Checklist before requesting a review
Description
The remaining screens built with
echoare now rendered with Twig templates, using the GLPI form components.Mappings and additional information
components/mapping_table.html.twigcomponent.ajax/fieldsChoices.php). The rows are no longer reloaded byajax/dropdownChooseField.php/ajax/dropdownMandatory.php, which are removed.Other screens
Dropdown::showFromArray(), and the upload form uses the GLPI field macros.Html::getProgressBar().Code
header()+echo.tests/unit/InjectionTypeRowTest.php.Screenshots (if appropriate):
Before / after for each modified page: