fix(fields): don't enforce mandatory fields on automated item creation - #1274
Conversation
Rom1-B
left a comment
There was a problem hiding this comment.
This only relaxes mandatory checks for CLI/cron/_auto_import (Ticket-only). !46291's actual scenarios (Inventory agent, REST API bulk import) go through plain HTTP requests and never set any of these. Can you also check is_dynamic (set by src/Glpi/Inventory/**) and isAPI() in inc/container.class.php:1743?
| ERROR, | ||
| ); | ||
|
|
||
| unset($GLOBALS['GLPI_IS_COMMAND_LINE']); |
There was a problem hiding this comment.
Move the unset into the existing tearDown() so it always runs, even if the assertion above fails.
This isn't the only line in this case; please process them all.
Rom1-B
left a comment
There was a problem hiding this comment.
The new isAPI() / is_dynamic bypass paths in isMandatoryCheckBypassed() have no test coverage. Can you add a case for an inventory-created item (is_dynamic) and one for an API-created item (isAPI()) skipping mandatory validation?
Description
Root cause
Mandatory custom fields were enforced unconditionally, even for items created without any human filling a form (tickets generated by the Mail Collector) Since there is no way to fill a mandatory custom field from an incoming email, item creation was silently rejected with "Some mandatory fields are empty".
Fix
Mandatory field enforcement in
PluginFieldsContainer::validateValues()is nowskipped when any of the following applies:
isCommandLine())Session::isCron())(
_auto_import), set byMailCollector::buildTicket()and by recurringtickets, this covers the "Collect now" button too, which is a plain web
request (neither CLI nor cron), so it wasn't covered by the first two checks
alone.
Steps to reproduce
Ticketwith a mandatory custom field and nodefault value.
empty"), even though there is no way for the sender to fill that field.
After the fix: the ticket is created normally.