Skip to content

Commit a6b4f19

Browse files
committed
feat(issue): access tickets from service catalog
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
1 parent 49b70a1 commit a6b4f19

File tree

3 files changed

+266
-13
lines changed

3 files changed

+266
-13
lines changed

hook.php

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function plugin_formcreator_addDefaultJoin($itemtype, $ref_table, &$already_link
102102
$ref_table,
103103
$already_link_tables,
104104
$issueSo[9]['table'],
105-
'users_id_validator',
105+
$issueSo[9]['linkfield'],
106106
0,
107107
0,
108108
$issueSo[9]['joinparams']
@@ -112,7 +112,7 @@ function plugin_formcreator_addDefaultJoin($itemtype, $ref_table, &$already_link
112112
$ref_table,
113113
$already_link_tables,
114114
$issueSo[11]['table'],
115-
'users_id_validate',
115+
$issueSo[11]['linkfield'],
116116
0,
117117
0,
118118
$issueSo[11]['joinparams']
@@ -122,11 +122,41 @@ function plugin_formcreator_addDefaultJoin($itemtype, $ref_table, &$already_link
122122
$ref_table,
123123
$already_link_tables,
124124
$issueSo[16]['table'],
125-
'groups_id_validator',
125+
$issueSo[16]['linkfield'],
126126
0,
127127
0,
128128
$issueSo[16]['joinparams']
129129
);
130+
$join .= Search::addLeftJoin(
131+
$itemtype,
132+
$ref_table,
133+
$already_link_tables,
134+
$issueSo[42]['table'],
135+
$issueSo[42]['linkfield'],
136+
0,
137+
0,
138+
$issueSo[42]['joinparams']
139+
);
140+
$join .= Search::addLeftJoin(
141+
$itemtype,
142+
$ref_table,
143+
$already_link_tables,
144+
$issueSo[43]['table'],
145+
$issueSo[43]['linkfield'],
146+
0,
147+
0,
148+
$issueSo[43]['joinparams']
149+
);
150+
$join .= Search::addLeftJoin(
151+
$itemtype,
152+
$ref_table,
153+
$already_link_tables,
154+
$issueSo[44]['table'],
155+
$issueSo[44]['linkfield'],
156+
0,
157+
0,
158+
$issueSo[44]['joinparams']
159+
);
130160
}
131161
break;
132162

@@ -185,6 +215,19 @@ function plugin_formcreator_addDefaultWhere($itemtype) {
185215
// condition where current user is a validator of a issue of type ticket
186216
$complexJoinId = Search::computeComplexJoinID($issueSearchOptions[11]['joinparams']);
187217
$condition .= " OR `glpi_users_users_id_validate_$complexJoinId`.`id` = '$currentUser'";
218+
219+
// condition where the current user is a requester of a ticket linked to a form answer typed issue
220+
$complexJoinId = Search::computeComplexJoinID($issueSearchOptions[42]['joinparams']);
221+
$condition .= " OR `glpi_users_$complexJoinId`.`id` = '$currentUser'";
222+
223+
// condition where the current user is a watcher of a ticket linked to a form answer typed issue
224+
$complexJoinId = Search::computeComplexJoinID($issueSearchOptions[43]['joinparams']);
225+
$condition .= " OR `glpi_users_$complexJoinId`.`id` = '$currentUser'";
226+
227+
// condition where the current user is assigned of a ticket linked to a form answer typed issue
228+
$complexJoinId = Search::computeComplexJoinID($issueSearchOptions[44]['joinparams']);
229+
$condition .= " OR `glpi_users_$complexJoinId`.`id` = '$currentUser'";
230+
188231
// Add users_id_recipient
189232
$condition .= " OR `glpi_plugin_formcreator_issues`.`users_id_recipient` = $currentUser ";
190233
return "($condition)";

inc/formanswer.class.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,40 @@ public function canViewItem() {
164164
}
165165
}
166166

167+
// Check if the current user is a requester of a ticket linked to a form answer typed
168+
// Matches search option 42, 43 and 44 of PluginFormcreatorIssue (requester, watcher, assigned)
169+
$ticket_table = Ticket::getTable();
170+
$ticket_user_table = Ticket_User::getTable();
171+
$item_ticket_table = Item_Ticket::getTable();
172+
$request = [
173+
'SELECT' => Ticket_User::getTableField(User::getForeignKeyField()),
174+
'FROM' => $ticket_user_table,
175+
'INNER JOIN' => [
176+
$ticket_table => [
177+
'FKEY' => [
178+
$ticket_table => 'id',
179+
$ticket_user_table => 'tickets_id',
180+
],
181+
],
182+
$item_ticket_table => [
183+
'FKEY' => [
184+
$item_ticket_table => 'tickets_id',
185+
$ticket_table => 'id',
186+
['AND' => [
187+
Item_Ticket::getTableField('itemtype') => self::getType(),
188+
]],
189+
],
190+
],
191+
192+
]
193+
];
194+
195+
foreach ($DB->request($request) as $row) {
196+
if ($row[User::getForeignKeyField()] == $currentUser) {
197+
return true;
198+
}
199+
}
200+
167201
return false;
168202
}
169203

