Skip to content

Harmonize code accross similar controllers - #389

Open
btry wants to merge 1 commit into
pluginsGLPI:12.0/bugfixesfrom
btry:refactor/harmonize_data_reset
Open

btry wants to merge 1 commit into
pluginsGLPI:12.0/bugfixesfrom
btry:refactor/harmonize_data_reset

Conversation

@btry

@btry btry commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

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

Embodied impact and usage impact of a specific asset are not erased with the same query parameters. The PR harmonizes this.

Screenshots (if appropriate):

@btry btry self-assigned this Nov 4, 2026
@btry
btry requested a review from Rom1-B November 4, 2026 12:15

@Rom1-B Rom1-B 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.

tests/units/Controller/EmbodiedImpactControllerTest.php still posts id, so it now stops on the missing arguments check and never reaches the purge right check. Asserting the message makes that visible:

@@ -32,6 +32,7 @@
 namespace GlpiPlugin\Carbon\Tests\Controller;
 
+use Computer;
 use Glpi\Exception\Http\AccessDeniedHttpException;
@@ -127,13 +128,14 @@
         $request = Request::create('/', 'POST', [
-            'id' => '1',
+            'itemtype' => Computer::class,
+            'items_id' => '1',
         ]);
 
         $response = $this->callPrivateMethod(new EmbodiedImpactController(), 'reset', $request);
 
         $this->assertInstanceOf(RedirectResponse::class, $response);
-        $this->assertCount(1, $_SESSION['MESSAGE_AFTER_REDIRECT'][ERROR]);
+        $this->assertSame([__('Reset denied.', 'carbon')], $_SESSION['MESSAGE_AFTER_REDIRECT'][ERROR]);

$item->check($items_id, UPDATE);

if (!$embodied_impact->delete($embodied_impact->fields)) {
if (!CommonAsset::deleteEmbodiedImpact($item)) {

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.

Can you add a test resetting a real asset with itemtype/items_id and checking its embodied impact row is gone?

if (!$request->request->has('id')) {
Session::addMessageAfterRedirect(__('Missing arguments in request.', 'carbon'), false, ERROR);
if (!$request->request->has('itemtype') || !$request->request->has('items_id')) {
Session::addMessageAfterRedirect(__('Missing arguments in the request.', 'carbon'), false, ERROR);

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.

calculate() still uses the old msgid, which is already translated; I'd keep it here and in UsageImpactController too:

Suggested change
Session::addMessageAfterRedirect(__('Missing arguments in the request.', 'carbon'), false, ERROR);
Session::addMessageAfterRedirect(__('Missing arguments in request.', 'carbon'), false, ERROR);

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants