From fb894c8bd803e1cc1e8d8045ab0202624f99ba53 Mon Sep 17 00:00:00 2001 From: romanskijdev Date: Wed, 14 Oct 2026 10:56:11 +0300 Subject: [PATCH 1/2] Fix approver name in approval card --- .../telegram_service/handlers/approval/selection_approver.go | 2 +- service/telegram_service/keyboard/delegation.go | 2 ++ service/telegram_service/keyboard/menu.go | 2 -- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/service/telegram_service/handlers/approval/selection_approver.go b/service/telegram_service/handlers/approval/selection_approver.go index 64737cb..83829c3 100644 --- a/service/telegram_service/handlers/approval/selection_approver.go +++ b/service/telegram_service/handlers/approval/selection_approver.go @@ -402,7 +402,7 @@ func (h *Handler) sendConfirmationCard(bot *tgbotapi.BotAPI, ctx context.Context if actualApprover != nil && actualApprover.FullName != nil { approverLine = *actualApprover.FullName if actualApprover.ID != nil && originalApprover.ID != nil && *actualApprover.ID != *originalApprover.ID { - approverLine += fmt.Sprintf(" (Временно исполняющий обязанности %s)", *originalApprover.FullName) + approverLine += fmt.Sprintf(" (Временно исполняющий обязанности за: %s)", *originalApprover.FullName) } } } diff --git a/service/telegram_service/keyboard/delegation.go b/service/telegram_service/keyboard/delegation.go index a179738..88e76f2 100644 --- a/service/telegram_service/keyboard/delegation.go +++ b/service/telegram_service/keyboard/delegation.go @@ -16,7 +16,9 @@ const delegationPerPage = 6 func BuildDelegationMainMenu() interface{} { return tgkit.NewInlineKeyboard(). Row(tgkit.BtnStyled(tgkit.ButtonStyleSuccess, "Делегировать заявки", "deleg_create")). + Row(tgkit.BtnStyled(tgkit.ButtonStyleSuccess, "Делегировать задачи", "deleg_task_create")). Row(tgkit.Btn("📋 Мои делегирования (Заявки)", "deleg_list")). + Row(tgkit.Btn("📋 Мои делегирования (Задачи)", "deleg_task_list")). Build() } diff --git a/service/telegram_service/keyboard/menu.go b/service/telegram_service/keyboard/menu.go index d882787..b0f4a28 100644 --- a/service/telegram_service/keyboard/menu.go +++ b/service/telegram_service/keyboard/menu.go @@ -37,8 +37,6 @@ func BuildMainMenu(roles UserRole) tgbotapi.ReplyKeyboardMarkup { // Раздел: Исполнитель if roles.IsExecutor { kb.Row("Задачи к исполнению") - kb.Row(tgkit.BtnStyled(tgkit.ButtonStyleSuccess, "Делегировать задачи", "deleg_task_create")) - kb.Row(tgkit.Btn("📋 Мои делегирования (Задачи)", "deleg_task_list")) } // Общие кнопки — всегда внизу -- 2.43.0 From bb6dc67b9ca570f0f8dde5867d9ec67ceb420e8a Mon Sep 17 00:00:00 2001 From: romanskijdev Date: Wed, 14 Oct 2026 13:02:51 +0300 Subject: [PATCH 2/2] Fix approver name in approval cards for all roles --- .../handlers/approval/helper.go | 11 --- .../handlers/approval/notify.go | 74 +++++++++++++++++-- 2 files changed, 68 insertions(+), 17 deletions(-) diff --git a/service/telegram_service/handlers/approval/helper.go b/service/telegram_service/handlers/approval/helper.go index 9c9575f..ecdfaa6 100644 --- a/service/telegram_service/handlers/approval/helper.go +++ b/service/telegram_service/handlers/approval/helper.go @@ -710,17 +710,6 @@ func (h *Handler) buildApprovalCard(ctx context.Context, approval *typescore.App filesLabel, createdAt, status, ) - // Добавляем информацию о текущем согласующем если заявка в процессе - if approval.Status != nil && *approval.Status == "pending" { - activeStep, _ := h.ipc.Database.ApprovalStep.GetActiveStepDB(ctx, approvalID) - if activeStep != nil && activeStep.ApproverID != nil { - approver, _ := h.ipc.Database.User.GetUserByIDDB(ctx, *activeStep.ApproverID) - if approver != nil && approver.FullName != nil { - card += fmt.Sprintf("\n🔄 У согласующего: %s", *approver.FullName) - } - } - } - // Добавляем информацию о дополнительных согласующих additionalApprovers, _, _ := h.ipc.Database.ApprovalAdditionalApprover.GetApprovalAdditionalApproversListDB(ctx, typescore.ListDbOptions{ Filtering: &typescore.ApprovalAdditionalApprover{ diff --git a/service/telegram_service/handlers/approval/notify.go b/service/telegram_service/handlers/approval/notify.go index 73c8c86..5a397ff 100644 --- a/service/telegram_service/handlers/approval/notify.go +++ b/service/telegram_service/handlers/approval/notify.go @@ -2,6 +2,7 @@ package approval import ( "bitrix_balancer_api/core/typescore" + "bitrix_balancer_api/core/utilscore" "bitrix_balancer_api/telegram_service/approvalflow" "bitrix_balancer_api/telegram_service/keyboard" "bitrix_balancer_api/telegram_service/types" @@ -9,6 +10,7 @@ import ( "encoding/base64" "fmt" "github.com/sirupsen/logrus" + "time" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) @@ -22,6 +24,65 @@ func NewNotifier(ipc *types.InternalProviderControl, topic approvalflow.Topic) * return &Notifier{ipc: ipc, topic: topic} } +// getDisplayName проверяет активные делегирования и формирует строку "Делегат (Делегат от Оригинал)", +// если права были переданы, либо просто "Оригинал", если делегирования нет. +func (n *Notifier) getDisplayName(ctx context.Context, originalApproverID uint64, topicID *uint64) string { + originalApprover, err := n.ipc.Database.User.GetUserByIDDB(ctx, originalApproverID) + if err != nil || originalApprover == nil { + return "—" + } + + origName := "—" + if originalApprover.FullName != nil { + origName = *originalApprover.FullName + } + + if topicID == nil { + return origName + } + + // 1. Проверяем делегирование по теме + delegations, _, err := n.ipc.Database.ApprovalDelegation.GetApprovalDelegationsListDB(ctx, typescore.ListDbOptions{ + Filtering: &typescore.ApprovalDelegation{ + DelegatorID: &originalApproverID, + TopicID: topicID, + IsActive: utilscore.PointerToBool(true), + }, + }) + if err == nil { + for _, d := range delegations { + if d.ValidUntil != nil && d.ValidUntil.After(time.Now()) && d.DelegateID != nil { + if delegate, _ := n.ipc.Database.User.GetUserByIDDB(ctx, *d.DelegateID); delegate != nil && delegate.FullName != nil { + return fmt.Sprintf("%s (Временно исполняющий обязанности от: %s)", *delegate.FullName, origName) + } + } + } + } + + // 2. Проверяем делегирование по категории + topic, _ := n.ipc.Database.ApprovalTopic.GetApprovalTopicByIDDB(ctx, *topicID) + if topic != nil && topic.CategoryID != nil { + delegationsCat, _, err := n.ipc.Database.ApprovalDelegation.GetApprovalDelegationsListDB(ctx, typescore.ListDbOptions{ + Filtering: &typescore.ApprovalDelegation{ + DelegatorID: &originalApproverID, + CategoryID: topic.CategoryID, + IsActive: utilscore.PointerToBool(true), + }, + }) + if err == nil { + for _, d := range delegationsCat { + if d.ValidUntil != nil && d.ValidUntil.After(time.Now()) && d.DelegateID != nil { + if delegate, _ := n.ipc.Database.User.GetUserByIDDB(ctx, *d.DelegateID); delegate != nil && delegate.FullName != nil { + return fmt.Sprintf("%s (Делегат от %s)", *delegate.FullName, origName) + } + } + } + } + } + + return origName +} + func (h *Handler) notifyExecutor(bot *tgbotapi.BotAPI, ctx context.Context, executor *typescore.User, initiator *typescore.User, approval *typescore.Approval, task *typescore.ApprovalTask) { if executor.TelegramID == nil || task.ID == nil || approval.ID == nil { return @@ -178,8 +239,8 @@ func (n *Notifier) NotifyInitiatorApproved( } approverName := "—" - if lastApprover != nil && lastApprover.FullName != nil { - approverName = *lastApprover.FullName + if lastApprover != nil && lastApprover.ID != nil { + approverName = n.getDisplayName(context.Background(), *lastApprover.ID, approval.TopicID) } status := "" @@ -233,8 +294,9 @@ func (n *Notifier) NotifyInitiatorRejected( } approverName := "—" - if approver != nil && approver.FullName != nil { - approverName = *approver.FullName + if approver != nil && approver.ID != nil { + ctx := context.Background() + approverName = n.getDisplayName(ctx, *approver.ID, approval.TopicID) } initiatorCollected := make(map[string]string, len(collected)) @@ -324,8 +386,8 @@ func (n *Notifier) NotifyObserversDecision( card := n.buildApprovalCard(ctx, approval, initiator, collected) approverName := "—" - if approver != nil && approver.FullName != nil { - approverName = *approver.FullName + if approver != nil && approver.ID != nil { + approverName = n.getDisplayName(ctx, *approver.ID, approval.TopicID) } header := fmt.Sprintf( "✅ %s согласовал(а) заявку\n\n", -- 2.43.0