@@ -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,41 @@ 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+ $ request = [
237+ 'SELECT ' => [
238+ TicketValidation::getTableField (User::getForeignKeyField () . '_validate ' ),
239+ Ticket::getTableField ('id ' ),
240+ ],
241+ 'FROM ' => $ ticketvalidation_table ,
242+ 'INNER JOIN ' => [
243+ $ ticket_table => [
244+ 'FKEY ' => [
245+ $ ticket_table => 'id ' ,
246+ $ ticketvalidation_table => 'tickets_id ' ,
247+ ['AND ' => [
248+ TicketValidation::getTableField (User::getForeignKeyField () . '_validate ' ) => $ currentUser ,
249+ ]],
250+ ],
251+ ],
252+ ]
253+ ];
254+
255+ if ($ DB ->request ($ request )->count () > 0 ) {
256+ return true ;
257+ }
258+
259+ return false ;
260+
261+ }
262+
211263 public static function canPurge () {
212264 return true ;
213265 }
@@ -581,6 +633,12 @@ public function showForm($ID, $options = []) {
581633 if (!isset ($ ID ) || !$ this ->getFromDB ($ ID )) {
582634 Html::displayNotFoundError ();
583635 }
636+
637+ if ($ this ->canViewItem () && !$ this ->userIsTicketActor ()) {
638+ echo '<div class="alert alert-danger"> ' . __ ('You are not allowed to view this answer. ' ) . '</div> ' ;
639+ return false ;
640+ }
641+
584642 $ options ['canedit ' ] = false ;
585643
586644 // Print css media
0 commit comments