Skip to content

Commit 89df6c9

Browse files
cconard96trasher
authored andcommitted
remove redundant itemantivirus tab ui and checks
1 parent 46ded7e commit 89df6c9

File tree

3 files changed

+27
-64
lines changed

3 files changed

+27
-64
lines changed

src/ItemAntivirus.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -258,26 +258,22 @@ public static function rawSearchOptionsToAdd()
258258
**/
259259
public function showForm($ID, array $options = [])
260260
{
261-
$itemtype = $this->fields['itemtype'];
262-
263-
if (!Session::haveRight($itemtype::$rightname, READ)) {
264-
return false;
265-
}
266-
267-
if (!is_a($itemtype, CommonDBTM::class, true)) {
268-
return false;
261+
if (isset($options['parent'])) {
262+
$options['itemtype'] = $options['parent']::class;
263+
$options['items_id'] = $options['parent']->getID();
269264
}
270265

271-
$asset = new $itemtype();
272266
if ($ID > 0) {
267+
$asset = getItemForItemtype($this->fields['itemtype']);
273268
$this->check($ID, READ);
274269
$asset->getFromDB($this->fields['items_id']);
275270
} else {
271+
$asset = getItemForItemtype($options['itemtype']);
276272
$this->check(-1, CREATE, $options);
277273
$asset->getFromDB($options['items_id']);
278274
}
279275

280-
$options['canedit'] = Session::haveRight($itemtype::$rightname, UPDATE);
276+
$options['canedit'] = $asset->can($asset->getID(), UPDATE);
281277
$this->initForm($ID, $options);
282278
TemplateRenderer::getInstance()->display('components/form/item_antivirus.html.twig', [
283279
'item' => $this,
@@ -323,11 +319,15 @@ private static function showForItem(CommonDBTM $asset, $withtemplate = 0)
323319
]
324320
);
325321

326-
TemplateRenderer::getInstance()->display('components/form/item_antivirus_item.html.twig', [
327-
'canedit' => ($canedit && !(!empty($withtemplate) && ($withtemplate == 2))),
328-
'has_antivirus' => ($result->numrows() != 0),
329-
'antivirus_form_url' => ItemAntivirus::getFormURL() .
330-
"?itemtype=$itemtype&items_id=$ID&withtemplate=" . $withtemplate,
322+
TemplateRenderer::getInstance()->display('components/form/viewsubitem.html.twig', [
323+
'type' => self::class,
324+
'parenttype' => $itemtype,
325+
'items_id' => $asset::getForeignKeyField(),
326+
'id' => $ID,
327+
'cancreate' => ($canedit && !(!empty($withtemplate) && ($withtemplate == 2))),
328+
'add_new_label' => __('Add an antivirus'),
329+
'ajax_form_submit' => true,
330+
'reload_tab' => true,
331331
]);
332332

333333
$antivirus = new self();

templates/components/form/item_antivirus_item.html.twig

Lines changed: 0 additions & 49 deletions
This file was deleted.

tests/cypress/e2e/Asset/computer.cy.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,16 @@ describe("Computer asset form", () => {
6464
cy.findAllByRole('cell').contains('Test VM').should('be.visible');
6565
});
6666
});
67+
68+
it('Antivirus tab loads', () => {
69+
cy.visit(`/front/computer.form.php?id=${computers_id}`);
70+
cy.findByRole('tab', { name: /Antiviruses/ }).click();
71+
cy.findByRole('tabpanel').within(() => {
72+
cy.findByRole('cell').should('contain.text', 'No results found');
73+
cy.findByRole('button', {name: 'Add an antivirus'}).click();
74+
cy.findByRole('textbox', { name: 'Name' }).type('Test AV');
75+
cy.findByRole('button', {name: 'Add'}).click();
76+
cy.findAllByRole('cell').contains('Test AV').should('be.visible');
77+
});
78+
});
6779
});

0 commit comments

Comments
 (0)