@@ -1189,7 +1189,24 @@ router.put('/:botId/users/:userId', authorize('management:edit'), async (req, re
11891189router . post ( '/start-all' , authorize ( 'bot:start_stop' ) , async ( req , res ) => {
11901190 try {
11911191 console . log ( '[API] Получен запрос на запуск всех ботов.' ) ;
1192- const allBots = await prisma . bot . findMany ( { include : { server : true , proxy : true } } ) ;
1192+
1193+ // Определяем фильтр доступа по ботам для пользователя
1194+ let whereFilter = { } ;
1195+ if ( req . user && typeof req . user . userId === 'number' ) {
1196+ const panelUser = await prisma . panelUser . findUnique ( {
1197+ where : { id : req . user . userId } ,
1198+ include : { botAccess : { select : { botId : true } } }
1199+ } ) ;
1200+ if ( panelUser && panelUser . allBots === false ) {
1201+ const allowedIds = panelUser . botAccess . map ( a => a . botId ) ;
1202+ whereFilter = { id : { in : allowedIds . length ? allowedIds : [ - 1 ] } } ;
1203+ }
1204+ }
1205+
1206+ const allBots = await prisma . bot . findMany ( {
1207+ where : whereFilter ,
1208+ include : { server : true , proxy : true }
1209+ } ) ;
11931210 let startedCount = 0 ;
11941211 for ( const botConfig of allBots ) {
11951212 if ( ! botManager . bots . has ( botConfig . id ) ) {
@@ -1204,12 +1221,29 @@ router.post('/start-all', authorize('bot:start_stop'), async (req, res) => {
12041221 }
12051222} ) ;
12061223
1207- router . post ( '/stop-all' , authorize ( 'bot:start_stop' ) , ( req , res ) => {
1224+ router . post ( '/stop-all' , authorize ( 'bot:start_stop' ) , async ( req , res ) => {
12081225 try {
12091226 console . log ( '[API] Получен запрос на остановку всех ботов.' ) ;
1227+
1228+ // Определяем фильтр доступа по ботам для пользователя
1229+ let allowedBotIds = null ;
1230+ if ( req . user && typeof req . user . userId === 'number' ) {
1231+ const panelUser = await prisma . panelUser . findUnique ( {
1232+ where : { id : req . user . userId } ,
1233+ include : { botAccess : { select : { botId : true } } }
1234+ } ) ;
1235+ if ( panelUser && panelUser . allBots === false ) {
1236+ allowedBotIds = new Set ( panelUser . botAccess . map ( a => a . botId ) ) ;
1237+ }
1238+ }
1239+
12101240 const botIds = Array . from ( botManager . bots . keys ( ) ) ;
12111241 let stoppedCount = 0 ;
12121242 for ( const botId of botIds ) {
1243+ // Если у пользователя есть ограничения, проверяем доступ
1244+ if ( allowedBotIds !== null && ! allowedBotIds . has ( botId ) ) {
1245+ continue ;
1246+ }
12131247 botManager . stopBot ( botId ) ;
12141248 stoppedCount ++ ;
12151249 }
0 commit comments