Skip to content

Commit

Permalink
simplify tests + add missing trait / SO
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed May 22, 2024
1 parent bb82ab1 commit d1524fc
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 68 deletions.
1 change: 0 additions & 1 deletion src/Api/HL/Controller/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
use Glpi\Api\HL\Middleware\ResultFormatterMiddleware;
use Glpi\Api\HL\Route;
use Glpi\Api\HL\Search;
use Glpi\Features\AssignableItem;
use Glpi\Http\JSONResponse;
use Glpi\Http\Request;
use Glpi\Http\Response;
Expand Down
52 changes: 52 additions & 0 deletions src/Cable.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
/// Class Cable
class Cable extends CommonDBTM
{
use Glpi\Features\AssignableItem;
use Glpi\Features\Clonable;
use Glpi\Features\State;

Expand Down Expand Up @@ -271,6 +272,35 @@ public function rawSearchOptions()
'datatype' => 'text'
];

$tab[] = [
'id' => '70',
'table' => 'glpi_users',
'field' => 'name',
'name' => User::getTypeName(1),
'datatype' => 'dropdown',
'right' => 'all'
];

$tab[] = [
'id' => '71',
'table' => 'glpi_groups',
'field' => 'completename',
'name' => Group::getTypeName(1),
'condition' => ['is_itemgroup' => 1],
'joinparams' => [
'beforejoin' => [
'table' => 'glpi_groups_items',
'joinparams' => [
'jointype' => 'itemtype_item',
'condition' => ['NEWTABLE.type' => Group_Item::GROUP_TYPE_NORMAL]
]
]
],
'forcegroupby' => true,
'massiveaction' => false,
'datatype' => 'dropdown'
];

$tab[] = [
'id' => '19',
'table' => $this->getTable(),
Expand All @@ -286,6 +316,28 @@ public function rawSearchOptions()
'field' => 'name',
'linkfield' => 'users_id_tech',
'name' => __('Technician in charge'),
'datatype' => 'dropdown',
'right' => 'own_ticket'
];

$tab[] = [
'id' => '49',
'table' => 'glpi_groups',
'field' => 'completename',
'linkfield' => 'groups_id',
'name' => __('Group in charge'),
'condition' => ['is_assign' => 1],
'joinparams' => [
'beforejoin' => [
'table' => 'glpi_groups_items',
'joinparams' => [
'jointype' => 'itemtype_item',
'condition' => ['NEWTABLE.type' => Group_Item::GROUP_TYPE_TECH]
]
]
],
'forcegroupby' => true,
'massiveaction' => false,
'datatype' => 'dropdown'
];

Expand Down
2 changes: 1 addition & 1 deletion src/CommonDBTM.php
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ public function cleanRelationTable()
*/
global $CFG_GLPI, $DB;

