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:
123
server/auth/handlers/handle_dev.go
Normal file
123
server/auth/handlers/handle_dev.go
Normal file
@@ -0,0 +1,123 @@
|
||||
package handlers
|
||||
|
||||
// Handlers dev-view for templates & scenarios
|
||||
//
|
||||
// See auth/README.adoc for details on how this works
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/auth/request"
|
||||
"github.com/cortezaproject/corteza/server/pkg/y7s"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type (
|
||||
devScenariosDoc []*devTemplate
|
||||
devTemplate struct {
|
||||
Template string
|
||||
Scenes devScenes
|
||||
}
|
||||
|
||||
devScenes []*devScene
|
||||
devScene struct {
|
||||
Name string
|
||||
Template string
|
||||
Data map[string]interface{}
|
||||
}
|
||||
)
|
||||
|
||||
func (h *AuthHandlers) devView(req *request.AuthReq) (err error) {
|
||||
req.Template = "template-dev.html.tpl"
|
||||
req.Data["templates"], err = getScenes(h.Opt.AssetsPath)
|
||||
return
|
||||
}
|
||||
|
||||
func (h *AuthHandlers) devSceneView(w http.ResponseWriter, r *http.Request) {
|
||||
s, err := findScenario(
|
||||
h.Opt.AssetsPath,
|
||||
r.URL.Query().Get("template"),
|
||||
r.URL.Query().Get("scene"),
|
||||
)
|
||||
|
||||
s.Data["authBg"] = template.CSS(h.bgStylesData())
|
||||
|
||||
if err == nil && s != nil {
|
||||
err = h.Templates.ExecuteTemplate(w, s.Template+".html.tpl", s.Data)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func findScenario(assetsPath, template, scene string) (*devScene, error) {
|
||||
templates, err := getScenes(assetsPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, t := range templates {
|
||||
if t.Template != template {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, s := range t.Scenes {
|
||||
if s.Name != scene {
|
||||
continue
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func getScenes(assetsPath string) (devScenariosDoc, error) {
|
||||
if assetsPath == "" {
|
||||
return nil, fmt.Errorf("can not load scenarios without AUTH_ASSETS_PATH and exported assets")
|
||||
}
|
||||
|
||||
f, err := os.Open(assetsPath + "/templates/scenarios.yaml")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
aux := devScenariosDoc{}
|
||||
return aux, yaml.NewDecoder(f).Decode(&aux)
|
||||
}
|
||||
|
||||
func (doc *devScenariosDoc) UnmarshalYAML(n *yaml.Node) error {
|
||||
return y7s.EachMap(n, func(k *yaml.Node, v *yaml.Node) (err error) {
|
||||
dt := &devTemplate{Template: k.Value, Scenes: devScenes{}}
|
||||
|
||||
err = y7s.EachMap(v, func(k *yaml.Node, v *yaml.Node) (err error) {
|
||||
s := &devScene{
|
||||
Name: k.Value,
|
||||
Template: dt.Template,
|
||||
Data: make(map[string]interface{}),
|
||||
}
|
||||
|
||||
if err = v.Decode(s.Data); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
dt.Scenes = append(dt.Scenes, s)
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
*doc = append(*doc, dt)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user