zitadel/internal/repository/policy/label.go
Fabi 73d37459bb
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>
2021-06-04 14:53:51 +02:00

565 lines
15 KiB
Go

package policy
import (
"encoding/json"
"github.com/caos/zitadel/internal/errors"
"github.com/caos/zitadel/internal/eventstore"
"github.com/caos/zitadel/internal/eventstore/repository"
"github.com/caos/zitadel/internal/repository/asset"
)
const (
LabelPolicyAddedEventType = "policy.label.added"
LabelPolicyChangedEventType = "policy.label.changed"
LabelPolicyActivatedEventType = "policy.label.activated"
LabelPolicyLogoAddedEventType = "policy.label.logo.added"
LabelPolicyLogoRemovedEventType = "policy.label.logo.removed"
LabelPolicyIconAddedEventType = "policy.label.icon.added"
LabelPolicyIconRemovedEventType = "policy.label.icon.removed"
LabelPolicyLogoDarkAddedEventType = "policy.label.logo.dark.added"
LabelPolicyLogoDarkRemovedEventType = "policy.label.logo.dark.removed"
LabelPolicyIconDarkAddedEventType = "policy.label.icon.dark.added"
LabelPolicyIconDarkRemovedEventType = "policy.label.icon.dark.removed"
LabelPolicyFontAddedEventType = "policy.label.font.added"
LabelPolicyFontRemovedEventType = "policy.label.font.removed"
LabelPolicyAssetsRemovedEventType = "policy.label.assets.removed"
LabelPolicyRemovedEventType = "policy.label.removed"
)
type LabelPolicyAddedEvent struct {
eventstore.BaseEvent `json:"-"`
PrimaryColor string `json:"primaryColor,omitempty"`
BackgroundColor string `json:"backgroundColor,omitempty"`
WarnColor string `json:"warnColor,omitempty"`
FontColor string `json:"fontColor,omitempty"`
PrimaryColorDark string `json:"primaryColorDark,omitempty"`
BackgroundColorDark string `json:"backgroundColorDark,omitempty"`
WarnColorDark string `json:"warnColorDark,omitempty"`
FontColorDark string `json:"fontColorDark,omitempty"`
HideLoginNameSuffix bool `json:"hideLoginNameSuffix,omitempty"`
ErrorMsgPopup bool `json:"errorMsgPopup,omitempty"`
DisableWatermark bool `json:"disableMsgPopup,omitempty"`
}
func (e *LabelPolicyAddedEvent) Data() interface{} {
return e
}
func (e *LabelPolicyAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewLabelPolicyAddedEvent(
base *eventstore.BaseEvent,
primaryColor,
backgroundColor,
warnColor,
fontColor,
primaryColorDark,
backgroundColorDark,
warnColorDark,
fontColorDark string,
hideLoginNameSuffix,
errorMsgPopup,
disableWatermark bool,
) *LabelPolicyAddedEvent {
return &LabelPolicyAddedEvent{
BaseEvent: *base,
PrimaryColor: primaryColor,
BackgroundColor: backgroundColor,
WarnColor: warnColor,
FontColor: fontColor,
PrimaryColorDark: primaryColorDark,
BackgroundColorDark: backgroundColorDark,
WarnColorDark: warnColorDark,
FontColorDark: fontColorDark,
HideLoginNameSuffix: hideLoginNameSuffix,
ErrorMsgPopup: errorMsgPopup,
DisableWatermark: disableWatermark,
}
}
func LabelPolicyAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e := &LabelPolicyAddedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, e)
if err != nil {
return nil, errors.ThrowInternal(err, "POLIC-puqv4", "unable to unmarshal label policy")
}
return e, nil
}
type LabelPolicyChangedEvent struct {
eventstore.BaseEvent `json:"-"`
PrimaryColor *string `json:"primaryColor,omitempty"`
BackgroundColor *string `json:"backgroundColor,omitempty"`
WarnColor *string `json:"warnColor,omitempty"`
FontColor *string `json:"fontColor,omitempty"`
PrimaryColorDark *string `json:"primaryColorDark,omitempty"`
BackgroundColorDark *string `json:"backgroundColorDark,omitempty"`
WarnColorDark *string `json:"warnColorDark,omitempty"`
FontColorDark *string `json:"fontColorDark,omitempty"`
HideLoginNameSuffix *bool `json:"hideLoginNameSuffix,omitempty"`
ErrorMsgPopup *bool `json:"errorMsgPopup,omitempty"`
DisableWatermark *bool `json:"disableWatermark,omitempty"`
}
func (e *LabelPolicyChangedEvent) Data() interface{} {
return e
}
func (e *LabelPolicyChangedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewLabelPolicyChangedEvent(
base *eventstore.BaseEvent,
changes []LabelPolicyChanges,
) (*LabelPolicyChangedEvent, error) {
if len(changes) == 0 {
return nil, errors.ThrowPreconditionFailed(nil, "POLICY-Asfd3", "Errors.NoChangesFound")
}
changeEvent := &LabelPolicyChangedEvent{
BaseEvent: *base,
}
for _, change := range changes {
change(changeEvent)
}
return changeEvent, nil
}
type LabelPolicyChanges func(*LabelPolicyChangedEvent)
func ChangePrimaryColor(primaryColor string) func(*LabelPolicyChangedEvent) {
return func(e *LabelPolicyChangedEvent) {
e.PrimaryColor = &primaryColor
}
}
func ChangeBackgroundColor(background string) func(*LabelPolicyChangedEvent) {
return func(e *LabelPolicyChangedEvent) {
e.BackgroundColor = &background
}
}
func ChangeWarnColor(warnColor string) func(*LabelPolicyChangedEvent) {
return func(e *LabelPolicyChangedEvent) {
e.WarnColor = &warnColor
}
}
func ChangeFontColor(fontColor string) func(*LabelPolicyChangedEvent) {
return func(e *LabelPolicyChangedEvent) {
e.FontColor = &fontColor
}
}
func ChangePrimaryColorDark(primaryColorDark string) func(*LabelPolicyChangedEvent) {
return func(e *LabelPolicyChangedEvent) {
e.PrimaryColorDark = &primaryColorDark
}
}
func ChangeBackgroundColorDark(backgroundColorDark string) func(*LabelPolicyChangedEvent) {
return func(e *LabelPolicyChangedEvent) {
e.BackgroundColorDark = &backgroundColorDark
}
}
func ChangeWarnColorDark(warnColorDark string) func(*LabelPolicyChangedEvent) {
return func(e *LabelPolicyChangedEvent) {
e.WarnColorDark = &warnColorDark
}
}
func ChangeFontColorDark(fontColorDark string) func(*LabelPolicyChangedEvent) {
return func(e *LabelPolicyChangedEvent) {
e.FontColorDark = &fontColorDark
}
}
func ChangeHideLoginNameSuffix(hideLoginNameSuffix bool) func(*LabelPolicyChangedEvent) {
return func(e *LabelPolicyChangedEvent) {
e.HideLoginNameSuffix = &hideLoginNameSuffix
}
}
func ChangeErrorMsgPopup(errMsgPopup bool) func(*LabelPolicyChangedEvent) {
return func(e *LabelPolicyChangedEvent) {
e.ErrorMsgPopup = &errMsgPopup
}
}
func ChangeDisableWatermark(disableWatermark bool) func(*LabelPolicyChangedEvent) {
return func(e *LabelPolicyChangedEvent) {
e.DisableWatermark = &disableWatermark
}
}
func LabelPolicyChangedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e := &LabelPolicyChangedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}
err := json.Unmarshal(event.Data, e)
if err != nil {
return nil, errors.ThrowInternal(err, "POLIC-qhfFb", "unable to unmarshal label policy")
}
return e, nil
}
type LabelPolicyActivatedEvent struct {
eventstore.BaseEvent `json:"-"`
}
func (e *LabelPolicyActivatedEvent) Data() interface{} {
return e
}
func (e *LabelPolicyActivatedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewLabelPolicyActivatedEvent(base *eventstore.BaseEvent) *LabelPolicyActivatedEvent {
return &LabelPolicyActivatedEvent{
BaseEvent: *base,
}
}
func LabelPolicyActivatedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
return &LabelPolicyActivatedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}, nil
}
type LabelPolicyRemovedEvent struct {
eventstore.BaseEvent `json:"-"`
}
func (e *LabelPolicyRemovedEvent) Data() interface{} {
return e
}
func (e *LabelPolicyRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewLabelPolicyRemovedEvent(base *eventstore.BaseEvent) *LabelPolicyRemovedEvent {
return &LabelPolicyRemovedEvent{
BaseEvent: *base,
}
}
func LabelPolicyRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
return &LabelPolicyRemovedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}, nil
}
type LabelPolicyLogoAddedEvent struct {
asset.AddedEvent
}
func (e *LabelPolicyLogoAddedEvent) Data() interface{} {
return e
}
func (e *LabelPolicyLogoAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewLabelPolicyLogoAddedEvent(base *eventstore.BaseEvent, storageKey string) *LabelPolicyLogoAddedEvent {
return &LabelPolicyLogoAddedEvent{
*asset.NewAddedEvent(base, storageKey),
}
}
func LabelPolicyLogoAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := asset.AddedEventMapper(event)
if err != nil {
return nil, err
}
return &LabelPolicyLogoAddedEvent{*e.(*asset.AddedEvent)}, nil
}
type LabelPolicyLogoRemovedEvent struct {
asset.RemovedEvent
}
func (e *LabelPolicyLogoRemovedEvent) Data() interface{} {
return e
}
func (e *LabelPolicyLogoRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewLabelPolicyLogoRemovedEvent(base *eventstore.BaseEvent, storageKey string) *LabelPolicyLogoRemovedEvent {
return &LabelPolicyLogoRemovedEvent{
*asset.NewRemovedEvent(base, storageKey),
}
}
func LabelPolicyLogoRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := asset.RemovedEventMapper(event)
if err != nil {
return nil, err
}
return &LabelPolicyLogoRemovedEvent{*e.(*asset.RemovedEvent)}, nil
}
type LabelPolicyIconAddedEvent struct {
asset.AddedEvent
}
func (e *LabelPolicyIconAddedEvent) Data() interface{} {
return e
}
func (e *LabelPolicyIconAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewLabelPolicyIconAddedEvent(base *eventstore.BaseEvent, storageKey string) *LabelPolicyIconAddedEvent {
return &LabelPolicyIconAddedEvent{
*asset.NewAddedEvent(base, storageKey),
}
}
func LabelPolicyIconAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := asset.AddedEventMapper(event)
if err != nil {
return nil, err
}
return &LabelPolicyIconAddedEvent{*e.(*asset.AddedEvent)}, nil
}
type LabelPolicyIconRemovedEvent struct {
asset.RemovedEvent
}
func (e *LabelPolicyIconRemovedEvent) Data() interface{} {
return e
}
func (e *LabelPolicyIconRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewLabelPolicyIconRemovedEvent(base *eventstore.BaseEvent, storageKey string) *LabelPolicyIconRemovedEvent {
return &LabelPolicyIconRemovedEvent{
*asset.NewRemovedEvent(base, storageKey),
}
}
func LabelPolicyIconRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := asset.RemovedEventMapper(event)
if err != nil {
return nil, err
}
return &LabelPolicyIconRemovedEvent{*e.(*asset.RemovedEvent)}, nil
}
type LabelPolicyLogoDarkAddedEvent struct {
asset.AddedEvent
}
func (e *LabelPolicyLogoDarkAddedEvent) Data() interface{} {
return e
}
func (e *LabelPolicyLogoDarkAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewLabelPolicyLogoDarkAddedEvent(base *eventstore.BaseEvent, storageKey string) *LabelPolicyLogoDarkAddedEvent {
return &LabelPolicyLogoDarkAddedEvent{
*asset.NewAddedEvent(base, storageKey),
}
}
func LabelPolicyLogoDarkAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := asset.AddedEventMapper(event)
if err != nil {
return nil, err
}
return &LabelPolicyLogoDarkAddedEvent{*e.(*asset.AddedEvent)}, nil
}
type LabelPolicyLogoDarkRemovedEvent struct {
asset.RemovedEvent
}
func (e *LabelPolicyLogoDarkRemovedEvent) Data() interface{} {
return e
}
func (e *LabelPolicyLogoDarkRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewLabelPolicyLogoDarkRemovedEvent(base *eventstore.BaseEvent, storageKey string) *LabelPolicyLogoDarkRemovedEvent {
return &LabelPolicyLogoDarkRemovedEvent{
*asset.NewRemovedEvent(base, storageKey),
}
}
func LabelPolicyLogoDarkRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := asset.RemovedEventMapper(event)
if err != nil {
return nil, err
}
return &LabelPolicyLogoDarkRemovedEvent{*e.(*asset.RemovedEvent)}, nil
}
type LabelPolicyIconDarkAddedEvent struct {
asset.AddedEvent
}
func (e *LabelPolicyIconDarkAddedEvent) Data() interface{} {
return e
}
func (e *LabelPolicyIconDarkAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewLabelPolicyIconDarkAddedEvent(base *eventstore.BaseEvent, storageKey string) *LabelPolicyIconDarkAddedEvent {
return &LabelPolicyIconDarkAddedEvent{
*asset.NewAddedEvent(base, storageKey),
}
}
func LabelPolicyIconDarkAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := asset.AddedEventMapper(event)
if err != nil {
return nil, err
}
return &LabelPolicyIconDarkAddedEvent{*e.(*asset.AddedEvent)}, nil
}
type LabelPolicyIconDarkRemovedEvent struct {
asset.RemovedEvent
}
func (e *LabelPolicyIconDarkRemovedEvent) Data() interface{} {
return e
}
func (e *LabelPolicyIconDarkRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewLabelPolicyIconDarkRemovedEvent(base *eventstore.BaseEvent, storageKey string) *LabelPolicyIconDarkRemovedEvent {
return &LabelPolicyIconDarkRemovedEvent{
*asset.NewRemovedEvent(base, storageKey),
}
}
func LabelPolicyIconDarkRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := asset.RemovedEventMapper(event)
if err != nil {
return nil, err
}
return &LabelPolicyIconDarkRemovedEvent{*e.(*asset.RemovedEvent)}, nil
}
type LabelPolicyFontAddedEvent struct {
asset.AddedEvent
}
func (e *LabelPolicyFontAddedEvent) Data() interface{} {
return e
}
func (e *LabelPolicyFontAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewLabelPolicyFontAddedEvent(base *eventstore.BaseEvent, storageKey string) *LabelPolicyFontAddedEvent {
return &LabelPolicyFontAddedEvent{
*asset.NewAddedEvent(base, storageKey),
}
}
func LabelPolicyFontAddedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := asset.AddedEventMapper(event)
if err != nil {
return nil, err
}
return &LabelPolicyFontAddedEvent{*e.(*asset.AddedEvent)}, nil
}
type LabelPolicyFontRemovedEvent struct {
asset.RemovedEvent
}
func (e *LabelPolicyFontRemovedEvent) Data() interface{} {
return e
}
func (e *LabelPolicyFontRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewLabelPolicyFontRemovedEvent(base *eventstore.BaseEvent, storageKey string) *LabelPolicyFontRemovedEvent {
return &LabelPolicyFontRemovedEvent{
*asset.NewRemovedEvent(base, storageKey),
}
}
func LabelPolicyFontRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
e, err := asset.RemovedEventMapper(event)
if err != nil {
return nil, err
}
return &LabelPolicyFontRemovedEvent{*e.(*asset.RemovedEvent)}, nil
}
type LabelPolicyAssetsRemovedEvent struct {
eventstore.BaseEvent `json:"-"`
}
func (e *LabelPolicyAssetsRemovedEvent) Data() interface{} {
return nil
}
func (e *LabelPolicyAssetsRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewLabelPolicyAssetsRemovedEvent(base *eventstore.BaseEvent) *LabelPolicyAssetsRemovedEvent {
return &LabelPolicyAssetsRemovedEvent{
*base,
}
}
func LabelPolicyAssetsRemovedEventMapper(event *repository.Event) (eventstore.EventReader, error) {
return &LabelPolicyAssetsRemovedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}, nil
}