Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
fix(fleet): fix ability to delete a maanged fleet
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry authored and DIOHz0r committed Apr 2, 2018
1 parent b7501de commit ff6111b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions inc/fleet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ public function defineTabs($options = []) {
return $tab;
}

function canPurgeItem() {
if ($this->fields['is_default'] == '1') {
return false;
}
return parent::checkEntity();
}

/**
* Show form for edition
* @param $ID
Expand Down Expand Up @@ -461,8 +468,8 @@ public function getFromDBByDefaultForEntity($entityId = null) {
* @param string $entityId ID of the entoty to search in
* @return PluginFlyvemdmFleet|null
*/
public static function getDefaultFleet($entityId = '') {
if ($entityId == '') {
public static function getDefaultFleet($entityId = null) {
if ($entityId === null) {
$entityId = $_SESSION['glpiactive_entity'];
}
$defaultFleet = new PluginFlyvemdmFleet();
Expand Down
7 changes: 7 additions & 0 deletions tests/suite-unit/PluginFlyvemdmFleet.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ public function testGetMenuPicture() {
$this->given($class)->string($class::getMenuPicture())->isEqualTo('fa-group');
}

public function testPurgeteItem() {
$instance = \PluginFlyvemdmFleet::getDefaultFleet(0);
$this->variable($instance)->isNotNull();
$_SESSION['glpiactiveentities'] = [0];
$this->boolean($instance->canPurgeItem())->isFalse();
}

/**
* @tags testShowForm
*/
Expand Down

0 comments on commit ff6111b

Please sign in to comment.