if (Toolbox::hasTrait(static::class, AssignableItem::class)) {
if (in_array(static::class, $CFG_GLPI['assignable_types'], true)) {
$group_item = new Group_Item();
$group_item->deleteByCriteria(
[
Expand Down
48 changes: 47 additions & 1 deletion src/PDU.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
**/
class PDU extends CommonDBTM
{
use Glpi\Features\AssignableItem {
prepareInputForAdd as prepareInputForAddAssignableItem;
}
use Glpi\Features\DCBreadcrumb;
use Glpi\Features\Clonable;
use Glpi\Features\State;
Expand Down Expand Up @@ -127,6 +130,35 @@ public function rawSearchOptions()
'datatype' => 'text'
];

$tab[] = [
'id' => '70',
'table' => 'glpi_users',
'field' => 'name',
'name' => User::getTypeName(1),
'datatype' => 'dropdown',
'right' => 'all'
];

$tab[] = [
'id' => '71',
'table' => 'glpi_groups',
'field' => 'completename',
'name' => Group::getTypeName(1),
'condition' => ['is_itemgroup' => 1],
'joinparams' => [
'beforejoin' => [
'table' => 'glpi_groups_items',
'joinparams' => [
'jointype' => 'itemtype_item',
'condition' => ['NEWTABLE.type' => Group_Item::GROUP_TYPE_NORMAL]
]
]
],
'forcegroupby' => true,
'massiveaction' => false,
'datatype' => 'dropdown'
];

$tab[] = [
'id' => '19',
'table' => $this->getTable(),
Expand Down Expand Up @@ -175,9 +207,20 @@ public function rawSearchOptions()
'id' => '49',
'table' => 'glpi_groups',
'field' => 'completename',
'linkfield' => 'groups_id_tech',
'linkfield' => 'groups_id',
'name' => __('Group in charge'),
'condition' => ['is_assign' => 1],
'joinparams' => [
'beforejoin' => [
'table' => 'glpi_groups_items',
'joinparams' => [
'jointype' => 'itemtype_item',
'condition' => ['NEWTABLE.type' => Group_Item::GROUP_TYPE_TECH]
]
]
],
'forcegroupby' => true,
'massiveaction' => false,
'datatype' => 'dropdown'
];

Expand Down Expand Up @@ -244,6 +287,9 @@ public function prepareInputForAdd($input)
}
unset($input['id']);
unset($input['withtemplate']);

$input = $this->prepareInputForAddAssignableItem($input);

return $input;
}
}
46 changes: 43 additions & 3 deletions src/PassiveDCEquipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
* ---------------------------------------------------------------------
*/

use Glpi\Features\Clonable;
use Glpi\Socket;

/**
* PassiveDCEquipment Class
**/
class PassiveDCEquipment extends CommonDBTM
{
use Clonable;
use Glpi\Features\AssignableItem;
use Glpi\Features\Clonable;
use Glpi\Features\DCBreadcrumb;
use Glpi\Features\State;

Expand Down Expand Up @@ -124,6 +124,35 @@ public function rawSearchOptions()

$tab = array_merge($tab, Location::rawSearchOptionsToAdd());

$tab[] = [
'id' => '70',
'table' => 'glpi_users',
'field' => 'name',
'name' => User::getTypeName(1),
'datatype' => 'dropdown',
'right' => 'all'
];

$tab[] = [
'id' => '71',
'table' => 'glpi_groups',
'field' => 'completename',
'name' => Group::getTypeName(1),
'condition' => ['is_itemgroup' => 1],
'joinparams' => [
'beforejoin' => [
'table' => 'glpi_groups_items',
'joinparams' => [
'jointype' => 'itemtype_item',
'condition' => ['NEWTABLE.type' => Group_Item::GROUP_TYPE_NORMAL]
]
]
],
'forcegroupby' => true,
'massiveaction' => false,
'datatype' => 'dropdown'
];

$tab[] = [
'id' => '19',
'table' => $this->getTable(),
Expand Down Expand Up @@ -172,9 +201,20 @@ public function rawSearchOptions()
'id' => '49',
'table' => 'glpi_groups',
'field' => 'completename',
'linkfield' => 'groups_id_tech',
'linkfield' => 'groups_id',
'name' => __('Group in charge'),
'condition' => ['is_assign' => 1],
'joinparams' => [
'beforejoin' => [
'table' => 'glpi_groups_items',
'joinparams' => [
'jointype' => 'itemtype_item',
'condition' => ['NEWTABLE.type' => Group_Item::GROUP_TYPE_TECH]
]
]
],
'forcegroupby' => true,
'massiveaction' => false,
'datatype' => 'dropdown'
];

Expand Down
4 changes: 2 additions & 2 deletions src/Search/Provider/SQLProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3044,7 +3044,7 @@ public static function getMetaLeftJoinCriteria(string $from_type, string $to_typ
return $joins;
}

if ($to_type === 'Group' && Toolbox::hasTrait($from_referencetype, AssignableItem::class)) {
if ($to_type === 'Group' && in_array($from_referencetype, $CFG_GLPI['assignable_types'], true)) {
$relation_table_alias = 'glpi_groups_items' . $alias_suffix;
if (!in_array($relation_table_alias, $already_link_tables2, true)) {
$already_link_tables2[] = $relation_table_alias;
Expand Down Expand Up @@ -3076,7 +3076,7 @@ public static function getMetaLeftJoinCriteria(string $from_type, string $to_typ
return $joins;
}

if ($from_referencetype === 'Group' && Toolbox::hasTrait($to_type, AssignableItem::class)) {
if ($from_referencetype === 'Group' && in_array($to_type, $CFG_GLPI['assignable_types'], true)) {
$relation_table_alias = 'glpi_groups_items' . $alias_suffix;
if (!in_array($relation_table_alias, $already_link_tables2, true)) {
$already_link_tables2[] = $relation_table_alias;
Expand Down
7 changes: 0 additions & 7 deletions tests/functional/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
use Document;
use Document_Item;
use Glpi\Asset\Capacity\HasDocumentsCapacity;
use Glpi\Features\AssignableItem;
use Group_User;
use Psr\Log\LogLevel;
use Ticket;
Expand Down Expand Up @@ -1901,21 +1900,15 @@ public function testAllAssetsFields()
'users_id',
'contact',
'contact_num',
'groups_id',
'date_mod',
'manufacturers_id',
'groups_id_tech',
'entities_id',
];

foreach ($CFG_GLPI["asset_types"] as $itemtype) {
$table = getTableForItemType($itemtype);

foreach ($needed_fields as $field) {
if (\Toolbox::hasTrait($itemtype, AssignableItem::class) && str_starts_with($field, 'groups_id')) {
// The group fields don't exist in the main table for these assets
continue;
}
$this->boolean($DB->fieldExists($table, $field))
->isTrue("$table.$field is missing");
}
Expand Down

0 comments on commit d1524fc

Please sign in to comment.