From 431dca5bf4e775be9bea80db7911c406a212358f Mon Sep 17 00:00:00 2001 From: romanskijdev Date: Thu, 25 Jun 2026 17:36:51 +0300 Subject: [PATCH] fix observer approvals list --- core/db/methods/permission.go | 1 - core/lib/external/tgkit/client.go | 7 -- .../handlers/approval/handler_observer.go | 84 +++++++++++++------ 3 files changed, 60 insertions(+), 32 deletions(-) diff --git a/core/db/methods/permission.go b/core/db/methods/permission.go index 9d3a7c5..09d38a2 100644 --- a/core/db/methods/permission.go +++ b/core/db/methods/permission.go @@ -184,7 +184,6 @@ func (u *PermissionDB) DeletePermissionDB(ctx context.Context, params *typescore // GetUserPermissionsDB возвращает все permissions для пользователя через его роли. // action — фильтр: create | approve | revoke | "" (все) func (u *PermissionDB) GetUserPermissionsDB(ctx context.Context, userID uint64, action string) ([]*typescore.Permission, error) { - // Используем алиас "p" и в GetStructFieldsDB тоже fields := dbutils.GetStructFieldsDB(&typescore.Permission{}, "p") q := squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar). diff --git a/core/lib/external/tgkit/client.go b/core/lib/external/tgkit/client.go index e1fa8a1..247d4fa 100644 --- a/core/lib/external/tgkit/client.go +++ b/core/lib/external/tgkit/client.go @@ -284,13 +284,6 @@ func buildHTTPClient(proxyCfg *ProxyConfig, timeout time.Duration) (*http.Client var finalTransport http.RoundTripper = baseTransport - // Если прокси передан в конфиге, оборачиваем базовый транспорт в наш кастомный - if proxyCfg != nil { - finalTransport = &CustomAPIProxyTransport{ - wrapped: baseTransport, - } - } - return &http.Client{ Transport: finalTransport, Timeout: timeout, // Будет работать глобальный таймаут (например, твои 15 сек или дефолтные 30) diff --git a/service/telegram_service/handlers/approval/handler_observer.go b/service/telegram_service/handlers/approval/handler_observer.go index 16b9b04..5934052 100644 --- a/service/telegram_service/handlers/approval/handler_observer.go +++ b/service/telegram_service/handlers/approval/handler_observer.go @@ -42,28 +42,46 @@ func (h *Handler) HandleObservedApprovalsPage(bot *tgbotapi.BotAPI, chatID int64 return } - // Собираем коды категорий var visibleTopics []approvalflow.Topic seenCodes := make(map[string]bool) + seenTopicIDs := make(map[uint64]bool) for _, p := range perms { - if p.TopicCategoryID == nil { - continue - } - category, err := h.ipc.Database.ApprovalTopicCategory.GetApprovalTopicCategoryByIDDB(ctx, *p.TopicCategoryID) - if err != nil || category == nil || category.Code == nil { - continue - } - if seenCodes[*category.Code] { - continue - } - seenCodes[*category.Code] = true + if p.TopicCategoryID != nil { + category, err := h.ipc.Database.ApprovalTopicCategory.GetApprovalTopicCategoryByIDDB(ctx, *p.TopicCategoryID) + if err != nil || category == nil || category.Code == nil { + continue + } + if seenCodes[*category.Code] { + continue + } + seenCodes[*category.Code] = true - topic, err := h.Registry.Get(*category.Code) - if err != nil { - continue + topic, err := h.Registry.Get(*category.Code) + if err != nil { + continue + } + visibleTopics = append(visibleTopics, topic) + } + + if p.TopicID != nil { + if seenTopicIDs[*p.TopicID] { + continue + } + seenTopicIDs[*p.TopicID] = true + + topicDB, err := h.ipc.Database.ApprovalTopic.GetApprovalTopicByIDDB(ctx, *p.TopicID) + if err != nil || topicDB == nil || topicDB.Code == nil { + continue + } + + // Пытаемся найти тему в Registry + topic, err := h.Registry.Get(*topicDB.Code) + if err != nil { + continue + } + visibleTopics = append(visibleTopics, topic) } - visibleTopics = append(visibleTopics, topic) } if len(visibleTopics) == 0 { @@ -252,9 +270,33 @@ func (h *Handler) HandleObserverReminderCallback(bot *tgbotapi.BotAPI, cq *tgbot // sendObserverTopicApprovals — общий рендер списка заявок по теме. func (h *Handler) sendObserverTopicApprovals(bot *tgbotapi.BotAPI, ctx context.Context, chatID int64, topicCode string) { - approvals, err := h.ipc.Database.Approval.GetApprovalsByCategoryDB(ctx, topicCode) + var approvals []*typescore.Approval + var err error + var topicName string + + // Определяем, что это: код категории или код темы + category, catErr := h.ipc.Database.ApprovalTopicCategory.GetApprovalTopicCategoryByCodeDB(ctx, topicCode) + if catErr == nil && category != nil { + // Это категория — получаем все согласования по категории + topicName = *category.Name + approvals, err = h.ipc.Database.Approval.GetApprovalsByCategoryDB(ctx, topicCode) + } else { + // Это тема — получаем согласования только по этой теме + topic, topicErr := h.ipc.Database.ApprovalTopic.GetApprovalTopicByCodeDB(ctx, topicCode) + if topicErr != nil || topic == nil || topic.ID == nil { + sendText(bot, chatID, "⚠️ Тема не найдена.") + return + } + topicName = *topic.Name + approvals, _, err = h.ipc.Database.Approval.GetApprovalsListDB(ctx, typescore.ListDbOptions{ + Filtering: &typescore.Approval{ + TopicID: topic.ID, + }, + }) + } + if err != nil { - logrus.Errorf("sendObserverTopicApprovals: GetApprovalsByCategoryDB err=%v", err) + logrus.Errorf("sendObserverTopicApprovals: err=%v", err) sendText(bot, chatID, "Ошибка при получении заявок.") return } @@ -267,12 +309,6 @@ func (h *Handler) sendObserverTopicApprovals(bot *tgbotapi.BotAPI, ctx context.C } } - topic, _ := h.Registry.Get(topicCode) - topicName := topicCode - if topic != nil { - topicName = topic.Name() - } - if len(pending) == 0 { msg := tgbotapi.NewMessage(chatID, fmt.Sprintf("👁 %s\n\nНет заявок, ожидающих согласования.", topicName)) msg.ParseMode = "HTML"