mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:17:32 +00:00
feat: label policy (#1708)
* feat: label policy proto extension * feat: label policy and activate event * feat: label policy asset events * feat: label policy asset commands * feat: add storage key * feat: storage key validation * feat: label policy asset tests * feat: label policy query side * feat: avatar * feat: avatar event * feat: human avatar * feat: avatar read side * feat: font on iam label policy * feat: label policy font * feat: possiblity to create bucket on put file * uplaoder * login policy logo * set bucket prefix * feat: avatar upload * feat: avatar upload * feat: use assets on command side * feat: fix human avatar removed event * feat: remove human avatar * feat: mock asset storage * feat: remove human avatar * fix(operator): add configuration of asset storage to zitadel operator * feat(console): private labeling policy (#1697) * private labeling component, routing, preview * font, colors, upload, i18n * show logo * fix: uniqueness (#1710) * fix: uniqueconstraint to lower * feat: change org * feat: org change test * feat: change org * fix: tests * fix: handle domain claims correctly * feat: update org Co-authored-by: fabi <fabienne.gerschwiler@gmail.com> * fix: handle domain claimed event correctly for service users (#1711) * fix: handle domain claimed event correctly on user view * fix: ignore domain claimed events for email notifications * fix: change org * handle org changed in read models correctly * fix: change org in user grant handler Co-authored-by: fabi <fabienne.gerschwiler@gmail.com> * fix: correct value (#1695) * docs(api): correct link (#1712) * upload service Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: fabi <fabienne.gerschwiler@gmail.com> Co-authored-by: Florian Forster <florian@caos.ch> * feat: fix tests, * feat: remove assets from label policy * fix npm, set environment * lint ts * remove stylelinting * fix(operator): add mapping for console with changed unit tests * fix(operator): add secrets as env variables to pod * feat: remove human avatar * fix(operator): add secrets as env variables to pod * feat: map label policy * feat: labelpolicy, admin, mgmt, adv settings (#1715) * fetch label policy, mgmt, admin service * feat: advanced beh, links, add, update * lint ts * feat: watermark * feat: remove human avatar * feat: remove human avatar * feat: remove human avatar * feat: remove human avatar * feat: remove human avatar * feat: remove human avatar * feat: remove human avatar * feat: custom css * css * css * css * css * css * getobject * feat: dynamic handler * feat: varibale css * content info * css overwrite * feat: variablen css * feat: generate css file * feat: dark mode * feat: dark mode * fix logo css * feat: upload logos * dark mode with cookie * feat: handle images in login * avatar css and begin font * feat: avatar * feat: user avatar * caching of static assets in login * add avatar.js to main.html * feat: header dont show logo if no url * feat: label policy colors * feat: mock asset storage * feat: mock asset storage * feat: fix tests * feat: user avatar * feat: header logo * avatar * avatar * make it compatible with go 1.15 * feat: remove unused logos * fix handler * fix: styling error handling * fonts * fix: download func * switch to mux * fix: change upload api to assets * fix build * fix: download avatar * fix: download logos * fix: my avatar * font * fix: remove error msg popup possibility * fix: docs * fix: svalidate colors * rem msg popup from frontend * fix: email with private labeling * fix: tests * fix: email templates * fix: change migration version * fix: fix duplicate imports * fix(console): assets, service url, upload, policy current and preview (#1781) * upload endpoint, layout * fetch current, preview, fix upload * cleanup private labeling * fix linting * begin generated asset handler * generate asset api in dockerfile * features for label policy * features for label policy * features * flag for asset generator * change asset generator flag * fix label policy view in grpc * fix: layout, activate policy (#1786) * theme switcher up on top * change layout * activate policy * feat(console): label policy back color, layout (#1788) * theme switcher up on top * change layout * activate policy * fix overwrite value fc * reset policy, reset service * autosave policy, preview desc, layout impv * layout, i18n * background colors, inject material styles * load images * clean, lint * fix layout * set custom hex * fix content size conversion * remove font format in generated css * fix features for assets * fix(console): label policy colors, image downloads, preview (#1804) * load images * colors, images binding * lint * refresh emitter * lint * propagate font colors * upload error handling * label policy feature check * add blob in csp for console * log * fix: feature edits for label policy, refresh state on upload (#1807) * show error on load image, stop spinner * fix merge * fix migration versions * fix assets * fix csp * fix background color * scss * fix build * lint scss * fix statik for console * fix features check for label policy * cleanup * lint * public links * fix notifications * public links * feat: merge main * feat: fix translation files * fix migration * set api domain * fix logo in email * font face in email * font face in email * validate assets on upload * cleanup * add missing translations * add missing translations Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Stefan Benz <stefan@caos.ch> Co-authored-by: Max Peintner <max@caos.ch> Co-authored-by: Florian Forster <florian@caos.ch>
This commit is contained in:
@@ -300,7 +300,15 @@ func (repo *IAMRepository) GetOrgIAMPolicy(ctx context.Context) (*iam_model.OrgI
|
||||
}
|
||||
|
||||
func (repo *IAMRepository) GetDefaultLabelPolicy(ctx context.Context) (*iam_model.LabelPolicyView, error) {
|
||||
policy, err := repo.View.LabelPolicyByAggregateID(repo.SystemDefaults.IamID)
|
||||
policy, err := repo.View.LabelPolicyByAggregateIDAndState(repo.SystemDefaults.IamID, int32(domain.LabelPolicyStateActive))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return iam_es_model.LabelPolicyViewToModel(policy), err
|
||||
}
|
||||
|
||||
func (repo *IAMRepository) GetDefaultPreviewLabelPolicy(ctx context.Context) (*iam_model.LabelPolicyView, error) {
|
||||
policy, err := repo.View.LabelPolicyByAggregateIDAndState(repo.SystemDefaults.IamID, int32(domain.LabelPolicyStatePreview))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/caos/zitadel/internal/eventstore/v1"
|
||||
"github.com/caos/zitadel/internal/static"
|
||||
|
||||
"github.com/caos/zitadel/internal/admin/repository/eventsourcing/view"
|
||||
"github.com/caos/zitadel/internal/config/systemdefaults"
|
||||
@@ -30,8 +31,8 @@ func (h *handler) Eventstore() v1.Eventstore {
|
||||
return h.es
|
||||
}
|
||||
|
||||
func Register(configs Configs, bulkLimit, errorCount uint64, view *view.View, es v1.Eventstore, defaults systemdefaults.SystemDefaults) []query.Handler {
|
||||
return []query.Handler{
|
||||
func Register(configs Configs, bulkLimit, errorCount uint64, view *view.View, es v1.Eventstore, defaults systemdefaults.SystemDefaults, static static.Storage, localDevMode bool) []query.Handler {
|
||||
handlers := []query.Handler{
|
||||
newOrg(
|
||||
handler{view, bulkLimit, configs.cycleDuration("Org"), errorCount, es}),
|
||||
newIAMMember(
|
||||
@@ -66,6 +67,13 @@ func Register(configs Configs, bulkLimit, errorCount uint64, view *view.View, es
|
||||
newFeatures(
|
||||
handler{view, bulkLimit, configs.cycleDuration("Features"), errorCount, es}),
|
||||
}
|
||||
if static != nil {
|
||||
handlers = append(handlers, newStyling(
|
||||
handler{view, bulkLimit, configs.cycleDuration("Styling"), errorCount, es},
|
||||
static,
|
||||
localDevMode))
|
||||
}
|
||||
return handlers
|
||||
}
|
||||
|
||||
func (configs Configs) cycleDuration(viewModel string) time.Duration {
|
||||
|
@@ -2,6 +2,8 @@ package handler
|
||||
|
||||
import (
|
||||
"github.com/caos/logging"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/query"
|
||||
@@ -77,8 +79,25 @@ func (p *LabelPolicy) processLabelPolicy(event *es_models.Event) (err error) {
|
||||
switch event.Type {
|
||||
case model.LabelPolicyAdded:
|
||||
err = policy.AppendEvent(event)
|
||||
case model.LabelPolicyChanged:
|
||||
policy, err = p.view.LabelPolicyByAggregateID(event.AggregateID)
|
||||
case model.LabelPolicyChanged,
|
||||
model.LabelPolicyLogoAdded,
|
||||
model.LabelPolicyLogoRemoved,
|
||||
model.LabelPolicyIconAdded,
|
||||
model.LabelPolicyIconRemoved,
|
||||
model.LabelPolicyLogoDarkAdded,
|
||||
model.LabelPolicyLogoDarkRemoved,
|
||||
model.LabelPolicyIconDarkAdded,
|
||||
model.LabelPolicyIconDarkRemoved,
|
||||
model.LabelPolicyFontAdded,
|
||||
model.LabelPolicyFontRemoved,
|
||||
model.LabelPolicyAssetsRemoved:
|
||||
policy, err = p.view.LabelPolicyByAggregateIDAndState(event.AggregateID, int32(domain.LabelPolicyStatePreview))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = policy.AppendEvent(event)
|
||||
case model.LabelPolicyActivated:
|
||||
policy, err = p.view.LabelPolicyByAggregateIDAndState(event.AggregateID, int32(domain.LabelPolicyStatePreview))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
298
internal/admin/repository/eventsourcing/handler/styling.go
Normal file
298
internal/admin/repository/eventsourcing/handler/styling.go
Normal file
@@ -0,0 +1,298 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/lucasb-eyer/go-colorful"
|
||||
"github.com/muesli/gamut"
|
||||
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/query"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/spooler"
|
||||
iam_es_model "github.com/caos/zitadel/internal/iam/repository/eventsourcing/model"
|
||||
iam_model "github.com/caos/zitadel/internal/iam/repository/view/model"
|
||||
"github.com/caos/zitadel/internal/org/repository/eventsourcing/model"
|
||||
"github.com/caos/zitadel/internal/static"
|
||||
)
|
||||
|
||||
const (
|
||||
stylingTable = "adminapi.styling"
|
||||
)
|
||||
|
||||
type Styling struct {
|
||||
handler
|
||||
static static.Storage
|
||||
subscription *v1.Subscription
|
||||
devMode bool
|
||||
resourceUrl string
|
||||
}
|
||||
|
||||
func newStyling(handler handler, static static.Storage, localDevMode bool) *Styling {
|
||||
h := &Styling{
|
||||
handler: handler,
|
||||
static: static,
|
||||
}
|
||||
prefix := ""
|
||||
if localDevMode {
|
||||
prefix = "/login"
|
||||
}
|
||||
h.resourceUrl = prefix + "/resources/dynamic" //TODO: ?
|
||||
|
||||
h.subscribe()
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
func (m *Styling) subscribe() {
|
||||
m.subscription = m.es.Subscribe(m.AggregateTypes()...)
|
||||
go func() {
|
||||
for event := range m.subscription.Events {
|
||||
query.ReduceEvent(m, event)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (m *Styling) ViewModel() string {
|
||||
return stylingTable
|
||||
}
|
||||
|
||||
func (_ *Styling) AggregateTypes() []es_models.AggregateType {
|
||||
return []es_models.AggregateType{model.OrgAggregate, iam_es_model.IAMAggregate}
|
||||
}
|
||||
|
||||
func (m *Styling) CurrentSequence() (uint64, error) {
|
||||
sequence, err := m.view.GetLatestStylingSequence()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return sequence.CurrentSequence, nil
|
||||
}
|
||||
|
||||
func (m *Styling) EventQuery() (*es_models.SearchQuery, error) {
|
||||
sequence, err := m.view.GetLatestStylingSequence()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return es_models.NewSearchQuery().
|
||||
AggregateTypeFilter(m.AggregateTypes()...).
|
||||
LatestSequenceFilter(sequence.CurrentSequence), nil
|
||||
}
|
||||
|
||||
func (m *Styling) Reduce(event *es_models.Event) (err error) {
|
||||
switch event.AggregateType {
|
||||
case model.OrgAggregate, iam_es_model.IAMAggregate:
|
||||
err = m.processLabelPolicy(event)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *Styling) processLabelPolicy(event *es_models.Event) (err error) {
|
||||
policy := new(iam_model.LabelPolicyView)
|
||||
switch event.Type {
|
||||
case iam_es_model.LabelPolicyAdded, model.LabelPolicyAdded:
|
||||
err = policy.AppendEvent(event)
|
||||
case iam_es_model.LabelPolicyChanged, model.LabelPolicyChanged,
|
||||
iam_es_model.LabelPolicyLogoAdded, model.LabelPolicyLogoAdded,
|
||||
iam_es_model.LabelPolicyLogoRemoved, model.LabelPolicyLogoRemoved,
|
||||
iam_es_model.LabelPolicyIconAdded, model.LabelPolicyIconAdded,
|
||||
iam_es_model.LabelPolicyIconRemoved, model.LabelPolicyIconRemoved,
|
||||
iam_es_model.LabelPolicyLogoDarkAdded, model.LabelPolicyLogoDarkAdded,
|
||||
iam_es_model.LabelPolicyLogoDarkRemoved, model.LabelPolicyLogoDarkRemoved,
|
||||
iam_es_model.LabelPolicyIconDarkAdded, model.LabelPolicyIconDarkAdded,
|
||||
iam_es_model.LabelPolicyIconDarkRemoved, model.LabelPolicyIconDarkRemoved,
|
||||
iam_es_model.LabelPolicyFontAdded, model.LabelPolicyFontAdded,
|
||||
iam_es_model.LabelPolicyFontRemoved, model.LabelPolicyFontRemoved,
|
||||
iam_es_model.LabelPolicyAssetsRemoved, model.LabelPolicyAssetsRemoved:
|
||||
policy, err = m.view.StylingByAggregateIDAndState(event.AggregateID, int32(domain.LabelPolicyStatePreview))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = policy.AppendEvent(event)
|
||||
|
||||
case iam_es_model.LabelPolicyActivated, model.LabelPolicyActivated:
|
||||
policy, err = m.view.StylingByAggregateIDAndState(event.AggregateID, int32(domain.LabelPolicyStatePreview))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = policy.AppendEvent(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = m.generateStylingFile(policy)
|
||||
default:
|
||||
return m.view.ProcessedStylingSequence(event)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return m.view.PutStyling(policy, event)
|
||||
}
|
||||
|
||||
func (m *Styling) OnError(event *es_models.Event, err error) error {
|
||||
logging.LogWithFields("SPOOL-2m9fs", "id", event.AggregateID).WithError(err).Warn("something went wrong in label policy handler")
|
||||
return spooler.HandleError(event, err, m.view.GetLatestLabelPolicyFailedEvent, m.view.ProcessedLabelPolicyFailedEvent, m.view.ProcessedLabelPolicySequence, m.errorCountUntilSkip)
|
||||
}
|
||||
|
||||
func (m *Styling) OnSuccess() error {
|
||||
return spooler.HandleSuccess(m.view.UpdateLabelPolicySpoolerRunTimestamp)
|
||||
}
|
||||
|
||||
func (m *Styling) generateStylingFile(policy *iam_model.LabelPolicyView) error {
|
||||
reader, size, err := m.writeFile(policy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return m.uploadFilesToBucket(policy.AggregateID, "text/css", reader, size)
|
||||
}
|
||||
|
||||
func (m *Styling) writeFile(policy *iam_model.LabelPolicyView) (io.Reader, int64, error) {
|
||||
cssContent := ""
|
||||
cssContent += fmt.Sprint(":root {")
|
||||
if policy.PrimaryColor != "" {
|
||||
palette := m.generateColorPaletteRGBA255(policy.PrimaryColor)
|
||||
for i, color := range palette {
|
||||
cssContent += fmt.Sprintf("--zitadel-color-primary-%v: %s;", i, color)
|
||||
}
|
||||
}
|
||||
|
||||
if policy.BackgroundColor != "" {
|
||||
palette := m.generateColorPaletteRGBA255(policy.BackgroundColor)
|
||||
for i, color := range palette {
|
||||
cssContent += fmt.Sprintf("--zitadel-color-background-%v: %s;", i, color)
|
||||
}
|
||||
}
|
||||
if policy.WarnColor != "" {
|
||||
palette := m.generateColorPaletteRGBA255(policy.WarnColor)
|
||||
for i, color := range palette {
|
||||
cssContent += fmt.Sprintf("--zitadel-color-warn-%v: %s;", i, color)
|
||||
}
|
||||
}
|
||||
var fontname string
|
||||
if policy.FontURL != "" {
|
||||
split := strings.Split(policy.FontURL, "/")
|
||||
fontname = split[len(split)-1]
|
||||
cssContent += fmt.Sprintf("--zitadel-font-family: %s;", fontname)
|
||||
}
|
||||
cssContent += fmt.Sprint("}")
|
||||
if policy.FontURL != "" {
|
||||
cssContent += fmt.Sprintf(fontFaceTemplate, fontname, m.resourceUrl, policy.AggregateID, policy.FontURL)
|
||||
}
|
||||
cssContent += fmt.Sprint(".lgn-dark-theme {")
|
||||
if policy.PrimaryColorDark != "" {
|
||||
palette := m.generateColorPaletteRGBA255(policy.PrimaryColorDark)
|
||||
for i, color := range palette {
|
||||
cssContent += fmt.Sprintf("--zitadel-color-primary-%v: %s;", i, color)
|
||||
}
|
||||
}
|
||||
if policy.BackgroundColorDark != "" {
|
||||
palette := m.generateColorPaletteRGBA255(policy.BackgroundColorDark)
|
||||
for i, color := range palette {
|
||||
cssContent += fmt.Sprintf("--zitadel-color-background-%v: %s;", i, color)
|
||||
}
|
||||
}
|
||||
if policy.WarnColorDark != "" {
|
||||
palette := m.generateColorPaletteRGBA255(policy.WarnColorDark)
|
||||
for i, color := range palette {
|
||||
cssContent += fmt.Sprintf("--zitadel-color-warn-%v: %s;", i, color)
|
||||
}
|
||||
}
|
||||
if policy.FontColorDark != "" {
|
||||
palette := m.generateColorPaletteRGBA255(policy.FontColorDark)
|
||||
for i, color := range palette {
|
||||
cssContent += fmt.Sprintf("--zitadel-color-font-%v: %s;", i, color)
|
||||
}
|
||||
}
|
||||
cssContent += fmt.Sprint("}")
|
||||
|
||||
data := []byte(cssContent)
|
||||
buffer := bytes.NewBuffer(data)
|
||||
return buffer, int64(buffer.Len()), nil
|
||||
}
|
||||
|
||||
const fontFaceTemplate = `
|
||||
@font-face {
|
||||
font-family: '%s';
|
||||
font-style: normal;
|
||||
font-display: swap;
|
||||
src: url(%s?orgId=%s&filename=%s);
|
||||
}
|
||||
`
|
||||
|
||||
func (m *Styling) uploadFilesToBucket(aggregateID, contentType string, reader io.Reader, size int64) error {
|
||||
fileName := domain.CssPath + "/" + domain.CssVariablesFileName
|
||||
_, err := m.static.PutObject(context.Background(), aggregateID, fileName, contentType, reader, size, true)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *Styling) generateColorPaletteRGBA255(hex string) map[string]string {
|
||||
palette := make(map[string]string)
|
||||
defaultColor := gamut.Hex(hex)
|
||||
|
||||
color50, ok := colorful.MakeColor(gamut.Lighter(defaultColor, 1.0))
|
||||
if ok {
|
||||
palette["50"] = cssRGB(color50.RGB255())
|
||||
}
|
||||
|
||||
color100, ok := colorful.MakeColor(gamut.Lighter(defaultColor, 0.8))
|
||||
if ok {
|
||||
palette["100"] = cssRGB(color100.RGB255())
|
||||
}
|
||||
|
||||
color200, ok := colorful.MakeColor(gamut.Lighter(defaultColor, 0.6))
|
||||
if ok {
|
||||
palette["200"] = cssRGB(color200.RGB255())
|
||||
}
|
||||
|
||||
color300, ok := colorful.MakeColor(gamut.Lighter(defaultColor, 0.4))
|
||||
if ok {
|
||||
palette["300"] = cssRGB(color300.RGB255())
|
||||
}
|
||||
|
||||
color400, ok := colorful.MakeColor(gamut.Lighter(defaultColor, 0.1))
|
||||
if ok {
|
||||
palette["400"] = cssRGB(color400.RGB255())
|
||||
}
|
||||
|
||||
color500, ok := colorful.MakeColor(defaultColor)
|
||||
if ok {
|
||||
palette["500"] = cssRGB(color500.RGB255())
|
||||
}
|
||||
|
||||
color600, ok := colorful.MakeColor(gamut.Darker(defaultColor, 0.1))
|
||||
if ok {
|
||||
palette["600"] = cssRGB(color600.RGB255())
|
||||
}
|
||||
|
||||
color700, ok := colorful.MakeColor(gamut.Darker(defaultColor, 0.2))
|
||||
if ok {
|
||||
palette["700"] = cssRGB(color700.RGB255())
|
||||
}
|
||||
|
||||
color800, ok := colorful.MakeColor(gamut.Darker(defaultColor, 0.3))
|
||||
if ok {
|
||||
palette["800"] = cssRGB(color800.RGB255())
|
||||
}
|
||||
|
||||
color900, ok := colorful.MakeColor(gamut.Darker(defaultColor, 0.4))
|
||||
if ok {
|
||||
palette["900"] = cssRGB(color900.RGB255())
|
||||
}
|
||||
|
||||
colorContrast, ok := colorful.MakeColor(gamut.Contrast(defaultColor))
|
||||
if ok {
|
||||
palette["contrast"] = cssRGB(colorContrast.RGB255())
|
||||
}
|
||||
|
||||
return palette
|
||||
}
|
||||
|
||||
func cssRGB(r, g, b uint8) string {
|
||||
return fmt.Sprintf("rgb(%v, %v, %v)", r, g, b)
|
||||
}
|
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/caos/zitadel/internal/config/types"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1"
|
||||
es_spol "github.com/caos/zitadel/internal/eventstore/v1/spooler"
|
||||
"github.com/caos/zitadel/internal/static"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -28,7 +29,7 @@ type EsRepository struct {
|
||||
eventstore.UserRepo
|
||||
}
|
||||
|
||||
func Start(ctx context.Context, conf Config, systemDefaults sd.SystemDefaults, roles []string) (*EsRepository, error) {
|
||||
func Start(ctx context.Context, conf Config, systemDefaults sd.SystemDefaults, static static.Storage, roles []string, localDevMode bool) (*EsRepository, error) {
|
||||
es, err := v1.Start(conf.Eventstore)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -42,7 +43,7 @@ func Start(ctx context.Context, conf Config, systemDefaults sd.SystemDefaults, r
|
||||
return nil, err
|
||||
}
|
||||
|
||||
spool := spooler.StartSpooler(conf.Spooler, es, view, sqlClient, systemDefaults)
|
||||
spool := spooler.StartSpooler(conf.Spooler, es, view, sqlClient, systemDefaults, static, localDevMode)
|
||||
|
||||
return &EsRepository{
|
||||
spooler: spool,
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"database/sql"
|
||||
"github.com/caos/zitadel/internal/config/systemdefaults"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1"
|
||||
"github.com/caos/zitadel/internal/static"
|
||||
|
||||
"github.com/caos/zitadel/internal/admin/repository/eventsourcing/handler"
|
||||
"github.com/caos/zitadel/internal/admin/repository/eventsourcing/view"
|
||||
@@ -17,12 +18,12 @@ type SpoolerConfig struct {
|
||||
Handlers handler.Configs
|
||||
}
|
||||
|
||||
func StartSpooler(c SpoolerConfig, es v1.Eventstore, view *view.View, sql *sql.DB, defaults systemdefaults.SystemDefaults) *spooler.Spooler {
|
||||
func StartSpooler(c SpoolerConfig, es v1.Eventstore, view *view.View, sql *sql.DB, defaults systemdefaults.SystemDefaults, static static.Storage, localDevMode bool) *spooler.Spooler {
|
||||
spoolerConfig := spooler.Config{
|
||||
Eventstore: es,
|
||||
Locker: &locker{dbClient: sql},
|
||||
ConcurrentWorkers: c.ConcurrentWorkers,
|
||||
ViewHandlers: handler.Register(c.Handlers, c.BulkLimit, c.FailureCountUntilSkip, view, es, defaults),
|
||||
ViewHandlers: handler.Register(c.Handlers, c.BulkLimit, c.FailureCountUntilSkip, view, es, defaults, static, localDevMode),
|
||||
}
|
||||
spool := spoolerConfig.New()
|
||||
spool.Start()
|
||||
|
@@ -11,8 +11,8 @@ const (
|
||||
labelPolicyTable = "adminapi.label_policies"
|
||||
)
|
||||
|
||||
func (v *View) LabelPolicyByAggregateID(aggregateID string) (*model.LabelPolicyView, error) {
|
||||
return view.GetLabelPolicyByAggregateID(v.Db, labelPolicyTable, aggregateID)
|
||||
func (v *View) LabelPolicyByAggregateIDAndState(aggregateID string, state int32) (*model.LabelPolicyView, error) {
|
||||
return view.GetLabelPolicyByAggregateIDAndState(v.Db, labelPolicyTable, aggregateID, state)
|
||||
}
|
||||
|
||||
func (v *View) PutLabelPolicy(policy *model.LabelPolicyView, event *models.Event) error {
|
||||
|
44
internal/admin/repository/eventsourcing/view/styling.go
Normal file
44
internal/admin/repository/eventsourcing/view/styling.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
"github.com/caos/zitadel/internal/iam/repository/view"
|
||||
"github.com/caos/zitadel/internal/iam/repository/view/model"
|
||||
global_view "github.com/caos/zitadel/internal/view/repository"
|
||||
)
|
||||
|
||||
const (
|
||||
stylingTyble = "adminapi.styling"
|
||||
)
|
||||
|
||||
func (v *View) StylingByAggregateIDAndState(aggregateID string, state int32) (*model.LabelPolicyView, error) {
|
||||
return view.GetLabelPolicyByAggregateIDAndState(v.Db, stylingTyble, aggregateID, state)
|
||||
}
|
||||
|
||||
func (v *View) PutStyling(policy *model.LabelPolicyView, event *models.Event) error {
|
||||
err := view.PutLabelPolicy(v.Db, stylingTyble, policy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return v.ProcessedStylingSequence(event)
|
||||
}
|
||||
|
||||
func (v *View) GetLatestStylingSequence() (*global_view.CurrentSequence, error) {
|
||||
return v.latestSequence(stylingTyble)
|
||||
}
|
||||
|
||||
func (v *View) ProcessedStylingSequence(event *models.Event) error {
|
||||
return v.saveCurrentSequence(stylingTyble, event)
|
||||
}
|
||||
|
||||
func (v *View) UpdateStylingSpoolerRunTimestamp() error {
|
||||
return v.updateSpoolerRunSequence(stylingTyble)
|
||||
}
|
||||
|
||||
func (v *View) GetLatestStylingFailedEvent(sequence uint64) (*global_view.FailedEvent, error) {
|
||||
return v.latestFailedEvent(stylingTyble, sequence)
|
||||
}
|
||||
|
||||
func (v *View) ProcessedStylingFailedEvent(failedEvent *global_view.FailedEvent) error {
|
||||
return v.saveFailedEvent(failedEvent)
|
||||
}
|
@@ -24,6 +24,7 @@ type IAMRepository interface {
|
||||
ExternalIDPsByIDPConfigIDFromDefaultPolicy(ctx context.Context, idpConfigID string) ([]*usr_model.ExternalIDPView, error)
|
||||
|
||||
GetDefaultLabelPolicy(ctx context.Context) (*iam_model.LabelPolicyView, error)
|
||||
GetDefaultPreviewLabelPolicy(ctx context.Context) (*iam_model.LabelPolicyView, error)
|
||||
|
||||
GetDefaultMailTemplate(ctx context.Context) (*iam_model.MailTemplateView, error)
|
||||
|
||||
|
Reference in New Issue
Block a user