Update nodes filter for absense approvals
This commit is contained in:
parent
cdcbdb20fd
commit
3eccfd4289
|
|
@ -554,7 +554,6 @@ func (h *Handler) filterNodesByAccess(
|
|||
return nodes
|
||||
}
|
||||
|
||||
// 1. Получаем ТОЧНЫЕ права пользователя напрямую из БД (минуя абстрактный canUserAccessNode)
|
||||
perms, err := h.ipc.Database.Permission.GetUserPermissionsDB(ctx, *user.ID, "create")
|
||||
if err != nil {
|
||||
return nodes
|
||||
|
|
@ -579,12 +578,10 @@ func (h *Handler) filterNodesByAccess(
|
|||
|
||||
var allowedTopicCodes []string
|
||||
|
||||
// Если у пользователя есть ПРЯМОЕ право на ВСЮ категорию (ID 363)
|
||||
if allowedCategoryIDs[*category.ID] {
|
||||
allowedTopicCodes = append(allowedTopicCodes, categoryCode)
|
||||
}
|
||||
|
||||
// Собираем точные коды разрешенных тем внутри категории
|
||||
allTopics, _, err := h.ipc.Database.ApprovalTopic.GetApprovalTopicsListDB(ctx, typescore.ListDbOptions{
|
||||
Filtering: &typescore.ApprovalTopic{CategoryID: category.ID},
|
||||
})
|
||||
|
|
@ -596,8 +593,12 @@ func (h *Handler) filterNodesByAccess(
|
|||
}
|
||||
}
|
||||
|
||||
// Вспомогательная функция проверки разрешений
|
||||
isCodePermitted := func(targetCode string) bool {
|
||||
// If the user has access to the whole category, permit it
|
||||
if allowedCategoryIDs[*category.ID] {
|
||||
return true
|
||||
}
|
||||
|
||||
targetParts := strings.Split(targetCode, "_")
|
||||
targetMap := make(map[string]bool, len(targetParts))
|
||||
for _, p := range targetParts {
|
||||
|
|
@ -620,7 +621,6 @@ func (h *Handler) filterNodesByAccess(
|
|||
return false
|
||||
}
|
||||
|
||||
// 2. Рекурсивный Lookahead
|
||||
var hasValidLeaf func(n *approvalflow.FlowNode, collected map[string]string) bool
|
||||
hasValidLeaf = func(n *approvalflow.FlowNode, collected map[string]string) bool {
|
||||
newCollected := make(map[string]string, len(collected))
|
||||
|
|
@ -631,20 +631,21 @@ func (h *Handler) filterNodesByAccess(
|
|||
newCollected[n.DataKey] = n.DataValue
|
||||
}
|
||||
|
||||
code, err := topic.TopicCodeFromCollected(newCollected)
|
||||
if err == nil && code != "" {
|
||||
if isCodePermitted(code) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
isLeaf := len(n.Children) == 0
|
||||
isInputLeaf := len(n.Children) == 1 && n.Children[0].IsInput
|
||||
|
||||
// Only generate and check the code if we are at a leaf node
|
||||
// OR if the category doesn't use a complex template.
|
||||
// For template categories, intermediate codes are malformed.
|
||||
if isLeaf || isInputLeaf {
|
||||
code, err := topic.TopicCodeFromCollected(newCollected)
|
||||
if err == nil && code != "" {
|
||||
return isCodePermitted(code)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// It's an intermediate node, so we must check all children
|
||||
for _, child := range n.Children {
|
||||
if hasValidLeaf(child, newCollected) {
|
||||
return true
|
||||
|
|
@ -653,7 +654,6 @@ func (h *Handler) filterNodesByAccess(
|
|||
return false
|
||||
}
|
||||
|
||||
// 3. Итоговая фильтрация
|
||||
var filtered []*approvalflow.FlowNode
|
||||
for _, n := range nodes {
|
||||
if n == nil {
|
||||
|
|
|
|||
Loading…
Reference in New Issue