fix-permissions #191
|
|
@ -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🔄 <b>У согласующего:</b> %s", *approver.FullName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Добавляем информацию о дополнительных согласующих
|
||||
additionalApprovers, _, _ := h.ipc.Database.ApprovalAdditionalApprover.GetApprovalAdditionalApproversListDB(ctx, typescore.ListDbOptions{
|
||||
Filtering: &typescore.ApprovalAdditionalApprover{
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
"✅ <b>%s</b> согласовал(а) заявку\n\n",
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"))
|
||||
}
|
||||
|
||||
// Общие кнопки — всегда внизу
|
||||
|
|
|
|||
Loading…
Reference in New Issue