feat: migrar backend unificado a Go 1.27 + SPA Vite embebido
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ServicioDraftInput struct {
|
||||
CatalogoID string
|
||||
Nombre string
|
||||
EsPersonalizado bool
|
||||
}
|
||||
|
||||
type EvaluarSoloAdminInput struct {
|
||||
EsAgente bool
|
||||
HasPlanBucefalo bool
|
||||
Servicios []ServicioDraftInput
|
||||
SoloAdminCatalogIDs map[string]struct{}
|
||||
}
|
||||
|
||||
type EvaluarSoloAdminResult struct {
|
||||
OK bool
|
||||
Motivos []string
|
||||
ItemsBloqueados []string
|
||||
}
|
||||
|
||||
var bucefaloRe = regexp.MustCompile(`(?i)buc[eé]falo`)
|
||||
var bucefaloPrefixRe = regexp.MustCompile(`(?i)^bucefalo-`)
|
||||
|
||||
func EvaluarRestriccionSoloAdmin(in EvaluarSoloAdminInput) EvaluarSoloAdminResult {
|
||||
if !in.EsAgente {
|
||||
return EvaluarSoloAdminResult{OK: true}
|
||||
}
|
||||
|
||||
var motivos []string
|
||||
var bloqueados []string
|
||||
|
||||
if in.HasPlanBucefalo {
|
||||
motivos = append(motivos, "planBucefalo esta reservado al administrador humano")
|
||||
bloqueados = append(bloqueados, "planBucefalo")
|
||||
}
|
||||
|
||||
for _, svc := range in.Servicios {
|
||||
cid := strings.TrimSpace(svc.CatalogoID)
|
||||
nombre := strings.TrimSpace(svc.Nombre)
|
||||
|
||||
if cid != "" && bucefaloPrefixRe.MatchString(cid) {
|
||||
motivos = append(motivos, fmt.Sprintf("catalogoId restringido (%s)", cid))
|
||||
bloqueados = append(bloqueados, cid)
|
||||
continue
|
||||
}
|
||||
if cid != "" {
|
||||
if _, ok := in.SoloAdminCatalogIDs[cid]; ok {
|
||||
motivos = append(motivos, fmt.Sprintf("servicio marcado soloAdmin (%s)", cid))
|
||||
bloqueados = append(bloqueados, cid)
|
||||
continue
|
||||
}
|
||||
}
|
||||
if nombre != "" && bucefaloRe.MatchString(nombre) {
|
||||
motivos = append(motivos, fmt.Sprintf("servicio restringido por marca soloAdmin (%s)", nombre))
|
||||
bloqueados = append(bloqueados, nombre)
|
||||
}
|
||||
}
|
||||
|
||||
return EvaluarSoloAdminResult{
|
||||
OK: len(motivos) == 0,
|
||||
Motivos: motivos,
|
||||
ItemsBloqueados: bloqueados,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user