-
Notifications
You must be signed in to change notification settings - Fork 454
/
label.go
564 lines (452 loc) · 15.2 KB
/
label.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
package policy
import (
"encoding/json"
"github.com/zitadel/zitadel/internal/errors"
"github.com/zitadel/zitadel/internal/eventstore"
"github.com/zitadel/zitadel/internal/eventstore/repository"
"github.com/zitadel/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.Event, 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.Event, 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.Event, 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.Event, 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.Event, 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.Event, 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.Event, 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.Event, 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.Event, 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.Event, 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.Event, 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.Event, 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.Event, 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.Event, 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.Event, error) {
return &LabelPolicyAssetsRemovedEvent{
BaseEvent: *eventstore.BaseEventFromRepo(event),
}, nil
}