Skip to content

Conversation

@SebSept
Copy link
Contributor

@SebSept SebSept commented Oct 28, 2025

Checklist before requesting a review

Please delete options that are not relevant.

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.
  • This change requires a documentation update.

Description

@cconard96
Copy link
Contributor

Shouldn't the action for "Group" be changed in addition to "Group in charge"?

@SebSept
Copy link
Contributor Author

SebSept commented Oct 28, 2025

Shouldn't the action for "Group" be changed in addition to "Group in charge"?

good question.
groups_id_tech is used to associate asset to group with the type GROUP_TYPE_TECH
and groups_id association type is GROUP_TYPE_NORMAL (which have no clear meaning to me, is it ownership relation ?).

And, you are right, we can also add the possibility to add multiple groups for groups_id since it's possible in the UI.
I'll add it very soon. I guess it's possible to add it in this PR.

@SebSept SebSept marked this pull request as draft October 28, 2025 11:25
@cconard96
Copy link
Contributor

and groups_id association type is GROUP_TYPE_NORMAL (which have no clear meaning to me, is it ownership relation ?).

Yes. It is just the default/regular group association type.

And, you are right, we can also add the possibility to add multiple groups for groups_id since it's possible in the UI. I'll add it very soon. I guess it's possible to add it in this PR.

The only issue I forsee is confusion around the defaultfromuser and firstgroupfromuser actions in the context of multiple groups.

@SebSept SebSept marked this pull request as ready for review October 28, 2025 16:09
@cedric-anne cedric-anne added this to the 11.0.2 milestone Oct 29, 2025
@SebSept SebSept requested a review from cedric-anne October 30, 2025 13:08
@SebSept
Copy link
Contributor Author

SebSept commented Oct 30, 2025

permitseveral is applied only to append action (for both actions), so no problem with defaultfromuser and firstgroupfromuser.

Copy link
Member

@cedric-anne cedric-anne left a comment

Choose a reason for hiding this comment

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

The append action seems to remove the existing groups, instead of appending new groups to existing groups.

@cedric-anne cedric-anne modified the milestones: 11.0.2, 11.0.3 Nov 4, 2025
@SebSept
Copy link
Contributor Author

SebSept commented Nov 5, 2025

ok, I'll check by adding a test.

@SebSept SebSept marked this pull request as draft November 5, 2025 07:53
@SebSept
Copy link
Contributor Author

SebSept commented Nov 5, 2025

The append action seems to remove the existing groups, instead of appending new groups to existing groups.

This was the case. I added a test then fix the code.

@SebSept
Copy link
Contributor Author

SebSept commented Nov 5, 2025

(sorry for the merge, I resolved the conflict in GitHub)

@SebSept SebSept marked this pull request as ready for review November 5, 2025 14:57
@cedric-anne cedric-anne force-pushed the fix-20837-add-multiple-group-in-charge-of-an-asset branch from 9e9c7ef to 7afb679 Compare November 6, 2025 11:01
Copy link
Member

@cedric-anne cedric-anne left a comment

Choose a reason for hiding this comment

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

There is still an issue. Existing values are correctly preserved, but if I tried to manually add a group in the form, it is dropped when the "append" rule is executed.

@SebSept SebSept force-pushed the fix-20837-add-multiple-group-in-charge-of-an-asset branch from 96b6ae6 to 93a0131 Compare November 13, 2025 09:12
Copy link
Contributor

@AdrienClairembault AdrienClairembault left a comment

Choose a reason for hiding this comment

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

E2E failure is related, I reproduce it with make cypress c="--spec tests/cypress/e2e/form/destination_config_fields/requester.cy.js"

Image

The 500 error from the server logs:

[2025-11-14 08:49:37] glpi.CRITICAL:   *** Uncaught PHP Exception TypeError: "array_merge(): Argument #2 must be of type array, int given" at CommonDBTM.php line 5776
  Backtrace :
  ./src/CommonDBTM.php:5776                          
  ./src/CommonDBTM.php:5776                          array_merge()
  ./src/CommonDBTM.php:1353                          CommonDBTM->assetBusinessRules()
  ./src/Glpi/Api/API.php:1894                        CommonDBTM->add()
  ./src/Glpi/Api/APIRest.php:344                     Glpi\Api\API->createItems()
  ./src/Glpi/Controller/ApiRestController.php:59     Glpi\Api\APIRest->call()
  ./vendor/symfony/http-kernel/HttpKernel.php:101    Glpi\Controller\ApiRestController->{closure:Glpi\Controller\ApiRestController::__invoke():57}()
  ...ymfony/http-foundation/StreamedResponse.php:106 Symfony\Component\HttpKernel\HttpKernel::{closure:Symfony\Component\HttpKernel\HttpKernel::handle():98}()
  ./vendor/symfony/http-foundation/Response.php:423  Symfony\Component\HttpFoundation\StreamedResponse->sendContent()
  ./src/Glpi/Kernel/Kernel.php:295                   Symfony\Component\HttpFoundation\Response->send()
  ./public/index.php:72                              Glpi\Kernel\Kernel->sendResponse()

It seems to be this API payload that trigger the errors:

Image

