Skip to content

fix(commoninjectionlib.class.php): normalize group assignment fields for assignable items only#631

Open
TarekRemo wants to merge 4 commits into
pluginsGLPI:mainfrom
TarekRemo:ticket_44708
Open

fix(commoninjectionlib.class.php): normalize group assignment fields for assignable items only#631
TarekRemo wants to merge 4 commits into
pluginsGLPI:mainfrom
TarekRemo:ticket_44708

Conversation

@TarekRemo

@TarekRemo TarekRemo commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Checklist before requesting a review

Please delete options that are not relevant.

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Description

  • It fixes !44708
  • the block that normalizes group assignment fields (example : groups_id → _groups_id (array)) was triggered for any item with a search option pointing to glpi_groups. Some items (example: ITILCategory) store groups_id as a direct integer FK, not via Group_Item. For these items, the _groups_id array this block produced was silently ignored, leaving groups_id = 0.
  • Fix: Check that the item being injected has the AssignableItem trait to the guard condition. The rewrite now only happens for items like Computer that actually has this trait and expect group assignments through Group_Item relations.

@stonebuzz

Copy link
Copy Markdown
Contributor

I would appreciate having a unit test covering this part in order to definitively address the issue, as it has come up several times. This would also provide a good starting point for building our unit test coverage.Ideally, this should be validated with a real test involving the injection of a CSV file.

@TarekRemo

Copy link
Copy Markdown
Contributor Author

I would appreciate having a unit test covering this part in order to definitively address the issue, as it has come up several times. This would also provide a good starting point for building our unit test coverage.Ideally, this should be validated with a real test involving the injection of a CSV file.

I added unit tests. Didn't use a real CSV file but the tests simulate the starting point when a real CSV is injected.

Comment thread tests/unit/GroupInjectionTest.php Outdated

final class GroupInjectionTest extends DbTestCase
{
public static function AssigneGroupToInjectedAssignableItemProvider(): array

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.

Suggested change
public static function AssigneGroupToInjectedAssignableItemProvider(): array
public static function assignGroupToInjectedAssignableItemProvider(): array

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread tests/unit/GroupInjectionTest.php Outdated

/**
*
* @dataProvider assigneGroupToInjectedAssignableItemProvider

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.

Suggested change
* @dataProvider assigneGroupToInjectedAssignableItemProvider
* @dataProvider assignGroupToInjectedAssignableItemProvider

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread tests/bootstrap.php

use function Safe\realpath;

$current_plugin_folder = basename(realpath(__DIR__ . '/../'));

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.

useless now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed

Comment thread tests/unit/GroupInjectionTest.php Outdated
/**
* Updating an existing non assignable item via injection must also persist groups_id.
*/
public function testGroupIsUpdatedOnExistingNonAssugnableItem(): void

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.

Suggested change
public function testGroupIsUpdatedOnExistingNonAssugnableItem(): void
public function testGroupIsUpdatedOnExistingNonAssignableItem(): void

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

// Normalize group assignment fields to GLPI relation payload keys.
// Some search options do not expose a stable joinparams shape, but GLPI
// still expects _groups_id/_groups_id_tech arrays when saving equipment groups.
// Only apply to items using the AssignableItem trait.

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.

Suggested change
// Only apply to items using the AssignableItem trait.
// Only apply to items using the AssignableItem trait.
// Non-AssignableItem types store groups_id as a plain FK; skip array normalisation for them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added

@TarekRemo TarekRemo requested a review from stonebuzz June 18, 2026 14:13

@stonebuzz stonebuzz left a comment

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.

LGTM

@stonebuzz

Copy link
Copy Markdown
Contributor

Awaiting customer approval

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants