Skip to content

Commit

Permalink
feat(issue): access tickets from service catalog
Browse files Browse the repository at this point in the history
when a form generates several tickets and a service catalog user is added to one of those tickets, the user needs
to access the form answer then access the ticket
  • Loading branch information
btry committed Jan 13, 2023
1 parent 49b70a1 commit a6b4f19
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 13 deletions.
49 changes: 46 additions & 3 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function plugin_formcreator_addDefaultJoin($itemtype, $ref_table, &$already_link
$ref_table,
$already_link_tables,
$issueSo[9]['table'],
'users_id_validator',
$issueSo[9]['linkfield'],
0,
0,
$issueSo[9]['joinparams']
Expand All @@ -112,7 +112,7 @@ function plugin_formcreator_addDefaultJoin($itemtype, $ref_table, &$already_link
$ref_table,
$already_link_tables,
$issueSo[11]['table'],
'users_id_validate',
$issueSo[11]['linkfield'],
0,
0,
$issueSo[11]['joinparams']
Expand All @@ -122,11 +122,41 @@ function plugin_formcreator_addDefaultJoin($itemtype, $ref_table, &$already_link
$ref_table,
$already_link_tables,
$issueSo[16]['table'],
'groups_id_validator',
$issueSo[16]['linkfield'],
0,
0,
$issueSo[16]['joinparams']
);
$join .= Search::addLeftJoin(
$itemtype,
$ref_table,
$already_link_tables,
$issueSo[42]['table'],
$issueSo[42]['linkfield'],
0,
0,
$issueSo[42]['joinparams']
);
$join .= Search::addLeftJoin(
$itemtype,
$ref_table,
$already_link_tables,
$issueSo[43]['table'],
$issueSo[43]['linkfield'],
0,
0,
$issueSo[43]['joinparams']
);
$join .= Search::addLeftJoin(
$itemtype,
$ref_table,
$already_link_tables,
$issueSo[44]['table'],
$issueSo[44]['linkfield'],
0,
0,
$issueSo[44]['joinparams']
);
}
break;

Expand Down Expand Up @@ -185,6 +215,19 @@ function plugin_formcreator_addDefaultWhere($itemtype) {
// condition where current user is a validator of a issue of type ticket
$complexJoinId = Search::computeComplexJoinID($issueSearchOptions[11]['joinparams']);
$condition .= " OR `glpi_users_users_id_validate_$complexJoinId`.`id` = '$currentUser'";

// condition where the current user is a requester of a ticket linked to a form answer typed issue
$complexJoinId = Search::computeComplexJoinID($issueSearchOptions[42]['joinparams']);
$condition .= " OR `glpi_users_$complexJoinId`.`id` = '$currentUser'";

// condition where the current user is a watcher of a ticket linked to a form answer typed issue
$complexJoinId = Search::computeComplexJoinID($issueSearchOptions[43]['joinparams']);
$condition .= " OR `glpi_users_$complexJoinId`.`id` = '$currentUser'";

// condition where the current user is assigned of a ticket linked to a form answer typed issue
$complexJoinId = Search::computeComplexJoinID($issueSearchOptions[44]['joinparams']);
$condition .= " OR `glpi_users_$complexJoinId`.`id` = '$currentUser'";

// Add users_id_recipient
$condition .= " OR `glpi_plugin_formcreator_issues`.`users_id_recipient` = $currentUser ";
return "($condition)";
Expand Down
34 changes: 34 additions & 0 deletions inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,40 @@ public function canViewItem() {
}
}

// Check if the current user is a requester of a ticket linked to a form answer typed
// Matches search option 42, 43 and 44 of PluginFormcreatorIssue (requester, watcher, assigned)
$ticket_table = Ticket::getTable();
$ticket_user_table = Ticket_User::getTable();
$item_ticket_table = Item_Ticket::getTable();
$request = [
'SELECT' => Ticket_User::getTableField(User::getForeignKeyField()),
'FROM' => $ticket_user_table,
'INNER JOIN' => [
$ticket_table => [
'FKEY' => [
$ticket_table => 'id',
$ticket_user_table => 'tickets_id',
],
],
$item_ticket_table => [
'FKEY' => [
$item_ticket_table => 'tickets_id',
$ticket_table => 'id',
['AND' => [
Item_Ticket::getTableField('itemtype') => self::getType(),
]],
],
],

]
];

foreach ($DB->request($request) as $row) {
if ($row[User::getForeignKeyField()] == $currentUser) {
return true;
}
}

return false;
}

