@@ -65,6 +65,32 @@ public function getItopUrl(string $userId): string {
6565 return $ this ->config ->getUserValue ($ userId , Application::APP_ID , 'url ' ) ?: $ adminItopUrl ;
6666 }
6767
68+ /**
69+ * Build ticket URL based on user's portal access level
70+ *
71+ * Portal-only users get portal URLs (/pages/exec.php/object/edit/...)
72+ * Power users (agents/admins) get admin UI URLs (/pages/UI.php?operation=details...)
73+ *
74+ * @param string $userId Nextcloud user ID
75+ * @param string $class iTop class (UserRequest, Incident, etc.)
76+ * @param string $id Ticket ID
77+ * @return string Full ticket URL
78+ */
79+ private function buildTicketUrl (string $ userId , string $ class , string $ id ): string {
80+ $ itopUrl = $ this ->getItopUrl ($ userId );
81+
82+ // Check if user is portal-only (cached by ProfileService)
83+ $ isPortalOnly = $ this ->config ->getUserValue ($ userId , Application::APP_ID , 'is_portal_only ' , '0 ' ) === '1 ' ;
84+
85+ if ($ isPortalOnly ) {
86+ // Portal user - use portal URL format
87+ return $ itopUrl . '/pages/exec.php/object/edit/ ' . $ class . '/ ' . $ id . '?exec_module=itop-portal-base&exec_page=index.php&portal_id=itop-portal ' ;
88+ } else {
89+ // Power user - use admin UI URL format
90+ return $ itopUrl . '/pages/UI.php?operation=details&class= ' . $ class . '&id= ' . $ id ;
91+ }
92+ }
93+
6894 /**
6995 * Get application token for API requests
7096 *
@@ -245,7 +271,7 @@ public function getUserCreatedTickets(string $userId, ?string $since = null, ?in
245271 'start_date ' => $ ticket ['fields ' ]['start_date ' ] ?? '' ,
246272 'last_update ' => $ ticket ['fields ' ]['last_update ' ] ?? '' ,
247273 'close_date ' => $ ticket ['fields ' ]['close_date ' ] ?? '' ,
248- 'url ' => $ itopUrl . ' /pages/UI.php?operation=details&class= UserRequest&id= ' . $ ticketId
274+ 'url ' => $ this -> buildTicketUrl ( $ userId , ' UserRequest ' , $ ticketId)
249275 ];
250276 }
251277 }
@@ -290,7 +316,7 @@ public function getUserCreatedTickets(string $userId, ?string $since = null, ?in
290316 'start_date ' => $ ticket ['fields ' ]['start_date ' ] ?? '' ,
291317 'last_update ' => $ ticket ['fields ' ]['last_update ' ] ?? '' ,
292318 'close_date ' => $ ticket ['fields ' ]['close_date ' ] ?? '' ,
293- 'url ' => $ itopUrl . ' /pages/UI.php?operation=details&class= Incident&id= ' . $ ticketId
319+ 'url ' => $ this -> buildTicketUrl ( $ userId , ' Incident ' , $ ticketId)
294320 ];
295321 }
296322 }
@@ -562,7 +588,7 @@ public function search(string $userId, string $query, int $offset = 0, int $limi
562588 'start_date ' => $ ticket ['fields ' ]['start_date ' ] ?? '' ,
563589 'last_update ' => $ ticket ['fields ' ]['last_update ' ] ?? '' ,
564590 'close_date ' => $ ticket ['fields ' ]['close_date ' ] ?? '' ,
565- 'url ' => $ itopUrl . ' /pages/UI.php?operation=details&class= UserRequest&id= ' . $ ticket ['fields ' ]['id ' ]
591+ 'url ' => $ this -> buildTicketUrl ( $ userId , ' UserRequest ' , $ ticket ['fields ' ]['id ' ])
566592 ];
567593 }
568594 }
@@ -601,7 +627,7 @@ public function search(string $userId, string $query, int $offset = 0, int $limi
601627 'start_date ' => $ ticket ['fields ' ]['start_date ' ] ?? '' ,
602628 'last_update ' => $ ticket ['fields ' ]['last_update ' ] ?? '' ,
603629 'close_date ' => $ ticket ['fields ' ]['close_date ' ] ?? '' ,
604- 'url ' => $ itopUrl . ' /pages/UI.php?operation=details&class= Incident&id= ' . $ ticket ['fields ' ]['id ' ]
630+ 'url ' => $ this -> buildTicketUrl ( $ userId , ' Incident ' , $ ticket ['fields ' ]['id ' ])
605631 ];
606632 }
607633 }
@@ -658,7 +684,7 @@ public function search(string $userId, string $query, int $offset = 0, int $limi
658684 'start_date ' => $ ticket ['fields ' ]['start_date ' ] ?? '' ,
659685 'last_update ' => $ ticket ['fields ' ]['last_update ' ] ?? '' ,
660686 'close_date ' => $ ticket ['fields ' ]['close_date ' ] ?? '' ,
661- 'url ' => $ itopUrl . ' /pages/UI.php?operation=details&class= ' . $ ticketClass . ' &id= ' . $ ticket ['fields ' ]['id ' ]
687+ 'url ' => $ this -> buildTicketUrl ( $ userId , $ ticketClass, $ ticket ['fields ' ]['id ' ])
662688 ];
663689 }
664690 }
@@ -1246,7 +1272,7 @@ public function getMyAssignedTickets(string $userId, int $limit = 20): array {
12461272 'team ' => $ ticket ['fields ' ]['team_id_friendlyname ' ] ?? '' ,
12471273 'start_date ' => $ ticket ['fields ' ]['start_date ' ] ?? '' ,
12481274 'last_update ' => $ ticket ['fields ' ]['last_update ' ] ?? '' ,
1249- 'url ' => $ itopUrl . ' /pages/UI.php?operation=details&class= UserRequest&id= ' . $ ticketId
1275+ 'url ' => $ this -> buildTicketUrl ( $ userId , ' UserRequest ' , $ ticketId)
12501276 ];
12511277 }
12521278 }
@@ -1277,7 +1303,7 @@ public function getMyAssignedTickets(string $userId, int $limit = 20): array {
12771303 'team ' => $ ticket ['fields ' ]['team_id_friendlyname ' ] ?? '' ,
12781304 'start_date ' => $ ticket ['fields ' ]['start_date ' ] ?? '' ,
12791305 'last_update ' => $ ticket ['fields ' ]['last_update ' ] ?? '' ,
1280- 'url ' => $ itopUrl . ' /pages/UI.php?operation=details&class= Incident&id= ' . $ ticketId
1306+ 'url ' => $ this -> buildTicketUrl ( $ userId , ' Incident ' , $ ticketId)
12811307 ];
12821308 }
12831309 }
@@ -1336,7 +1362,7 @@ public function getTeamAssignedTickets(string $userId, int $limit = 20): array {
13361362 'team ' => $ ticket ['fields ' ]['team_id_friendlyname ' ] ?? '' ,
13371363 'start_date ' => $ ticket ['fields ' ]['start_date ' ] ?? '' ,
13381364 'last_update ' => $ ticket ['fields ' ]['last_update ' ] ?? '' ,
1339- 'url ' => $ itopUrl . ' /pages/UI.php?operation=details&class= UserRequest&id= ' . $ ticketId
1365+ 'url ' => $ this -> buildTicketUrl ( $ userId , ' UserRequest ' , $ ticketId)
13401366 ];
13411367 }
13421368 }
@@ -1367,7 +1393,7 @@ public function getTeamAssignedTickets(string $userId, int $limit = 20): array {
13671393 'team ' => $ ticket ['fields ' ]['team_id_friendlyname ' ] ?? '' ,
13681394 'start_date ' => $ ticket ['fields ' ]['start_date ' ] ?? '' ,
13691395 'last_update ' => $ ticket ['fields ' ]['last_update ' ] ?? '' ,
1370- 'url ' => $ itopUrl . ' /pages/UI.php?operation=details&class= Incident&id= ' . $ ticketId
1396+ 'url ' => $ this -> buildTicketUrl ( $ userId , ' Incident ' , $ ticketId)
13711397 ];
13721398 }
13731399 }
@@ -1434,7 +1460,7 @@ public function getEscalatedTicketsForMyTeams(string $userId, int $limit = 20):
14341460 'team ' => $ ticket ['fields ' ]['team_id_friendlyname ' ] ?? '' ,
14351461 'start_date ' => $ ticket ['fields ' ]['start_date ' ] ?? '' ,
14361462 'last_update ' => $ ticket ['fields ' ]['last_update ' ] ?? '' ,
1437- 'url ' => $ itopUrl . ' /pages/UI.php?operation=details&class= UserRequest&id= ' . $ ticketId
1463+ 'url ' => $ this -> buildTicketUrl ( $ userId , ' UserRequest ' , $ ticketId)
14381464 ];
14391465 }
14401466 }
@@ -1465,7 +1491,7 @@ public function getEscalatedTicketsForMyTeams(string $userId, int $limit = 20):
14651491 'team ' => $ ticket ['fields ' ]['team_id_friendlyname ' ] ?? '' ,
14661492 'start_date ' => $ ticket ['fields ' ]['start_date ' ] ?? '' ,
14671493 'last_update ' => $ ticket ['fields ' ]['last_update ' ] ?? '' ,
1468- 'url ' => $ itopUrl . ' /pages/UI.php?operation=details&class= Incident&id= ' . $ ticketId
1494+ 'url ' => $ this -> buildTicketUrl ( $ userId , ' Incident ' , $ ticketId)
14691495 ];
14701496 }
14711497 }
@@ -1521,7 +1547,7 @@ public function getUpcomingChanges(string $userId, int $limit = 10): array {
15211547 'last_update ' => $ change ['fields ' ]['last_update ' ] ?? '' ,
15221548 'operational_status ' => $ change ['fields ' ]['operational_status ' ] ?? '' ,
15231549 'finalclass ' => $ finalclass ,
1524- 'url ' => $ itopUrl . ' /pages/UI.php?operation=details&class= ' . $ finalclass . ' &id= ' . $ changeId
1550+ 'url ' => $ this -> buildTicketUrl ( $ userId , $ finalclass, $ changeId)
15251551 ];
15261552 }
15271553 }
0 commit comments