updated core types && updated admins table #47
|
|
@ -9,7 +9,7 @@ const (
|
|||
ContextTimeoutLong = 30 * time.Second
|
||||
)
|
||||
|
||||
// Константы для нового API-прокси (должны совпадать с tgkit)
|
||||
// Константы для нового API-прокси
|
||||
const (
|
||||
ProxyForwardURL = "https://proxyservice.ddns.net/forward"
|
||||
ProxySecretHeader = "X-Proxy-Secret"
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
"context"
|
||||
|
|
@ -30,7 +31,6 @@ func (h *Handler) HandleObservedApprovalsPage(bot *tgbotapi.BotAPI, chatID int64
|
|||
return
|
||||
}
|
||||
|
||||
// Получаем все категории на которые у пользователя есть права наблюдателя
|
||||
perms, err := h.ipc.Database.Permission.GetUserPermissionsDB(ctx, *user.ID, "observe")
|
||||
if err != nil {
|
||||
logrus.Errorf("HandleObservedApprovalsPage: GetUserPermissionsDB err=%v", err)
|
||||
|
|
@ -42,45 +42,39 @@ func (h *Handler) HandleObservedApprovalsPage(bot *tgbotapi.BotAPI, chatID int64
|
|||
return
|
||||
}
|
||||
|
||||
var visibleTopics []approvalflow.Topic
|
||||
seenCodes := make(map[string]bool)
|
||||
var visibleTopics []*typescore.ApprovalTopic
|
||||
seenTopicIDs := make(map[uint64]bool)
|
||||
|
||||
for _, p := range perms {
|
||||
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
|
||||
}
|
||||
visibleTopics = append(visibleTopics, topic)
|
||||
}
|
||||
|
||||
if p.TopicID != nil {
|
||||
if seenTopicIDs[*p.TopicID] {
|
||||
// Права на конкретную тему
|
||||
if p.TopicID != nil && !seenTopicIDs[*p.TopicID] {
|
||||
topicDB, err := h.ipc.Database.ApprovalTopic.GetApprovalTopicByIDDB(ctx, *p.TopicID)
|
||||
if err != nil || topicDB == nil || !*topicDB.IsActive {
|
||||
continue
|
||||
}
|
||||
seenTopicIDs[*p.TopicID] = true
|
||||
visibleTopics = append(visibleTopics, topicDB)
|
||||
}
|
||||
|
||||
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 p.TopicCategoryID != nil {
|
||||
topics, _, err := h.ipc.Database.ApprovalTopic.GetApprovalTopicsListDB(ctx, typescore.ListDbOptions{
|
||||
Filtering: &typescore.ApprovalTopic{
|
||||
CategoryID: p.TopicCategoryID,
|
||||
IsActive: utilscore.PointerToBool(true),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
logrus.Warnf("HandleObservedApprovalsPage: GetApprovalTopicsListDB err=%v", err)
|
||||
continue
|
||||
}
|
||||
visibleTopics = append(visibleTopics, topic)
|
||||
for _, t := range topics {
|
||||
if t.ID == nil || seenTopicIDs[*t.ID] {
|
||||
continue
|
||||
}
|
||||
seenTopicIDs[*t.ID] = true
|
||||
visibleTopics = append(visibleTopics, t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -89,9 +83,12 @@ func (h *Handler) HandleObservedApprovalsPage(bot *tgbotapi.BotAPI, chatID int64
|
|||
return
|
||||
}
|
||||
|
||||
logrus.Infof("👁 HandleObservedApprovalsPage: found %d topics for user %d", len(visibleTopics), *user.ID)
|
||||
|
||||
// 🆕 Строим клавиатуру из ApprovalTopic (не из Registry)
|
||||
msg := tgbotapi.NewMessage(chatID, "👁 <b>Наблюдение за согласованиями</b>\n\nВыберите тему:")
|
||||
msg.ParseMode = "HTML"
|
||||
msg.ReplyMarkup = keyboard.BuildObserverTopicMenu(visibleTopics, page)
|
||||
msg.ReplyMarkup = keyboard.BuildObserverTopicMenuFromDB(visibleTopics, page)
|
||||
bot.Send(msg) //nolint:errcheck
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -136,6 +136,45 @@ func BuildObserverSelectionMenu(observers []*typescore.User, selectedIDs []uint6
|
|||
return kb.Build()
|
||||
}
|
||||
|
||||
// BuildObserverTopicMenuFromDB — строит меню тем наблюдения из БД
|
||||
func BuildObserverTopicMenuFromDB(topics []*typescore.ApprovalTopic, page int) tgbotapi.InlineKeyboardMarkup {
|
||||
const perPage = 6
|
||||
total := len(topics)
|
||||
totalPages := (total + perPage - 1) / perPage
|
||||
if page < 0 {
|
||||
page = 0
|
||||
}
|
||||
if page >= totalPages && totalPages > 0 {
|
||||
page = totalPages - 1
|
||||
}
|
||||
start := page * perPage
|
||||
end := start + perPage
|
||||
if end > total {
|
||||
end = total
|
||||
}
|
||||
|
||||
var rows [][]tgbotapi.InlineKeyboardButton
|
||||
for _, t := range topics[start:end] {
|
||||
if t.ID == nil || t.Name == nil || t.Code == nil {
|
||||
continue
|
||||
}
|
||||
rows = append(rows, tgbotapi.NewInlineKeyboardRow(
|
||||
tgbotapi.NewInlineKeyboardButtonData(*t.Name, fmt.Sprintf("obs_topic:%s", *t.Code)),
|
||||
))
|
||||
}
|
||||
|
||||
if totalPages > 1 {
|
||||
rows = append(rows, tgkit.PaginationRow(
|
||||
page, totalPages,
|
||||
fmt.Sprintf("obs_topic_page:%d", page-1),
|
||||
fmt.Sprintf("obs_topic_page:%d", page+1),
|
||||
"obs_topic_noop",
|
||||
))
|
||||
}
|
||||
|
||||
return tgbotapi.NewInlineKeyboardMarkup(rows...)
|
||||
}
|
||||
|
||||
func BuildObserverTopicMenu(topics []approvalflow.Topic, page int) tgbotapi.InlineKeyboardMarkup {
|
||||
const perPage = 6
|
||||
total := len(topics)
|
||||
|
|
|
|||
Loading…
Reference in New Issue