fixed infinity context in admin req #18

Merged
romanskijdev merged 1 commits from test-deploy into main 2026-06-18 16:43:16 +03:00
14 changed files with 65 additions and 93 deletions

View File

@ -45,15 +45,14 @@ func (s *ApprovalStepsReg) GetApprovalStepsListHandler(w http.ResponseWriter, r
LikeFields: likeFields,
}
ctx := context.Background()
stepsDbLst, total, errW := s.ipc.Database.ApprovalStep.GetApprovalStepsListDB(ctx, options)
stepsDbLst, total, errW := s.ipc.Database.ApprovalStep.GetApprovalStepsListDB(r.Context(), options)
if errW != nil {
return nil, errW
}
// 🚀 Подгружаем связанные данные
for _, step := range stepsDbLst {
s.enrichStep(ctx, step, false)
s.enrichStep(r.Context(), step, false)
}
return &typescore.ApiResponseBase{
@ -85,8 +84,7 @@ func (s *ApprovalStepsReg) GetApprovalStepByIDHandler(w http.ResponseWriter, r *
return nil, errors.New("invalid step id")
}
ctx := context.Background()
steps, _, err := s.ipc.Database.ApprovalStep.GetApprovalStepsListDB(ctx, typescore.ListDbOptions{
steps, _, err := s.ipc.Database.ApprovalStep.GetApprovalStepsListDB(r.Context(), typescore.ListDbOptions{
Filtering: &typescore.ApprovalStep{ID: &id},
})
if err != nil {
@ -97,7 +95,7 @@ func (s *ApprovalStepsReg) GetApprovalStepByIDHandler(w http.ResponseWriter, r *
}
step := steps[0]
s.enrichStep(ctx, step, true)
s.enrichStep(r.Context(), step, true)
return step, nil
}
@ -125,10 +123,8 @@ func (s *ApprovalStepsReg) GetStepsByApprovalIDHandler(w http.ResponseWriter, r
return nil, errors.New("invalid approval_id")
}
ctx := context.Background()
// Проверяем, что заявка существует
approval, err := s.ipc.Database.Approval.GetApprovalByIDDB(ctx, approvalID)
approval, err := s.ipc.Database.Approval.GetApprovalByIDDB(r.Context(), approvalID)
if err != nil {
return nil, err
}
@ -136,7 +132,7 @@ func (s *ApprovalStepsReg) GetStepsByApprovalIDHandler(w http.ResponseWriter, r
return nil, errors.New("approval not found")
}
steps, _, err := s.ipc.Database.ApprovalStep.GetApprovalStepsListDB(ctx, typescore.ListDbOptions{
steps, _, err := s.ipc.Database.ApprovalStep.GetApprovalStepsListDB(r.Context(), typescore.ListDbOptions{
Filtering: &typescore.ApprovalStep{ApprovalID: &approvalID},
})
if err != nil {
@ -148,7 +144,7 @@ func (s *ApprovalStepsReg) GetStepsByApprovalIDHandler(w http.ResponseWriter, r
// Подгружаем связанные данные
for _, step := range steps {
s.enrichStep(ctx, step, false)
s.enrichStep(r.Context(), step, false)
}
return &typescore.ApiResponseBase{
@ -194,7 +190,7 @@ func (s *ApprovalStepsReg) CreateApprovalStepHandler(w http.ResponseWriter, r *h
return nil, errors.New("step_order is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем существование заявки
approval, err := s.ipc.Database.Approval.GetApprovalByIDDB(ctx, *req.ApprovalID)
@ -278,7 +274,7 @@ func (s *ApprovalStepsReg) UpdateApprovalStepHandler(w http.ResponseWriter, r *h
return nil, errors.New("step id is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем, что шаг существует
existingSteps, _, err := s.ipc.Database.ApprovalStep.GetApprovalStepsListDB(ctx, typescore.ListDbOptions{
@ -340,7 +336,7 @@ func (s *ApprovalStepsReg) DeleteApprovalStepHandler(w http.ResponseWriter, r *h
return nil, errors.New("step id is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем, что шаг существует
existingSteps, _, err := s.ipc.Database.ApprovalStep.GetApprovalStepsListDB(ctx, typescore.ListDbOptions{

View File

@ -35,7 +35,7 @@ func (s *ApprovalTasksReg) GetApprovalTasksListHandler(w http.ResponseWriter, r
LikeFields: likeFields,
}
ctx := context.Background()
ctx := r.Context()
tasks, total, errW := s.ipc.Database.ApprovalTasks.GetApprovalTasksListDB(ctx, options)
if errW != nil {
return nil, errW
@ -64,7 +64,7 @@ func (s *ApprovalTasksReg) GetApprovalTaskByIDHandler(w http.ResponseWriter, r *
return nil, errors.New("invalid task id")
}
ctx := context.Background()
ctx := r.Context()
task, err := s.ipc.Database.ApprovalTasks.GetApprovalTaskByIDDB(ctx, id)
if err != nil {
return nil, err
@ -97,7 +97,7 @@ func (s *ApprovalTasksReg) UpdateApprovalTaskHandler(w http.ResponseWriter, r *h
return nil, errors.New("task id is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем существование
existingTask, err := s.ipc.Database.ApprovalTasks.GetApprovalTaskByIDDB(ctx, *req.ID)
@ -146,7 +146,7 @@ func (s *ApprovalTasksReg) DeleteApprovalTaskHandler(w http.ResponseWriter, r *h
return nil, errors.New("task id is required")
}
ctx := context.Background()
ctx := r.Context()
err = s.ipc.Database.ApprovalTasks.DeleteApprovalTaskDB(ctx, &req)
if err != nil {
return nil, err

View File

@ -58,7 +58,7 @@ func (s *ApprovalsReg) GetApprovalsListHandler(w http.ResponseWriter, r *http.Re
LikeFields: likeFields,
}
ctx := context.Background()
ctx := r.Context()
var approvalsDbLst []*typescore.Approval
var total uint64
@ -111,7 +111,7 @@ func (s *ApprovalsReg) GetApprovalByIDHandler(w http.ResponseWriter, r *http.Req
return nil, errors.New("invalid approval id")
}
ctx := context.Background()
ctx := r.Context()
approval, err := s.ipc.Database.Approval.GetApprovalByIDDB(ctx, id)
if err != nil {
return nil, err
@ -156,7 +156,7 @@ func (s *ApprovalsReg) UpdateApprovalHandler(w http.ResponseWriter, r *http.Requ
return nil, errors.New("approval id is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем, что заявка существует
existingApproval, err := s.ipc.Database.Approval.GetApprovalByIDDB(ctx, *req.ID)
@ -215,7 +215,7 @@ func (s *ApprovalsReg) DeleteApprovalHandler(w http.ResponseWriter, r *http.Requ
return nil, errors.New("approval id is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем, что заявка существует
existingApproval, err := s.ipc.Database.Approval.GetApprovalByIDDB(ctx, *req.ID)
@ -289,7 +289,7 @@ func (s *ApprovalsReg) GetApprovalsForReportHandler(w http.ResponseWriter, r *ht
filter.AllAccess = true
}
ctx := context.Background()
ctx := r.Context()
approvals, err := s.ipc.Database.Approval.GetApprovalsForReportDB(ctx, filter)
if err != nil {
return nil, err

View File

@ -10,7 +10,7 @@ import (
// GetDashboardStatsHandler — возвращает все данные для дашборда одним запросом
func (s *DashboardReg) GetDashboardStatsHandler(w http.ResponseWriter, r *http.Request) (interface{}, error) {
ctx := context.Background()
ctx := r.Context()
// === 1. KPI: считаем сущности ===
totalUsers := s.countUsers(ctx, &typescore.User{})

View File

@ -3,7 +3,6 @@ package departmentshandler
import (
"bitrix_balancer_api/core/typescore"
"bitrix_balancer_api/core/utilscore"
"context"
"encoding/json"
"errors"
"github.com/sirupsen/logrus"
@ -43,7 +42,7 @@ func (s *DepartmentsReg) GetDepartmentsListHandler(w http.ResponseWriter, r *htt
LikeFields: likeFields,
}
ctx := context.Background()
ctx := r.Context()
departmentsDbLst, total, errW := s.ipc.Database.Department.GetDepartmentsListDB(ctx, options)
if errW != nil {
return nil, errW
@ -78,7 +77,7 @@ func (s *DepartmentsReg) GetDepartmentByIDHandler(w http.ResponseWriter, r *http
return nil, errors.New("invalid department id")
}
ctx := context.Background()
ctx := r.Context()
department, err := s.ipc.Database.Department.GetDepartmentByIDDB(ctx, id)
if err != nil {
return nil, err
@ -125,7 +124,7 @@ func (s *DepartmentsReg) CreateDepartmentHandler(w http.ResponseWriter, r *http.
}
// Проверяем, что код уникален
ctx := context.Background()
ctx := r.Context()
existingDepts, _, err := s.ipc.Database.Department.GetDepartmentsListDB(ctx, typescore.ListDbOptions{
Filtering: &typescore.Department{Code: req.Code},
})
@ -181,7 +180,7 @@ func (s *DepartmentsReg) UpdateDepartmentHandler(w http.ResponseWriter, r *http.
}
// Проверяем, что отдел существует
ctx := context.Background()
ctx := r.Context()
existingDept, err := s.ipc.Database.Department.GetDepartmentByIDDB(ctx, *req.ID)
if err != nil {
return nil, err
@ -244,7 +243,7 @@ func (s *DepartmentsReg) DeleteDepartmentHandler(w http.ResponseWriter, r *http.
}
// Проверяем, что отдел существует
ctx := context.Background()
ctx := r.Context()
existingDept, err := s.ipc.Database.Department.GetDepartmentByIDDB(ctx, *req.ID)
if err != nil {
return nil, err

View File

@ -20,24 +20,6 @@ import (
"github.com/sirupsen/logrus"
)
func BasicAuthMiddleware(username, password string) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user, pass, ok := r.BasicAuth()
if !ok || !validateCredentials(user, pass, username, password) {
w.Header().Set("WWW-Authenticate", `Basic realm="Restricted"`)
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
}
next.ServeHTTP(w, r)
})
}
}
func validateCredentials(username, password, validUsername, validPassword string) bool {
return username == validUsername && password == validPassword
}
// JWTVerifier middleware для проверки JWT токена и соответствия IP
func JWTVerifier(cfg *configcore.Config, adminDB dbcore.AdminDBI, redisModule *redismodule.ModuleRedis) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {

View File

@ -46,7 +46,7 @@ func (s *PermissionsReg) GetPermissionsListHandler(w http.ResponseWriter, r *htt
LikeFields: likeFields,
}
ctx := context.Background()
ctx := r.Context()
permissionsDbLst, total, errW := s.ipc.Database.Permission.GetPermissionsListDB(ctx, options)
if errW != nil {
return nil, errW
@ -86,7 +86,7 @@ func (s *PermissionsReg) GetPermissionByIDHandler(w http.ResponseWriter, r *http
return nil, errors.New("invalid permission id")
}
ctx := context.Background()
ctx := r.Context()
permissions, _, err := s.ipc.Database.Permission.GetPermissionsListDB(ctx, typescore.ListDbOptions{
Filtering: &typescore.Permission{ID: &id},
})
@ -126,7 +126,7 @@ func (s *PermissionsReg) GetPermissionsByRoleIDHandler(w http.ResponseWriter, r
return nil, errors.New("invalid role_id")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем, что роль существует
role, err := s.ipc.Database.Role.GetRoleByIDDB(ctx, roleID)
@ -195,7 +195,7 @@ func (s *PermissionsReg) CreatePermissionHandler(w http.ResponseWriter, r *http.
return nil, errors.New("invalid action: must be one of create, read, update, delete, approve, revoke, observe")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем существование роли
role, err := s.ipc.Database.Role.GetRoleByIDDB(ctx, *req.RoleID)
@ -291,7 +291,7 @@ func (s *PermissionsReg) UpdatePermissionHandler(w http.ResponseWriter, r *http.
return nil, errors.New("permission id is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем, что право существует
existingPermissions, _, err := s.ipc.Database.Permission.GetPermissionsListDB(ctx, typescore.ListDbOptions{
@ -400,7 +400,7 @@ func (s *PermissionsReg) DeletePermissionHandler(w http.ResponseWriter, r *http.
return nil, errors.New("permission id is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем, что право существует
existingPermissions, _, err := s.ipc.Database.Permission.GetPermissionsListDB(ctx, typescore.ListDbOptions{

View File

@ -3,7 +3,6 @@ package roleshandler
import (
"bitrix_balancer_api/core/typescore"
"bitrix_balancer_api/core/utilscore"
"context"
"encoding/json"
"errors"
"github.com/sirupsen/logrus"
@ -42,7 +41,7 @@ func (s *RolesReg) GetRolesListHandler(w http.ResponseWriter, r *http.Request) (
LikeFields: likeFields,
}
ctx := context.Background()
ctx := r.Context()
rolesDbLst, total, errW := s.ipc.Database.Role.GetRolesListDB(ctx, options)
if errW != nil {
return nil, errW
@ -77,7 +76,7 @@ func (s *RolesReg) GetRoleByIDHandler(w http.ResponseWriter, r *http.Request) (i
return nil, errors.New("invalid role id")
}
ctx := context.Background()
ctx := r.Context()
role, err := s.ipc.Database.Role.GetRoleByIDDB(ctx, id)
if err != nil {
return nil, err
@ -124,7 +123,7 @@ func (s *RolesReg) CreateRoleHandler(w http.ResponseWriter, r *http.Request) (in
}
// Проверяем, что код уникален
ctx := context.Background()
ctx := r.Context()
existingRoles, _, err := s.ipc.Database.Role.GetRolesListDB(ctx, typescore.ListDbOptions{
Filtering: &typescore.Role{Code: req.Code},
})
@ -196,7 +195,7 @@ func (s *RolesReg) UpdateRoleHandler(w http.ResponseWriter, r *http.Request) (in
}
// Проверяем, что роль существует
ctx := context.Background()
ctx := r.Context()
existingRole, err := s.ipc.Database.Role.GetRoleByIDDB(ctx, *req.ID)
if err != nil {
return nil, err
@ -259,7 +258,7 @@ func (s *RolesReg) DeleteRoleHandler(w http.ResponseWriter, r *http.Request) (in
}
// Проверяем, что роль существует
ctx := context.Background()
ctx := r.Context()
existingRole, err := s.ipc.Database.Role.GetRoleByIDDB(ctx, *req.ID)
if err != nil {
return nil, err

View File

@ -3,7 +3,6 @@ package categorieshandler
import (
"bitrix_balancer_api/core/typescore"
"bitrix_balancer_api/core/utilscore"
"context"
"encoding/json"
"errors"
"github.com/sirupsen/logrus"
@ -43,7 +42,7 @@ func (s *CategoriesReg) GetCategoriesListHandler(w http.ResponseWriter, r *http.
LikeFields: likeFields,
}
ctx := context.Background()
ctx := r.Context()
categoriesDbLst, total, errW := s.ipc.Database.ApprovalTopicCategory.GetApprovalTopicCategoryListDB(ctx, options)
if errW != nil {
return nil, errW
@ -78,7 +77,7 @@ func (s *CategoriesReg) GetCategoryByIDHandler(w http.ResponseWriter, r *http.Re
return nil, errors.New("invalid category id")
}
ctx := context.Background()
ctx := r.Context()
category, err := s.ipc.Database.ApprovalTopicCategory.GetApprovalTopicCategoryByIDDB(ctx, id)
if err != nil {
return nil, err
@ -133,7 +132,7 @@ func (s *CategoriesReg) CreateCategoryHandler(w http.ResponseWriter, r *http.Req
}
// Проверяем, что код уникален
ctx := context.Background()
ctx := r.Context()
existingCategories, _, err := s.ipc.Database.ApprovalTopicCategory.GetApprovalTopicCategoryListDB(ctx, typescore.ListDbOptions{
Filtering: &typescore.ApprovalTopicCategory{Code: req.Code},
})
@ -189,7 +188,7 @@ func (s *CategoriesReg) UpdateCategoryHandler(w http.ResponseWriter, r *http.Req
}
// Проверяем, что категория существует
ctx := context.Background()
ctx := r.Context()
existingCategory, err := s.ipc.Database.ApprovalTopicCategory.GetApprovalTopicCategoryByIDDB(ctx, *req.ID)
if err != nil {
return nil, err
@ -253,7 +252,7 @@ func (s *CategoriesReg) DeleteCategoryHandler(w http.ResponseWriter, r *http.Req
}
// Проверяем, что категория существует
ctx := context.Background()
ctx := r.Context()
existingCategory, err := s.ipc.Database.ApprovalTopicCategory.GetApprovalTopicCategoryByIDDB(ctx, *req.ID)
if err != nil {
return nil, err

View File

@ -45,7 +45,7 @@ func (s *TopicExecutorsReg) GetTopicExecutorsListHandler(w http.ResponseWriter,
LikeFields: likeFields,
}
ctx := context.Background()
ctx := r.Context()
executorsDbLst, total, errW := s.ipc.Database.ApprovalTopicExecutor.GetApprovalTopicExecutorListDB(ctx, options)
if errW != nil {
return nil, errW
@ -85,7 +85,7 @@ func (s *TopicExecutorsReg) GetTopicExecutorByIDHandler(w http.ResponseWriter, r
return nil, errors.New("invalid executor id")
}
ctx := context.Background()
ctx := r.Context()
executors, _, err := s.ipc.Database.ApprovalTopicExecutor.GetApprovalTopicExecutorListDB(ctx, typescore.ListDbOptions{
Filtering: &typescore.ApprovalTopicExecutor{ID: &id},
})
@ -125,7 +125,7 @@ func (s *TopicExecutorsReg) GetExecutorsByTopicIDHandler(w http.ResponseWriter,
return nil, errors.New("invalid topic_id")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем, что тема существует
topic, err := s.ipc.Database.ApprovalTopic.GetApprovalTopicByIDDB(ctx, topicID)
@ -187,7 +187,7 @@ func (s *TopicExecutorsReg) CreateTopicExecutorHandler(w http.ResponseWriter, r
return nil, errors.New("user_id is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем существование темы
topic, err := s.ipc.Database.ApprovalTopic.GetApprovalTopicByIDDB(ctx, *req.TopicID)
@ -288,7 +288,7 @@ func (s *TopicExecutorsReg) UpdateTopicExecutorHandler(w http.ResponseWriter, r
return nil, errors.New("executor id is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем, что запись существует
existingExecutors, _, err := s.ipc.Database.ApprovalTopicExecutor.GetApprovalTopicExecutorListDB(ctx, typescore.ListDbOptions{
@ -374,7 +374,7 @@ func (s *TopicExecutorsReg) DeleteTopicExecutorHandler(w http.ResponseWriter, r
return nil, errors.New("executor id is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем, что запись существует
existingExecutors, _, err := s.ipc.Database.ApprovalTopicExecutor.GetApprovalTopicExecutorListDB(ctx, typescore.ListDbOptions{

View File

@ -3,7 +3,6 @@ package topicshandler
import (
"bitrix_balancer_api/core/typescore"
"bitrix_balancer_api/core/utilscore"
"context"
"encoding/json"
"errors"
"github.com/sirupsen/logrus"
@ -44,7 +43,7 @@ func (s *TopicsReg) GetTopicsListHandler(w http.ResponseWriter, r *http.Request)
LikeFields: likeFields,
}
ctx := context.Background()
ctx := r.Context()
topicsDbLst, total, errW := s.ipc.Database.ApprovalTopic.GetApprovalTopicsListDB(ctx, options)
if errW != nil {
return nil, errW
@ -89,7 +88,7 @@ func (s *TopicsReg) GetTopicByIDHandler(w http.ResponseWriter, r *http.Request)
return nil, errors.New("invalid topic id")
}
ctx := context.Background()
ctx := r.Context()
topic, err := s.ipc.Database.ApprovalTopic.GetApprovalTopicByIDDB(ctx, id)
if err != nil {
return nil, err
@ -147,7 +146,7 @@ func (s *TopicsReg) CreateTopicHandler(w http.ResponseWriter, r *http.Request) (
}
// Проверяем, что категория существует
ctx := context.Background()
ctx := r.Context()
category, err := s.ipc.Database.ApprovalTopicCategory.GetApprovalTopicCategoryByIDDB(ctx, *req.CategoryID)
if err != nil {
return nil, err
@ -248,7 +247,7 @@ func (s *TopicsReg) UpdateTopicHandler(w http.ResponseWriter, r *http.Request) (
}
// Проверяем, что тема существует
ctx := context.Background()
ctx := r.Context()
existingTopic, err := s.ipc.Database.ApprovalTopic.GetApprovalTopicByIDDB(ctx, *req.ID)
if err != nil {
return nil, err
@ -333,7 +332,7 @@ func (s *TopicsReg) DeleteTopicHandler(w http.ResponseWriter, r *http.Request) (
}
// Проверяем, что тема существует
ctx := context.Background()
ctx := r.Context()
existingTopic, err := s.ipc.Database.ApprovalTopic.GetApprovalTopicByIDDB(ctx, *req.ID)
if err != nil {
return nil, err

View File

@ -45,7 +45,7 @@ func (s *HierarchiesReg) GetHierarchiesListHandler(w http.ResponseWriter, r *htt
LikeFields: likeFields,
}
ctx := context.Background()
ctx := r.Context()
hierarchiesDbLst, total, errW := s.ipc.Database.UserHierarchy.GetUserHierarchyListDB(ctx, options)
if errW != nil {
return nil, errW
@ -85,7 +85,7 @@ func (s *HierarchiesReg) GetHierarchyByIDHandler(w http.ResponseWriter, r *http.
return nil, errors.New("invalid hierarchy id")
}
ctx := context.Background()
ctx := r.Context()
hierarchies, _, err := s.ipc.Database.UserHierarchy.GetUserHierarchyListDB(ctx, typescore.ListDbOptions{
Filtering: &typescore.UserHierarchy{ID: &id},
})
@ -139,7 +139,7 @@ func (s *HierarchiesReg) CreateHierarchyHandler(w http.ResponseWriter, r *http.R
return nil, errors.New("department_id is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем существование подчинённого
subordinate, err := s.ipc.Database.User.GetUserByIDDB(ctx, *req.SubordinateID)
@ -260,7 +260,7 @@ func (s *HierarchiesReg) UpdateHierarchyHandler(w http.ResponseWriter, r *http.R
return nil, errors.New("hierarchy id is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем, что запись существует
existingHierarchies, _, err := s.ipc.Database.UserHierarchy.GetUserHierarchyListDB(ctx, typescore.ListDbOptions{
@ -388,7 +388,7 @@ func (s *HierarchiesReg) DeleteHierarchyHandler(w http.ResponseWriter, r *http.R
return nil, errors.New("hierarchy id is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем, что запись существует
existingHierarchies, _, err := s.ipc.Database.UserHierarchy.GetUserHierarchyListDB(ctx, typescore.ListDbOptions{

View File

@ -3,7 +3,6 @@ package userroleshandler
import (
"bitrix_balancer_api/core/typescore"
"bitrix_balancer_api/core/utilscore"
"context"
"encoding/json"
"errors"
"github.com/sirupsen/logrus"
@ -58,7 +57,7 @@ func (s *UserRolesReg) GetUserRolesListHandler(w http.ResponseWriter, r *http.Re
LikeFields: likeFields,
}
ctx := context.Background()
ctx := r.Context()
userRolesDbLst, total, errW := s.ipc.Database.UserRole.GetUserRolesListDB(ctx, options)
if errW != nil {
return nil, errW
@ -103,7 +102,7 @@ func (s *UserRolesReg) GetUserRolesByUserIDHandler(w http.ResponseWriter, r *htt
return nil, errors.New("invalid user_id")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем, что пользователь существует
user, err := s.ipc.Database.User.GetUserByIDDB(ctx, userID)
@ -171,7 +170,7 @@ func (s *UserRolesReg) AssignUserRoleHandler(w http.ResponseWriter, r *http.Requ
return nil, errors.New("role_id is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем, что пользователь существует
user, err := s.ipc.Database.User.GetUserByIDDB(ctx, *req.UserID)
@ -256,7 +255,7 @@ func (s *UserRolesReg) BulkAssignRolesHandler(w http.ResponseWriter, r *http.Req
return nil, errors.New("user_id is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем, что пользователь существует
user, err := s.ipc.Database.User.GetUserByIDDB(ctx, *req.UserID)
@ -356,7 +355,7 @@ func (s *UserRolesReg) RemoveUserRoleHandler(w http.ResponseWriter, r *http.Requ
return nil, errors.New("user_role id is required")
}
ctx := context.Background()
ctx := r.Context()
// Проверяем, что запись существует
existingRoles, _, err := s.ipc.Database.UserRole.GetUserRolesListDB(ctx, typescore.ListDbOptions{

View File

@ -3,7 +3,6 @@ package usershandler
import (
"bitrix_balancer_api/core/typescore"
"bitrix_balancer_api/core/utilscore"
"context"
"encoding/json"
"errors"
"github.com/sirupsen/logrus"
@ -45,7 +44,7 @@ func (s *UserReg) GetUserListHandler(w http.ResponseWriter, r *http.Request) (in
LikeFields: likeFields,
}
ctx := context.Background()
ctx := r.Context()
userDbLst, total, errW := s.ipc.Database.User.GetUsersListDB(ctx, options)
if errW != nil {
return nil, errW
@ -108,7 +107,7 @@ func (s *UserReg) GetUserByIDHandler(w http.ResponseWriter, r *http.Request) (in
return nil, errors.New("invalid user id")
}
ctx := context.Background()
ctx := r.Context()
user, err := s.ipc.Database.User.GetUserByIDDB(ctx, id)
if err != nil {
return nil, err
@ -176,7 +175,7 @@ func (s *UserReg) UpdateUserHandler(w http.ResponseWriter, r *http.Request) (int
}
// Проверяем, что пользователь существует
ctx := context.Background()
ctx := r.Context()
existingUser, err := s.ipc.Database.User.GetUserByIDDB(ctx, *req.ID)
if err != nil {
return nil, err