snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
99
server/pkg/envoyx/localeutils.go
Normal file
99
server/pkg/envoyx/localeutils.go
Normal file
@@ -0,0 +1,99 @@
|
||||
package envoyx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
)
|
||||
|
||||
type (
|
||||
localer interface {
|
||||
ResourceTranslation() string
|
||||
}
|
||||
)
|
||||
|
||||
func ResourceTranslationsForNodes(tt types.ResourceTranslationSet, nn ...*Node) (translations NodeSet, err error) {
|
||||
translations = make(NodeSet, 0, len(tt)/2)
|
||||
dups := make(map[types.Lang]map[string]map[string]bool)
|
||||
|
||||
for _, n := range nn {
|
||||
if n.Placeholder {
|
||||
continue
|
||||
}
|
||||
|
||||
c, ok := n.Resource.(localer)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
||||
// Split up the path of this resource
|
||||
//
|
||||
// @todo move over to those generated functions
|
||||
resPath := splitResourcePath(c.ResourceTranslation())
|
||||
|
||||
// Find all of the translations that fall under this resource
|
||||
for _, r := range tt {
|
||||
|
||||
// Split up the path of the rule
|
||||
//
|
||||
// @todo move over to that generated function
|
||||
rulePath := splitResourcePath(r.Resource)
|
||||
// @note resource translations don't support wildcards
|
||||
if !isPathSubset(rulePath, resPath, false) {
|
||||
// Mismatch; skip
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if this translation has already been seen
|
||||
if dups[r.Lang] != nil && dups[r.Lang][r.Resource][r.K] {
|
||||
continue
|
||||
}
|
||||
|
||||
// Parse the path so we can process it further
|
||||
// @todo make a generic function for RBAC rules and res. tr.
|
||||
localeRt, res, path, err := ParseRule(r.Resource)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if localeRt != n.ResourceType {
|
||||
// Resource type missmatch; skip
|
||||
continue
|
||||
}
|
||||
|
||||
// Get the refs
|
||||
rf := make(map[string]Ref, 2)
|
||||
for i, ref := range append(path, res) {
|
||||
// Whenever you'd use a wildcard, it will produce a nil so it
|
||||
// needs to be skipped
|
||||
if ref == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
ref.Scope = n.Scope
|
||||
|
||||
// @todo make the thing not a pointer
|
||||
rf[fmt.Sprintf("Path.%d", i)] = *ref
|
||||
}
|
||||
|
||||
translations = append(translations, &Node{
|
||||
Resource: r,
|
||||
|
||||
ResourceType: types.ResourceTranslationResourceType,
|
||||
References: rf,
|
||||
Scope: n.Scope,
|
||||
})
|
||||
|
||||
// Update the dup checking index
|
||||
if dups[r.Lang] == nil {
|
||||
dups[r.Lang] = make(map[string]map[string]bool)
|
||||
}
|
||||
if dups[r.Lang][r.Resource] == nil {
|
||||
dups[r.Lang][r.Resource] = make(map[string]bool)
|
||||
}
|
||||
dups[r.Lang][r.Resource][r.K] = true
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user