inc/issue.class.php

Lines changed: 186 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,8 @@ public function getTicketsForDisplay($options) {
472472
$item = $ticket;
473473
}
474474
} else {
475-
// multiple tickets, ticket specified, then substitute the ticket to the form answer
476475
if (isset($options['tickets_id'])) {
476+
// multiple tickets, ticket specified, then substitute the ticket to the form answer
477477
$ticket = Ticket::getById((int) $options['tickets_id']);
478478
if ($ticket) {
479479
$item = $ticket;
@@ -645,17 +645,50 @@ public function rawSearchOptions() {
645645
'massiveaction' => false,
646646
'joinparams' => [
647647
'beforejoin' => [
648-
'table' => TicketValidation::getTable(),
649-
'joinparams' => [
650-
'jointype' => 'child',
651-
'beforejoin' => [
652-
'table' => Ticket::getTable(),
653-
'joinparams' => [
654-
'jointype' => 'itemtype_item_revert',
655-
'specific_itemtype' => Ticket::class,
648+
[
649+
'table' => TicketValidation::getTable(),
650+
'joinparams' => [
651+
'jointype' => 'child',
652+
'beforejoin' => [
653+
'table' => Ticket::getTable(),
654+
'joinparams' => [
655+
'jointype' => 'itemtype_item_revert',
656+
'specific_itemtype' => Ticket::class,
657+
]
656658
]
657659
]
658-
]
660+
],
661+
[
662+
'table' => TicketValidation::getTable(),
663+
'joinparams' => [
664+
'jointype' => 'child',
665+
'beforejoin' => [
666+
'table' => Ticket::getTable(),
667+
'joinparams' => [
668+
'jointype' => 'empty',
669+
'condition' => [
670+
new \QueryExpression(
671+
'1=1'
672+
),
673+
],
674+
'beforejoin' => [
675+
'table' => Item_Ticket::getTable(),
676+
'joinparams' => [
677+
'jointype' => 'itemtype_item',
678+
'specific_itemtype' => PluginFormcreatorFormAnswer::class,
679+
'beforejoin' => [
680+
'table' => PluginFormcreatorFormAnswer::getTable(),
681+
'joinparams' => [
682+
'jointype' => 'itemtype_item_revert',
683+
'specific_itemtype' => PluginFormcreatorFormAnswer::class,
684+
],
685+
],
686+
],
687+
],
688+
],
689+
]
690+
]
691+
],
659692
],
660693
]
661694
];
@@ -800,6 +833,149 @@ public function rawSearchOptions() {
800833
}
801834
}
802835

836+
$tab[] = [
837+
'id' => '42',
838+
'table' => User::getTable(),
839+
'field' => 'name',
840+
'name' => __('Ticket requester', 'formcreator'),
841+
'massiveaction' => false,
842+
'datatype' => 'dropdown',
843+
'forcegroupby' => true,
844+
'joinparams' => [
845+
'jointype' => 'empty',
846+
'beforejoin' => [
847+
'table' => Ticket_User::getTable(),
848+
'joinparams' => [
849+
'jointype' => 'child',
850+
'condition' => [
851+
'NEWTABLE.type' => CommonITILActor::REQUESTER,
852+
],
853+
'beforejoin' => [
854+
'table' => Ticket::getTable(),
855+
'joinparams' => [
856+
'jointype' => 'empty',
857+
'condition' => [
858+
new \QueryExpression(
859+
'1=1'
860+
),
861+
],
862+
'beforejoin' => [
863+
'table' => Item_Ticket::getTable(),
864+
'joinparams' => [
865+
'jointype' => 'itemtype_item',
866+
'specific_itemtype' => PluginFormcreatorFormAnswer::class,
867+
'beforejoin' => [
868+
'table' => PluginFormcreatorFormAnswer::getTable(),
869+
'joinparams' => [
870+
'jointype' => 'itemtype_item_revert',
871+
'specific_itemtype' => PluginFormcreatorFormAnswer::class,
872+
],
873+
],
874+
],
875+
],
876+
],
877+
],
878+
],
879+
],
880+
],
881+
];
882+
883+
$tab[] = [
884+
'id' => '43',
885+
'table' => User::getTable(),
886+
'field' => 'name',
887+
'name' => __('Ticket observer', 'formcreator'),
888+
'massiveaction' => false,
889+
'nosearch' => true,
890+
'datatype' => 'dropdown',
891+
'forcegroupby' => true,
892+
'joinparams' => [
893+
'jointype' => 'empty',
894+
'beforejoin' => [
895+
'table' => Ticket_User::getTable(),
896+
'joinparams' => [
897+
'jointype' => 'child',
898+
'condition' => [
899+
'NEWTABLE.type' => CommonITILActor::OBSERVER,
900+
],
901+
'beforejoin' => [
902+
'table' => Ticket::getTable(),
903+
'joinparams' => [
904+
'jointype' => 'empty',
905+
'condition' => [
906+
new \QueryExpression(
907+
'1=1'
908+
),
909+
],
910+
'beforejoin' => [
911+
'table' => Item_Ticket::getTable(),
912+
'joinparams' => [
913+
'jointype' => 'itemtype_item',
914+
'specific_itemtype' => PluginFormcreatorFormAnswer::class,
915+
'beforejoin' => [
916+
'table' => PluginFormcreatorFormAnswer::getTable(),
917+
'joinparams' => [
918+
'jointype' => 'itemtype_item_revert',
919+
'specific_itemtype' => PluginFormcreatorFormAnswer::class,
920+
],
921+
],
922+
],
923+
],
924+
],
925+
],
926+
],
927+
],
928+
],
929+
];
930+
931+
$tab[] = [
932+
'id' => '44',
933+
'table' => User::getTable(),
934+
'field' => 'name',
935+
'name' => __('Ticket technician', 'formcreator'),
936+
'massiveaction' => false,
937+
'nosearch' => true,
938+
'datatype' => 'dropdown',
939+
'forcegroupby' => true,
940+
'joinparams' => [
941+
'jointype' => 'empty',
942+
'beforejoin' => [
943+
'table' => Ticket_User::getTable(),
944+
'joinparams' => [
945+
'jointype' => 'child',
946+
'condition' => [
947+
'NEWTABLE.type' => CommonITILActor::ASSIGN,
948+
],
949+
'beforejoin' => [
950+
'table' => Ticket::getTable(),
951+
'joinparams' => [
952+
'jointype' => 'empty',
953+
'condition' => [
954+
new \QueryExpression(
955+
'1=1'
956+
),
957+
],
958+
'beforejoin' => [
959+
'table' => Item_Ticket::getTable(),
960+
'joinparams' => [
961+
'jointype' => 'itemtype_item',
962+
'specific_itemtype' => PluginFormcreatorFormAnswer::class,
963+
'beforejoin' => [
964+
'table' => PluginFormcreatorFormAnswer::getTable(),
965+
'joinparams' => [
966+
'jointype' => 'itemtype_item_revert',
967+
'specific_itemtype' => PluginFormcreatorFormAnswer::class,
968+
],
969+
],
970+
],
971+
],
972+
],
973+
],
974+
],
975+
],
976+
],
977+
];
978+
803979
return $tab;
804980
}
805981

0 commit comments

Comments
 (0)