@@ -19,6 +19,7 @@ package restHandler
19
19
import (
20
20
"encoding/json"
21
21
"fmt"
22
+ bean4 "github.com/devtron-labs/devtron/pkg/auth/user/bean"
22
23
"github.com/devtron-labs/devtron/pkg/build/git/gitMaterial/repository"
23
24
"github.com/devtron-labs/devtron/pkg/build/git/gitProvider"
24
25
"github.com/devtron-labs/devtron/pkg/bulkAction/bean"
@@ -212,9 +213,14 @@ func (handler BulkUpdateRestHandlerImpl) CheckAuthForBulkUpdate(AppId int, EnvId
212
213
213
214
}
214
215
func (handler BulkUpdateRestHandlerImpl ) BulkUpdate (w http.ResponseWriter , r * http.Request ) {
216
+ userId , err := handler .userAuthService .GetLoggedInUser (r )
217
+ if userId == 0 || err != nil {
218
+ common .WriteJsonResp (w , err , "Unauthorized User" , http .StatusUnauthorized )
219
+ return
220
+ }
215
221
decoder := json .NewDecoder (r .Body )
216
222
var script bean.BulkUpdateScript
217
- err : = decoder .Decode (& script )
223
+ err = decoder .Decode (& script )
218
224
if err != nil {
219
225
common .WriteJsonResp (w , err , nil , http .StatusBadRequest )
220
226
return
@@ -250,8 +256,18 @@ func (handler BulkUpdateRestHandlerImpl) BulkUpdate(w http.ResponseWriter, r *ht
250
256
common .WriteJsonResp (w , fmt .Errorf ("unauthorized user" ), "Unauthorized User" , http .StatusForbidden )
251
257
}
252
258
}
253
-
254
- response := handler .bulkUpdateService .BulkUpdate (script .Spec )
259
+ isSuperAdmin := handler .enforcer .Enforce (token , casbin .ResourceGlobal , casbin .ActionCreate , "*" )
260
+ userEmail , err := handler .userAuthService .GetActiveEmailById (userId )
261
+ if err != nil {
262
+ common .WriteJsonResp (w , fmt .Errorf ("userEmail not found by userId" ), "userEmail not found by userId" , http .StatusNotFound )
263
+ return
264
+ }
265
+ userMetadata := & bean4.UserMetadata {
266
+ UserEmailId : userEmail ,
267
+ IsUserSuperAdmin : isSuperAdmin ,
268
+ UserId : userId ,
269
+ }
270
+ response := handler .bulkUpdateService .BulkUpdate (script .Spec , userMetadata )
255
271
common .WriteJsonResp (w , nil , response , http .StatusOK )
256
272
}
257
273
@@ -261,7 +277,19 @@ func (handler BulkUpdateRestHandlerImpl) BulkHibernate(w http.ResponseWriter, r
261
277
return // response already written by the helper on error.
262
278
}
263
279
token := r .Header .Get ("token" )
264
- response , err := handler .bulkUpdateService .BulkHibernate (request , r .Context (), w , token , handler .checkAuthForBulkHibernateAndUnhibernate )
280
+ isSuperAdmin := handler .enforcer .Enforce (token , casbin .ResourceGlobal , casbin .ActionCreate , "*" )
281
+ userEmail , err := handler .userAuthService .GetActiveEmailById (request .UserId )
282
+ if err != nil {
283
+ common .WriteJsonResp (w , fmt .Errorf ("userEmail not found by userId" ), "userEmail not found by userId" , http .StatusNotFound )
284
+ return
285
+ }
286
+ userMetadata := & bean4.UserMetadata {
287
+ UserEmailId : userEmail ,
288
+ IsUserSuperAdmin : isSuperAdmin ,
289
+ UserId : request .UserId ,
290
+ }
291
+
292
+ response , err := handler .bulkUpdateService .BulkHibernate (r .Context (), request , token , handler .checkAuthForBulkHibernateAndUnhibernate , userMetadata )
265
293
if err != nil {
266
294
common .WriteJsonResp (w , err , nil , http .StatusInternalServerError )
267
295
return
@@ -298,7 +326,18 @@ func (handler BulkUpdateRestHandlerImpl) BulkUnHibernate(w http.ResponseWriter,
298
326
return // response already written by the helper on error.
299
327
}
300
328
token := r .Header .Get ("token" )
301
- response , err := handler .bulkUpdateService .BulkUnHibernate (request , r .Context (), w , token , handler .checkAuthForBulkHibernateAndUnhibernate )
329
+ isSuperAdmin := handler .enforcer .Enforce (token , casbin .ResourceGlobal , casbin .ActionCreate , "*" )
330
+ userEmail , err := handler .userAuthService .GetActiveEmailById (request .UserId )
331
+ if err != nil {
332
+ common .WriteJsonResp (w , fmt .Errorf ("userEmail not found by userId" ), "userEmail not found by userId" , http .StatusNotFound )
333
+ return
334
+ }
335
+ userMetadata := & bean4.UserMetadata {
336
+ UserEmailId : userEmail ,
337
+ IsUserSuperAdmin : isSuperAdmin ,
338
+ UserId : request .UserId ,
339
+ }
340
+ response , err := handler .bulkUpdateService .BulkUnHibernate (r .Context (), request , token , handler .checkAuthForBulkHibernateAndUnhibernate , userMetadata )
302
341
if err != nil {
303
342
common .WriteJsonResp (w , err , nil , http .StatusInternalServerError )
304
343
return
@@ -326,7 +365,18 @@ func (handler BulkUpdateRestHandlerImpl) BulkDeploy(w http.ResponseWriter, r *ht
326
365
common .WriteJsonResp (w , err , nil , http .StatusBadRequest )
327
366
return
328
367
}
329
- response , err := handler .bulkUpdateService .BulkDeploy (& request , token , handler .checkAuthBatch )
368
+ isSuperAdmin := handler .enforcer .Enforce (token , casbin .ResourceGlobal , casbin .ActionCreate , "*" )
369
+ userEmail , err := handler .userAuthService .GetActiveEmailById (userId )
370
+ if err != nil {
371
+ common .WriteJsonResp (w , fmt .Errorf ("userEmail not found by userId" ), "userEmail not found by userId" , http .StatusNotFound )
372
+ return
373
+ }
374
+ userMetadata := & bean4.UserMetadata {
375
+ UserEmailId : userEmail ,
376
+ IsUserSuperAdmin : isSuperAdmin ,
377
+ UserId : userId ,
378
+ }
379
+ response , err := handler .bulkUpdateService .BulkDeploy (& request , token , handler .checkAuthBatch , userMetadata )
330
380
if err != nil {
331
381
common .WriteJsonResp (w , err , nil , http .StatusInternalServerError )
332
382
return
0 commit comments