Resolve BE reviews
This commit is contained in:
committed by
Mumbi Francis
parent
0095663f60
commit
dcc0876254
@@ -192,12 +192,10 @@ export default {
|
||||
this.themes = [
|
||||
{
|
||||
id: 'light',
|
||||
title: this.$t('light'),
|
||||
values: this.lightModeVariables,
|
||||
},
|
||||
{
|
||||
id: 'dark',
|
||||
title: this.$t('dark'),
|
||||
values: this.darkModeVariables,
|
||||
},
|
||||
]
|
||||
|
||||
@@ -1398,6 +1398,7 @@ export default class System {
|
||||
handle,
|
||||
kind,
|
||||
labels,
|
||||
meta,
|
||||
} = (a as KV) || {}
|
||||
if (!email) {
|
||||
throw Error('field email is empty')
|
||||
@@ -1413,6 +1414,7 @@ export default class System {
|
||||
handle,
|
||||
kind,
|
||||
labels,
|
||||
meta,
|
||||
}
|
||||
return this.api().request(cfg).then(result => stdResolve(result))
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"github.com/cortezaproject/corteza/server/pkg/sass"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
@@ -34,7 +35,6 @@ import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/options"
|
||||
"github.com/cortezaproject/corteza/server/pkg/provision"
|
||||
"github.com/cortezaproject/corteza/server/pkg/rbac"
|
||||
"github.com/cortezaproject/corteza/server/pkg/sass"
|
||||
"github.com/cortezaproject/corteza/server/pkg/scheduler"
|
||||
"github.com/cortezaproject/corteza/server/pkg/sentry"
|
||||
"github.com/cortezaproject/corteza/server/pkg/valuestore"
|
||||
@@ -562,7 +562,7 @@ func (app *CortezaApp) Activate(ctx context.Context) (err error) {
|
||||
app.AuthService.Watch(ctx)
|
||||
|
||||
//Generate CSS for webapps
|
||||
if err = service.GenerateCSS(sysService.CurrentSettings, app.Opt.Webapp.ScssDirPath); err != nil {
|
||||
if err = service.GenerateCSS(sysService.CurrentSettings, app.Opt.Webapp.ScssDirPath, app.Log); err != nil {
|
||||
return fmt.Errorf("could not generate css for webapps: %w", err)
|
||||
}
|
||||
|
||||
@@ -967,11 +967,7 @@ func updateSmtpSettings(log *zap.Logger, current *types.AppSettings) {
|
||||
}
|
||||
|
||||
func updateSassInstallSettings(ctx context.Context, log *zap.Logger) {
|
||||
var sassInstalled bool
|
||||
|
||||
if sass.DartSassTranspiler(log) != nil {
|
||||
sassInstalled = true
|
||||
}
|
||||
sassInstalled := sass.DartSassTranspiler(log) != nil
|
||||
|
||||
// update dart-sass installed setting
|
||||
err := updateSetting(ctx, "ui.studio.sass-installed", sassInstalled)
|
||||
|
||||
@@ -3,13 +3,15 @@ package provision
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/cortezaproject/corteza/server/pkg/sass"
|
||||
"github.com/cortezaproject/corteza/server/store"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"go.uber.org/zap"
|
||||
"strconv"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// updateWebappTheme is a function that provisions webapp themes.
|
||||
// It migrates the old custom css and branding sass settings to the new webapp themes setting.
|
||||
func updateWebappTheme(ctx context.Context, log *zap.Logger, s store.Storer) (err error) {
|
||||
vv, _, err := store.SearchSettingValues(ctx, s, types.SettingsFilter{})
|
||||
if err != nil {
|
||||
@@ -27,31 +29,25 @@ func updateWebappTheme(ctx context.Context, log *zap.Logger, s store.Storer) (er
|
||||
|
||||
var themes []types.Theme
|
||||
for _, themeID := range themeIDs {
|
||||
title := []rune(themeID)
|
||||
title[0] = unicode.ToUpper(title[0])
|
||||
|
||||
if len(themeIDs) > 2 {
|
||||
if themeID == "general" {
|
||||
themes = append(themes, types.Theme{
|
||||
ID: themeID,
|
||||
Title: string(title),
|
||||
Values: oldValueStr,
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
if len(themeIDs) == 2 {
|
||||
themes = append(themes, types.Theme{
|
||||
ID: themeID,
|
||||
Title: string(title),
|
||||
Values: "",
|
||||
Values: oldValueStr,
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
if themeID == sass.GeneralTheme {
|
||||
themes = append(themes, types.Theme{
|
||||
ID: themeID,
|
||||
Values: oldValueStr,
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
themes = append(themes, types.Theme{
|
||||
ID: themeID,
|
||||
Title: string(title),
|
||||
Values: oldValueStr,
|
||||
Values: "",
|
||||
})
|
||||
}
|
||||
|
||||
@@ -71,7 +67,7 @@ func updateWebappTheme(ctx context.Context, log *zap.Logger, s store.Storer) (er
|
||||
return err
|
||||
}
|
||||
|
||||
// delete old custom css from the database
|
||||
// delete old custom css and branding sass settings from the database
|
||||
err = store.DeleteSettingValue(ctx, s, oldValue)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -82,7 +78,7 @@ func updateWebappTheme(ctx context.Context, log *zap.Logger, s store.Storer) (er
|
||||
|
||||
// provision custom CSS
|
||||
if !oldCustomCSS.IsNull() {
|
||||
err = provisionTheme("ui.studio.custom-css", oldCustomCSS, "general", "light", "dark")
|
||||
err = provisionTheme("ui.studio.custom-css", oldCustomCSS, sass.GeneralTheme, sass.LightTheme, sass.DarkTheme)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -90,7 +86,7 @@ func updateWebappTheme(ctx context.Context, log *zap.Logger, s store.Storer) (er
|
||||
|
||||
// provision branding sass
|
||||
if !oldBranding.IsNull() {
|
||||
err = provisionTheme("ui.studio.themes", oldBranding, "light", "dark")
|
||||
err = provisionTheme("ui.studio.themes", oldBranding, sass.LightTheme, sass.DarkTheme)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -15,6 +15,15 @@ import (
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const (
|
||||
GeneralTheme = "general"
|
||||
LightTheme = "light"
|
||||
DarkTheme = "dark"
|
||||
SectionRoot = "root"
|
||||
SectionMain = "main"
|
||||
SectionTheme = "theme"
|
||||
)
|
||||
|
||||
var (
|
||||
StylesheetCache = newStylesheetCache()
|
||||
sassVariablesPattern = regexp.MustCompile(`(\$[a-zA-Z_-]+):\s*([^;]+);`)
|
||||
@@ -49,19 +58,21 @@ func DefaultCSS(log *zap.Logger, customCSS string) string {
|
||||
|
||||
func Transpile(transpiler *godartsass.Transpiler, log *zap.Logger, themeID, themeSASS, customCSS, sassDirPath string) (err error) {
|
||||
// process root section
|
||||
err = processSass(transpiler, log, "root", themeID, themeSASS, customCSS, sassDirPath)
|
||||
err = processSass(transpiler, log, SectionRoot, themeID, themeSASS, customCSS, sassDirPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// process main section
|
||||
err = processSass(transpiler, log, "main", themeID, themeSASS, customCSS, sassDirPath)
|
||||
if err != nil {
|
||||
return err
|
||||
if themeID == LightTheme {
|
||||
err = processSass(transpiler, log, SectionMain, themeID, themeSASS, customCSS, sassDirPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
//process theme section
|
||||
err = processSass(transpiler, log, "theme", themeID, themeSASS, customCSS, sassDirPath)
|
||||
err = processSass(transpiler, log, SectionTheme, themeID, themeSASS, customCSS, sassDirPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -542,6 +542,10 @@ endpoints:
|
||||
name: labels
|
||||
title: Labels
|
||||
parser: label.ParseStrings
|
||||
- name: meta
|
||||
type: "*types.UserMeta"
|
||||
title: Additional user info
|
||||
parser: types.ParseUserMeta
|
||||
- name: update
|
||||
method: PUT
|
||||
title: Update user details
|
||||
|
||||
@@ -143,6 +143,11 @@ type (
|
||||
//
|
||||
// Labels
|
||||
Labels map[string]string
|
||||
|
||||
// Meta POST parameter
|
||||
//
|
||||
// Additional user info
|
||||
Meta *types.UserMeta
|
||||
}
|
||||
|
||||
UserUpdate struct {
|
||||
@@ -629,6 +634,7 @@ func (r UserCreate) Auditable() map[string]interface{} {
|
||||
"handle": r.Handle,
|
||||
"kind": r.Kind,
|
||||
"labels": r.Labels,
|
||||
"meta": r.Meta,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -657,6 +663,11 @@ func (r UserCreate) GetLabels() map[string]string {
|
||||
return r.Labels
|
||||
}
|
||||
|
||||
// Auditable returns all auditable/loggable parameters
|
||||
func (r UserCreate) GetMeta() *types.UserMeta {
|
||||
return r.Meta
|
||||
}
|
||||
|
||||
// Fill processes request and fills internal variables
|
||||
func (r *UserCreate) Fill(req *http.Request) (err error) {
|
||||
|
||||
@@ -717,6 +728,18 @@ func (r *UserCreate) Fill(req *http.Request) (err error) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if val, ok := req.MultipartForm.Value["meta[]"]; ok {
|
||||
r.Meta, err = types.ParseUserMeta(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if val, ok := req.MultipartForm.Value["meta"]; ok {
|
||||
r.Meta, err = types.ParseUserMeta(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -766,6 +789,18 @@ func (r *UserCreate) Fill(req *http.Request) (err error) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if val, ok := req.Form["meta[]"]; ok {
|
||||
r.Meta, err = types.ParseUserMeta(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if val, ok := req.Form["meta"]; ok {
|
||||
r.Meta, err = types.ParseUserMeta(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
|
||||
@@ -139,6 +139,7 @@ func (ctrl User) Create(ctx context.Context, r *request.UserCreate) (interface{}
|
||||
Handle: r.Handle,
|
||||
Kind: r.Kind,
|
||||
Labels: r.Labels,
|
||||
Meta: r.Meta,
|
||||
}
|
||||
|
||||
res, err := ctrl.user.Create(ctx, user)
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cespare/xxhash/v2"
|
||||
"strings"
|
||||
|
||||
"github.com/cortezaproject/corteza/server/pkg/logger"
|
||||
"github.com/cortezaproject/corteza/server/pkg/sass"
|
||||
"github.com/cortezaproject/corteza/server/pkg/str"
|
||||
"github.com/cortezaproject/corteza/server/system/types"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// GenerateCSS takes care of creating CSS for webapps by reading SASS content from embedded assets,
|
||||
// combining it with brandingSass and customCSS, and then transpiling it using the dart-sass compiler.
|
||||
// combining it with different themeSASS and customCSS themes, and then transpiling it using the dart-sass compiler.
|
||||
//
|
||||
// If dart sass isn't installed on the host machine, it will default to css content from the minified-custom.css which is
|
||||
// generated from [Boostrap, bootstrap-vue and custom variables sass content].
|
||||
// If dart isn't installed on the host machine, customCustom css will continue to function, but without sass support.
|
||||
//
|
||||
// In case of an error, it will return default css and log out the error
|
||||
func GenerateCSS(settings *types.AppSettings, sassDirPath string) (err error) {
|
||||
func GenerateCSS(settings *types.AppSettings, sassDirPath string, log *zap.Logger) (err error) {
|
||||
var (
|
||||
log = logger.Default()
|
||||
studio = settings.UI.Studio
|
||||
customCSSMap = make(map[string]string)
|
||||
)
|
||||
@@ -29,7 +28,7 @@ func GenerateCSS(settings *types.AppSettings, sassDirPath string) (err error) {
|
||||
customCSSMap[customCSS.ID] = customCSS.Values
|
||||
}
|
||||
|
||||
sass.DefaultCSS(log, customCSSMap["general"])
|
||||
sass.DefaultCSS(log, customCSSMap[sass.GeneralTheme])
|
||||
|
||||
if studio.Themes == nil && studio.CustomCSS == nil {
|
||||
return
|
||||
@@ -62,7 +61,7 @@ func GenerateCSS(settings *types.AppSettings, sassDirPath string) (err error) {
|
||||
} else {
|
||||
if studio.CustomCSS != nil {
|
||||
for key := range customCSSMap {
|
||||
if key == "general" {
|
||||
if key == sass.GeneralTheme {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -83,7 +82,7 @@ func GenerateCSS(settings *types.AppSettings, sassDirPath string) (err error) {
|
||||
func processCustomCSS(themeID string, customCSSMap map[string]string) (customCSS string) {
|
||||
var stringsBuilder strings.Builder
|
||||
|
||||
stringsBuilder.WriteString(customCSSMap["general"])
|
||||
stringsBuilder.WriteString(customCSSMap[sass.GeneralTheme])
|
||||
stringsBuilder.WriteString("\n")
|
||||
stringsBuilder.WriteString(customCSSMap[themeID])
|
||||
|
||||
@@ -107,7 +106,7 @@ func updateCSS(current, old, compStyles *types.SettingValue, name, sassDirPath s
|
||||
}
|
||||
|
||||
for key := range currentThemesMap {
|
||||
if str.HashStringSHA256(oldThemesMap[key]) == str.HashStringSHA256(currentThemesMap[key]) {
|
||||
if xxhash.Sum64String(oldThemesMap[key]) == xxhash.Sum64String(currentThemesMap[key]) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -116,10 +115,9 @@ func updateCSS(current, old, compStyles *types.SettingValue, name, sassDirPath s
|
||||
continue
|
||||
}
|
||||
|
||||
if key == "general" {
|
||||
if key == sass.GeneralTheme {
|
||||
if complimentaryStylesMap == nil {
|
||||
themeID := "light"
|
||||
transpileSASS(themeID, complimentaryStylesMap[themeID], currentThemesMap)
|
||||
transpileSASS(sass.LightTheme, complimentaryStylesMap[sass.LightTheme], currentThemesMap)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -131,7 +129,6 @@ func updateCSS(current, old, compStyles *types.SettingValue, name, sassDirPath s
|
||||
|
||||
transpileSASS(key, complimentaryStylesMap[key], currentThemesMap)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func themeMap(settingsValue *types.SettingValue) (themeMap map[string]string) {
|
||||
@@ -152,25 +149,27 @@ func themeMap(settingsValue *types.SettingValue) (themeMap map[string]string) {
|
||||
}
|
||||
|
||||
func FetchCSS() string {
|
||||
var stringsBuilder strings.Builder
|
||||
var (
|
||||
stringsBuilder strings.Builder
|
||||
rootLight = sass.StylesheetCache.Get(fmt.Sprintf("%s-%s", sass.SectionRoot, sass.LightTheme))
|
||||
)
|
||||
|
||||
if sass.StylesheetCache.Get("root-light") == "" {
|
||||
if rootLight == "" {
|
||||
return sass.StylesheetCache.Get("default-theme")
|
||||
}
|
||||
|
||||
// root css section
|
||||
stringsBuilder.WriteString(sass.StylesheetCache.Get("root-light"))
|
||||
stringsBuilder.WriteString(rootLight)
|
||||
stringsBuilder.WriteString("\n")
|
||||
stringsBuilder.WriteString(sass.StylesheetCache.Get("root-dark"))
|
||||
|
||||
stringsBuilder.WriteString(sass.StylesheetCache.Get(fmt.Sprintf("%s-%s", sass.SectionRoot, sass.DarkTheme)))
|
||||
stringsBuilder.WriteString("\n")
|
||||
|
||||
//theme css section
|
||||
stringsBuilder.WriteString(sass.StylesheetCache.Get("theme-dark"))
|
||||
stringsBuilder.WriteString(sass.StylesheetCache.Get(fmt.Sprintf("%s-%s", sass.SectionTheme, sass.DarkTheme)))
|
||||
stringsBuilder.WriteString("\n")
|
||||
|
||||
// body css section
|
||||
stringsBuilder.WriteString(sass.StylesheetCache.Get("main-light"))
|
||||
stringsBuilder.WriteString(sass.StylesheetCache.Get(fmt.Sprintf("%s-%s", sass.SectionMain, sass.LightTheme)))
|
||||
stringsBuilder.WriteString("\n")
|
||||
|
||||
return stringsBuilder.String()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -168,9 +168,9 @@ func (meta *UserMeta) Value() (driver.Value, error) { return json.Marshal(meta)
|
||||
func ParseUserMeta(ss []string) (p *UserMeta, err error) {
|
||||
p = &UserMeta{}
|
||||
|
||||
if len(ss) == 0 {
|
||||
if len(ss) > 0 {
|
||||
return
|
||||
}
|
||||
|
||||
return p, json.Unmarshal([]byte(ss[0]), p)
|
||||
return p, json.Unmarshal([]byte(ss[0]), &p)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user