@@ -1793,6 +1793,38 @@ public static function findContainer($itemtype, $type = 'tab', $subtype = '')
17931793 return $ id ;
17941794 }
17951795
1796+ public static function findAllContainers ($ itemtype )
1797+ {
1798+ $ condition = ['is_active ' => 1 ];
1799+
1800+ $ entity = $ _SESSION ['glpiactiveentities ' ] ?? 0 ;
1801+ $ condition += getEntitiesRestrictCriteria ('' , '' , $ entity , true , true );
1802+
1803+ $ container = new PluginFieldsContainer ();
1804+ $ itemtypes = $ container ->find ($ condition );
1805+
1806+ if (empty ($ itemtypes )) {
1807+ return false ;
1808+ }
1809+
1810+ $ ids = [];
1811+ foreach ($ itemtypes as $ data ) {
1812+ $ dataitemtypes = PluginFieldsToolbox::decodeJSONItemtypes ($ data ['itemtypes ' ]);
1813+ if (in_array ($ itemtype , $ dataitemtypes )) {
1814+ $ id = $ data ['id ' ];
1815+ //profiles restriction
1816+ if (isset ($ _SESSION ['glpiactiveprofile ' ]['id ' ]) && $ _SESSION ['glpiactiveprofile ' ]['id ' ] != null && $ id > 0 ) {
1817+ $ right = PluginFieldsProfile::getRightOnContainer ($ _SESSION ['glpiactiveprofile ' ]['id ' ], $ id );
1818+ if ($ right >= READ ) {
1819+ $ ids [] = $ id ;
1820+ }
1821+ }
1822+ }
1823+ }
1824+
1825+ return $ ids ;
1826+ }
1827+
17961828 /**
17971829 * Post item hook for add
17981830 * Do store data in db
@@ -1889,14 +1921,15 @@ public static function preItem(CommonDBTM $item)
18891921 $ loc_c ->getFromDB ($ c_id );
18901922
18911923 // check rights on $c_id
1892-
1924+ // The profile check is only enforced when an active user profile is present in session.
1925+ // Automated contexts (cron jobs, API token sessions without profile) bypass the check
1926+ // so that plugin fields can still be persisted — authentication is already enforced
1927+ // at a higher level by the GLPI API/cron layer.
18931928 if (isset ($ _SESSION ['glpiactiveprofile ' ]['id ' ]) && $ _SESSION ['glpiactiveprofile ' ]['id ' ] != null && $ c_id > 0 ) {
18941929 $ right = PluginFieldsProfile::getRightOnContainer ($ _SESSION ['glpiactiveprofile ' ]['id ' ], $ c_id );
18951930 if (($ right > READ ) === false ) {
18961931 return false ;
18971932 }
1898- } else {
1899- return false ;
19001933 }
19011934
19021935
@@ -2217,8 +2250,11 @@ public static function getAddSearchOptions($itemtype, $containers_id = false)
22172250 $ opt [$ i ]['datatype ' ] = 'specific ' ;
22182251 $ opt [$ i ]['searchtype ' ] = ['equals ' , 'notequals ' ];
22192252 } else {
2220- $ opt [$ i ]['table ' ] = CommonDBTM::getTable ($ dropdown_matches ['class ' ]);
2221- $ opt [$ i ]['field ' ] = 'name ' ;
2253+ $ opt [$ i ]['table ' ] = getTableForItemType ($ dropdown_matches ['class ' ]);
2254+ $ opt [$ i ]['field ' ] = is_a ($ dropdown_matches ['class ' ], CommonTreeDropdown::class, true )
2255+ ? 'completename '
2256+ : 'name ' ;
2257+ $ opt [$ i ]['itemtype ' ] = $ dropdown_matches ['class ' ];
22222258 $ opt [$ i ]['right ' ] = 'all ' ;
22232259 $ opt [$ i ]['datatype ' ] = 'dropdown ' ;
22242260
0 commit comments