@@ -781,6 +781,7 @@ public static function get_tickets_by_user_id(
781781 $ table_support_status = Database::get_main_table (TABLE_TICKET_STATUS );
782782 $ direction = !empty ($ direction ) ? $ direction : 'DESC ' ;
783783 $ userId = !empty ($ userId ) ? $ userId : api_get_user_id ();
784+ $ userInfo = api_get_user_info ($ userId );
784785 $ isAdmin = UserManager::is_admin ($ userId );
785786
786787 if (!isset ($ _GET ['project_id ' ])) {
@@ -841,7 +842,11 @@ public static function get_tickets_by_user_id(
841842 WHERE 1=1
842843 " ;
843844
844- if (!$ isAdmin ) {
845+ $ projectId = (int ) $ _GET ['project_id ' ];
846+ $ userIsAllowInProject = self ::userIsAllowInProject ($ userInfo , $ projectId );
847+
848+ // Check if a role was set to the project
849+ if ($ userIsAllowInProject == false ) {
845850 $ sql .= " AND (ticket.assigned_last_user = $ userId OR ticket.sys_insert_user_id = $ userId ) " ;
846851 }
847852
@@ -980,7 +985,7 @@ public static function get_tickets_by_user_id(
980985
981986 /**
982987 * @param int $userId
983- * @return mixed
988+ * @return int
984989 */
985990 public static function get_total_tickets_by_user_id ($ userId = 0 )
986991 {
@@ -989,7 +994,11 @@ public static function get_total_tickets_by_user_id($userId = 0)
989994 $ table_support_priority = Database::get_main_table (TABLE_TICKET_PRIORITY );
990995 $ table_support_status = Database::get_main_table (TABLE_TICKET_STATUS );
991996
992- $ userId = api_get_user_id ();
997+ $ userInfo = api_get_user_info ();
998+ if (empty ($ userInfo )) {
999+ return 0 ;
1000+ }
1001+ $ userId = $ userInfo ['id ' ];
9931002
9941003 if (!isset ($ _GET ['project_id ' ])) {
9951004 return 0 ;
@@ -1003,10 +1012,20 @@ public static function get_total_tickets_by_user_id($userId = 0)
10031012 ON (ticket.priority_id = priority.id)
10041013 INNER JOIN $ table_support_status status
10051014 ON (ticket.status_id = status.id)
1006- WHERE 1 = 1 " ;
1015+ WHERE 1 = 1 " ;
10071016
1008- if (!api_is_platform_admin ()) {
1009- $ sql .= " AND (ticket.assigned_last_user = $ userId OR ticket.sys_insert_user_id = $ userId ) " ;
1017+ $ projectId = (int ) $ _GET ['project_id ' ];
1018+ $ allowRoleList = self ::getAllowedRolesFromProject ($ projectId );
1019+
1020+ // Check if a role was set to the project
1021+ if (!empty ($ allowRoleList ) && is_array ($ allowRoleList )) {
1022+ if (!in_array ($ userInfo ['status ' ], $ allowRoleList )) {
1023+ $ sql .= " AND (ticket.assigned_last_user = $ userId OR ticket.sys_insert_user_id = $ userId ) " ;
1024+ }
1025+ } else {
1026+ if (!api_is_platform_admin ()) {
1027+ $ sql .= " AND (ticket.assigned_last_user = $ userId OR ticket.sys_insert_user_id = $ userId ) " ;
1028+ }
10101029 }
10111030
10121031 // Search simple
@@ -1066,7 +1085,7 @@ public static function get_total_tickets_by_user_id($userId = 0)
10661085 $ res = Database::query ($ sql );
10671086 $ obj = Database::fetch_object ($ res );
10681087
1069- return $ obj ->total ;
1088+ return ( int ) $ obj ->total ;
10701089 }
10711090
10721091 /**
@@ -1140,10 +1159,8 @@ public static function get_ticket_detail_by_id($ticketId)
11401159 $ webPath = api_get_path (WEB_CODE_PATH );
11411160 while ($ row = Database::fetch_assoc ($ result )) {
11421161 $ message = $ row ;
1143- $ completeName = api_get_person_name ($ row ['firstname ' ], $ row ['lastname ' ]);
1144- $ href = $ webPath .'main/admin/user_information.php?user_id= ' .$ row ['user_id ' ];
11451162 $ message ['admin ' ] = UserManager::is_admin ($ message ['user_id ' ]);
1146- $ message ['user_created ' ] = " <a href=' $ href '> $ completeName </a> " ;
1163+ $ message ['user_info ' ] = api_get_user_info ( $ message [ ' user_id ' ]) ;
11471164 $ sql = "SELECT *
11481165 FROM $ table_support_message_attachments
11491166 WHERE
@@ -2252,4 +2269,45 @@ public static function deleteUserFromTicketSystem($userId)
22522269 Database::query ($ sql );
22532270 }
22542271 }
2272+
2273+ /**
2274+ * @param array $userInfo
2275+ * @param int $projectId
2276+ *
2277+ * @return bool
2278+ */
2279+ public static function userIsAllowInProject ($ userInfo , $ projectId )
2280+ {
2281+ if (api_is_platform_admin ()) {
2282+ return true ;
2283+ }
2284+
2285+ $ allowRoleList = self ::getAllowedRolesFromProject ($ projectId );
2286+
2287+ // Check if a role was set to the project
2288+ if (!empty ($ allowRoleList ) && is_array ($ allowRoleList )) {
2289+ if (in_array ($ userInfo ['status ' ], $ allowRoleList )) {
2290+ return true ;
2291+ }
2292+ }
2293+
2294+ return false ;
2295+ }
2296+
2297+ /**
2298+ * @param int $projectId
2299+ * @todo load from database instead of configuration.php setting
2300+ * @return array
2301+ */
2302+ public static function getAllowedRolesFromProject ($ projectId )
2303+ {
2304+ $ options = api_get_configuration_value ('ticket_project_user_roles ' );
2305+ if ($ options ) {
2306+ if (isset ($ options ['permissions ' ][$ projectId ])) {
2307+ return $ options ['permissions ' ][$ projectId ];
2308+ }
2309+ }
2310+
2311+ return [];
2312+ }
22552313}
0 commit comments