I think you missed that groups_id can be an int instead of an array (as this API call work properly and set the correct groups on the bugfixes branch).

@SebSept
Copy link
Contributor Author

SebSept commented Nov 14, 2025

E2E failure is related, I reproduce it with make cypress c="--spec tests/cypress/e2e/form/destination_config_fields/requester.cy.js"
Image

The 500 error from the server logs:

[2025-11-14 08:49:37] glpi.CRITICAL:   *** Uncaught PHP Exception TypeError: "array_merge(): Argument #2 must be of type array, int given" at CommonDBTM.php line 5776
  Backtrace :
  ./src/CommonDBTM.php:5776                          
  ./src/CommonDBTM.php:5776                          array_merge()
  ./src/CommonDBTM.php:1353                          CommonDBTM->assetBusinessRules()
  ./src/Glpi/Api/API.php:1894                        CommonDBTM->add()
  ./src/Glpi/Api/APIRest.php:344                     Glpi\Api\API->createItems()
  ./src/Glpi/Controller/ApiRestController.php:59     Glpi\Api\APIRest->call()
  ./vendor/symfony/http-kernel/HttpKernel.php:101    Glpi\Controller\ApiRestController->{closure:Glpi\Controller\ApiRestController::__invoke():57}()
  ...ymfony/http-foundation/StreamedResponse.php:106 Symfony\Component\HttpKernel\HttpKernel::{closure:Symfony\Component\HttpKernel\HttpKernel::handle():98}()
  ./vendor/symfony/http-foundation/Response.php:423  Symfony\Component\HttpFoundation\StreamedResponse->sendContent()
  ./src/Glpi/Kernel/Kernel.php:295                   Symfony\Component\HttpFoundation\Response->send()
  ./public/index.php:72                              Glpi\Kernel\Kernel->sendResponse()

It seems to be this API payload that trigger the errors:
Image

I think you missed that groups_id can be an int instead of an array (as this API call work properly and set the correct groups on the bugfixes branch).

it means a phpunit test is missing, I suppose. I'll add it if possible.

@AdrienClairembault
Copy link
Contributor

Given the number of unexpected issues that have been found (and the fact that this is a new feature), I think it would be safer to target the main branch instead.

@SebSept
Copy link
Contributor Author

SebSept commented Nov 25, 2025

Given the number of unexpected issues that have been found (and the fact that this is a new feature), I think it would be safer to target the main branch instead.

A (cypress?) test is missing probably.

I agree, it's a feature more than a bugfix.

@cedric-anne cedric-anne modified the milestones: 11.0.3, 11.0.4 Nov 26, 2025
SebSept and others added 22 commits November 26, 2025 15:47
replace $this->assertEmpty() by $this->assertEquals([]
Co-authored-by: Johan Cwiklinski <trasher@x-tnd.be>
Co-authored-by: Adrien Clairembault <42734840+AdrienClairembault@users.noreply.github.com>
refix.

Co-authored-by: Adrien Clairembault <42734840+AdrienClairembault@users.noreply.github.com>
Not sure how this can happen, but it does...
@SebSept SebSept force-pushed the fix-20837-add-multiple-group-in-charge-of-an-asset branch from 5e3af5b to 20a9d11 Compare November 26, 2025 14:49
@cedric-anne cedric-anne modified the milestones: 11.0.4, 11.0.5 Dec 4, 2025
Copy link
Member

@cedric-anne cedric-anne left a comment

Choose a reason for hiding this comment

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

If we are able to move the required changes in the rules class, without having to change too much the API and the CommonDBTM code, it could be OK to include this change in GLPI 11.

//add current item
$message = '';
try {
$item->fields = []; // reset fields which can be set by $item->can(), avoid side effects
Copy link
Member

Choose a reason for hiding this comment

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

I think it must be fixed somewhere else. Indeed, there are probably many places where the if ($item->can($id, CREATE, $input)) { $item->add($input); } chaining is done. It should not trigger issues.

Comment on lines +5841 to +5864
if (is_array($value) && $value !== []) {
// determine $preserve_user_input by processing the first item, the value is the same on each entry
// but just in case this is not the case anymore a check is processed
// value can be an array if multiples values are set and can be an array because of appendtoarray & appendtoarrayfield are defined in action (for group fields, _groups_id , _groups_id_tech)
// @see \RuleAsset::getActions()
$_rule_action_field_exists = array_reduce(
$value,
static fn($result, $v) => $result && is_array($v) && array_key_exists('_rule_action', $v),
true
);
if ($_rule_action_field_exists) {

$preserve_user_input = $value[0]['_rule_action'] === 'append';
if ($preserve_user_input && !isset($existing_data[$field])) {
throw new LogicException('Implemetation error: action was defined with appendtoarray but the value not backed up before rule processing');
}
// use value before rule processing
$this->input[$field] = $preserve_user_input ? $existing_data[$field] : [];
foreach ($value as $_value) {
$this->input[$field][] = $_value[$field];
}
$value_processed = true;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

If possible , the related logic should be located in the rules classes. However, I do not know where the logic used for ticket actors is located.

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.

Can't add multiple groups in charge of an asset using Business Rules for Assets

5 participants