Expand Down
196 changes: 186 additions & 10 deletions inc/issue.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ public function getTicketsForDisplay($options) {
$item = $ticket;
}
} else {
// multiple tickets, ticket specified, then substitute the ticket to the form answer
if (isset($options['tickets_id'])) {
// multiple tickets, ticket specified, then substitute the ticket to the form answer
$ticket = Ticket::getById((int) $options['tickets_id']);
if ($ticket) {
$item = $ticket;
Expand Down Expand Up @@ -645,17 +645,50 @@ public function rawSearchOptions() {
'massiveaction' => false,
'joinparams' => [
'beforejoin' => [
'table' => TicketValidation::getTable(),
'joinparams' => [
'jointype' => 'child',
'beforejoin' => [
'table' => Ticket::getTable(),
'joinparams' => [
'jointype' => 'itemtype_item_revert',
'specific_itemtype' => Ticket::class,
[
'table' => TicketValidation::getTable(),
'joinparams' => [
'jointype' => 'child',
'beforejoin' => [
'table' => Ticket::getTable(),
'joinparams' => [
'jointype' => 'itemtype_item_revert',
'specific_itemtype' => Ticket::class,
]
]
]
]
],
[
'table' => TicketValidation::getTable(),
'joinparams' => [
'jointype' => 'child',
'beforejoin' => [
'table' => Ticket::getTable(),
'joinparams' => [
'jointype' => 'empty',
'condition' => [
new \QueryExpression(
'1=1'
),
],
'beforejoin' => [
'table' => Item_Ticket::getTable(),
'joinparams' => [
'jointype' => 'itemtype_item',
'specific_itemtype' => PluginFormcreatorFormAnswer::class,
'beforejoin' => [
'table' => PluginFormcreatorFormAnswer::getTable(),
'joinparams' => [
'jointype' => 'itemtype_item_revert',
'specific_itemtype' => PluginFormcreatorFormAnswer::class,
],
],
],
],
],
]
]
],
],
]
];
Expand Down Expand Up @@ -800,6 +833,149 @@ public function rawSearchOptions() {
}
}

$tab[] = [
'id' => '42',
'table' => User::getTable(),
'field' => 'name',
'name' => __('Ticket requester', 'formcreator'),
'massiveaction' => false,
'datatype' => 'dropdown',
'forcegroupby' => true,
'joinparams' => [
'jointype' => 'empty',
'beforejoin' => [
'table' => Ticket_User::getTable(),
'joinparams' => [
'jointype' => 'child',
'condition' => [
'NEWTABLE.type' => CommonITILActor::REQUESTER,
],
'beforejoin' => [
'table' => Ticket::getTable(),
'joinparams' => [
'jointype' => 'empty',
'condition' => [
new \QueryExpression(
'1=1'
),
],
'beforejoin' => [
'table' => Item_Ticket::getTable(),
'joinparams' => [
'jointype' => 'itemtype_item',
'specific_itemtype' => PluginFormcreatorFormAnswer::class,
'beforejoin' => [
'table' => PluginFormcreatorFormAnswer::getTable(),
'joinparams' => [
'jointype' => 'itemtype_item_revert',
'specific_itemtype' => PluginFormcreatorFormAnswer::class,
],
],
],
],
],
],
],
],
],
];

$tab[] = [
'id' => '43',
'table' => User::getTable(),
'field' => 'name',
'name' => __('Ticket observer', 'formcreator'),
'massiveaction' => false,
'nosearch' => true,
'datatype' => 'dropdown',
'forcegroupby' => true,
'joinparams' => [
'jointype' => 'empty',
'beforejoin' => [
'table' => Ticket_User::getTable(),
'joinparams' => [
'jointype' => 'child',
'condition' => [
'NEWTABLE.type' => CommonITILActor::OBSERVER,
],
'beforejoin' => [
'table' => Ticket::getTable(),
'joinparams' => [
'jointype' => 'empty',
'condition' => [
new \QueryExpression(
'1=1'
),
],
'beforejoin' => [
'table' => Item_Ticket::getTable(),
'joinparams' => [
'jointype' => 'itemtype_item',
'specific_itemtype' => PluginFormcreatorFormAnswer::class,
'beforejoin' => [
'table' => PluginFormcreatorFormAnswer::getTable(),
'joinparams' => [
'jointype' => 'itemtype_item_revert',
'specific_itemtype' => PluginFormcreatorFormAnswer::class,
],
],
],
],
],
],
],
],
],
];

$tab[] = [
'id' => '44',
'table' => User::getTable(),
'field' => 'name',
'name' => __('Ticket technician', 'formcreator'),
'massiveaction' => false,
'nosearch' => true,
'datatype' => 'dropdown',
'forcegroupby' => true,
'joinparams' => [
'jointype' => 'empty',
'beforejoin' => [
'table' => Ticket_User::getTable(),
'joinparams' => [
'jointype' => 'child',
'condition' => [
'NEWTABLE.type' => CommonITILActor::ASSIGN,
],
'beforejoin' => [
'table' => Ticket::getTable(),
'joinparams' => [
'jointype' => 'empty',
'condition' => [
new \QueryExpression(
'1=1'
),
],
'beforejoin' => [
'table' => Item_Ticket::getTable(),
'joinparams' => [
'jointype' => 'itemtype_item',
'specific_itemtype' => PluginFormcreatorFormAnswer::class,
'beforejoin' => [
'table' => PluginFormcreatorFormAnswer::getTable(),
'joinparams' => [
'jointype' => 'itemtype_item_revert',
'specific_itemtype' => PluginFormcreatorFormAnswer::class,
],
],
],
],
],
],
],
],
],
];

return $tab;
}

Expand Down

0 comments on commit a6b4f19

Please sign in to comment.