Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivam-nagar23 committed Feb 12, 2024
1 parent 0a8a53e commit 0e50351
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
28 changes: 15 additions & 13 deletions api/auth/user/UserRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,14 @@ func (handler UserRestHandlerImpl) BulkDeleteUsers(w http.ResponseWriter, r *htt
// setting logged in user Id for audit logs
request.LoggedInUserId = userId

// validations for system and admin user
err = helper.CheckValidationForAdminAndSystemUserId(request.Ids)
if err != nil {
handler.logger.Errorw("request err, BulkDeleteUsers, validation failed", "payload", request, "err", err)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}

// RBAC enforcer applying
token := r.Header.Get("token")
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok {
Expand All @@ -479,13 +487,6 @@ func (handler UserRestHandlerImpl) BulkDeleteUsers(w http.ResponseWriter, r *htt
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
// validations for system and admin user
err = helper.CheckValidationForAdminAndSystemUserId(request.Ids)
if err != nil {
handler.logger.Errorw("request err, BulkDeleteUsers, validation failed", "payload", request, "err", err)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
// service call
res, err := handler.userService.BulkDeleteUsers(request)
if err != nil {
Expand Down Expand Up @@ -840,12 +841,6 @@ func (handler UserRestHandlerImpl) BulkDeleteRoleGroups(w http.ResponseWriter, r
// setting logged in user Id for audit logs
request.LoggedInUserId = userId

// RBAC enforcer applying
token := r.Header.Get("token")
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok {
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
return
}
// struct validation
err = handler.validator.Struct(request)
if err != nil {
Expand All @@ -854,6 +849,13 @@ func (handler UserRestHandlerImpl) BulkDeleteRoleGroups(w http.ResponseWriter, r
return
}

// RBAC enforcer applying
token := r.Header.Get("token")
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionGet, "*"); !ok {
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)
return
}

// service call
res, err := handler.roleGroupService.BulkDeleteRoleGroups(request)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/auth/user/RoleGroupService.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ func (impl RoleGroupServiceImpl) deleteRoleGroupsByIds(request *bean.BulkDeleteR
tx, err := impl.roleGroupRepository.StartATransaction()
if err != nil {
impl.logger.Errorw("error in starting a transaction", "err", err)
return err
return &util.ApiError{Code: "500", HttpStatusCode: 500, UserMessage: "error starting a transaction in db", InternalMessage: "error starting a transaction in db"}
}
// Rollback tx on error.
defer tx.Rollback()
Expand Down Expand Up @@ -860,7 +860,7 @@ func (impl RoleGroupServiceImpl) deleteRoleGroupsByIds(request *bean.BulkDeleteR
err = impl.roleGroupRepository.CommitATransaction(tx)
if err != nil {
impl.logger.Errorw("error in committing a transaction in deleteRoleGroupsByIds", "err", err)
return err
return &util.ApiError{Code: "500", HttpStatusCode: 500, UserMessage: "error committing a transaction in db", InternalMessage: "error committing a transaction in db"}
}
return nil

Expand Down

0 comments on commit 0e50351

Please sign in to comment.