@@ -167,6 +167,23 @@ public function canViewItem() {
167167 }
168168 }
169169
170+ if ($ this ->userIsTicketActor ()) {
171+ return true ;
172+ }
173+
174+
175+ if ($ this ->userIsTicketValidator ()) {
176+ return true ;
177+ }
178+
179+ return false ;
180+ }
181+
182+ public function userIsTicketActor (): bool {
183+ global $ DB ;
184+
185+ $ currentUser = Session::getLoginUserID ();
186+
170187 // Check if the current user is a requester of a ticket linked to a form answer typed
171188 // Matches search option 42, 43 and 44 of PluginFormcreatorIssue (requester, watcher, assigned)
172189 $ ticket_table = Ticket::getTable ();
@@ -208,6 +225,52 @@ public function canViewItem() {
208225 return false ;
209226 }
210227
228+ public function userIsTicketValidator (): bool {
229+ global $ DB ;
230+
231+ $ currentUser = Session::getLoginUserID ();
232+
233+ // Check if the current user is a validator of a ticket linked to a form answer typed
234+ $ ticket_table = Ticket::getTable ();
235+ $ ticketvalidation_table = TicketValidation::getTable ();
236+ $ item_ticket_table = Item_Ticket::getTable ();
237+ $ request = [
238+ 'SELECT ' => [
239+ TicketValidation::getTableField (User::getForeignKeyField () . '_validate ' ),
240+ Ticket::getTableField ('id ' ),
241+ ],
242+ 'FROM ' => $ ticketvalidation_table ,
243+ 'INNER JOIN ' => [
244+ $ ticket_table => [
245+ 'FKEY ' => [
246+ $ ticket_table => 'id ' ,
247+ $ ticketvalidation_table => 'tickets_id ' ,
248+ ['AND ' => [
249+ TicketValidation::getTableField (User::getForeignKeyField () . '_validate ' ) => $ currentUser ,
250+ ]],
251+ ],
252+ ],
253+ $ item_ticket_table => [
254+ 'FKEY ' => [
255+ $ item_ticket_table => 'tickets_id ' ,
256+ $ ticket_table => 'id ' ,
257+ ['AND ' => [
258+ Item_Ticket::getTableField ('itemtype ' ) => self ::getType (),
259+ Item_Ticket::getTableField ('items_id ' ) => $ this ->getID (),
260+ ]],
261+ ],
262+ ],
263+ ]
264+ ];
265+
266+ if ($ DB ->request ($ request )->count () > 0 ) {
267+ return true ;
268+ }
269+
270+ return false ;
271+
272+ }
273+
211274 public static function canPurge () {
212275 return true ;
213276 }
@@ -581,6 +644,12 @@ public function showForm($ID, $options = []) {
581644 if (!isset ($ ID ) || !$ this ->getFromDB ($ ID )) {
582645 Html::displayNotFoundError ();
583646 }
647+
648+ if ($ this ->canViewItem () && !$ this ->userIsTicketActor ()) {
649+ echo '<div class="alert alert-danger"> ' . __ ('You are not allowed to view this answer. ' ) . '</div> ' ;
650+ return false ;
651+ }
652+
584653 $ options ['canedit ' ] = false ;
585654
586655 // Print css media
0 commit comments