feat: uniqueness (#1190)

* feat: uniqueness on events

* fix: some tests

* fix: add unique username

* fix: nice error message

* fix: add unique test

* fix: add unique test

* fix: add unique constraint to events

* fix: correct unique constraint on user events

* fix: remove user constraint

* fix: add unique constraints

* fix: add unique constraints

* fix: add unique constraints

* fix: unnique constraints without interface

* fix: unique idp config

* fix: unique constraint comments

* fix: unique constraints in one table

* fix: unique constraints error

* fix: fix unique constraint on create user

* fix: fix unique constraint on create project

* fix: fix unique constraint on idp configs
This commit is contained in:
Fabi
2021-01-21 10:49:38 +01:00
committed by GitHub
parent c2e6e782a8
commit 28bfe72930
62 changed files with 1046 additions and 313 deletions

View File

@@ -31,6 +31,10 @@ func (e *DomainAddedEvent) Data() interface{} {
return e
}
func (e *DomainAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewDomainAddedEvent(ctx context.Context, domain string) *DomainAddedEvent {
return &DomainAddedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
@@ -65,6 +69,10 @@ func (e *DomainVerificationAddedEvent) Data() interface{} {
return e
}
func (e *DomainVerificationAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewDomainVerificationAddedEvent(
ctx context.Context,
domain string,
@@ -103,6 +111,10 @@ func (e *DomainVerificationFailedEvent) Data() interface{} {
return e
}
func (e *DomainVerificationFailedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewDomainVerificationFailedEvent(ctx context.Context, domain string) *DomainVerificationFailedEvent {
return &DomainVerificationFailedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
@@ -135,6 +147,10 @@ func (e *DomainVerifiedEvent) Data() interface{} {
return e
}
func (e *DomainVerifiedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewDomainVerifiedEvent(ctx context.Context, domain string) *DomainVerifiedEvent {
return &DomainVerifiedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
@@ -167,6 +183,10 @@ func (e *DomainPrimarySetEvent) Data() interface{} {
return e
}
func (e *DomainPrimarySetEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewDomainPrimarySetEvent(ctx context.Context, domain string) *DomainPrimarySetEvent {
return &DomainPrimarySetEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
@@ -199,6 +219,10 @@ func (e *DomainRemovedEvent) Data() interface{} {
return e
}
func (e *DomainRemovedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewDomainRemovedEvent(ctx context.Context, domain string) *DomainRemovedEvent {
return &DomainRemovedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(

View File

@@ -22,7 +22,8 @@ type IDPConfigAddedEvent struct {
func NewIDPConfigAddedEvent(
ctx context.Context,
configID string,
resourceOwner,
configID,
name string,
configType domain.IDPConfigType,
stylingType domain.IDPConfigStylingType,
@@ -30,9 +31,10 @@ func NewIDPConfigAddedEvent(
return &IDPConfigAddedEvent{
IDPConfigAddedEvent: *idpconfig.NewIDPConfigAddedEvent(
eventstore.NewBaseEventForPush(
eventstore.NewBaseEventForPushWithResourceOwner(
ctx,
IDPConfigAddedEventType,
resourceOwner,
),
configID,
name,
@@ -86,16 +88,20 @@ type IDPConfigRemovedEvent struct {
func NewIDPConfigRemovedEvent(
ctx context.Context,
configID string,
resourceOwner,
configID,
name string,
) *IDPConfigRemovedEvent {
return &IDPConfigRemovedEvent{
IDPConfigRemovedEvent: *idpconfig.NewIDPConfigRemovedEvent(
eventstore.NewBaseEventForPush(
eventstore.NewBaseEventForPushWithResourceOwner(
ctx,
IDPConfigRemovedEventType,
resourceOwner,
),
configID,
name,
),
}
}

View File

@@ -10,6 +10,7 @@ import (
)
const (
uniqueOrgname = "org_name"
OrgAddedEventType = orgEventTypePrefix + "added"
OrgChangedEventType = orgEventTypePrefix + "changed"
OrgDeactivatedEventType = orgEventTypePrefix + "deactivated"
@@ -17,6 +18,25 @@ const (
OrgRemovedEventType = orgEventTypePrefix + "removed"
)
type OrgnameUniqueConstraint struct {
uniqueType string
orgName string
action eventstore.UniqueConstraintAction
}
func NewAddOrgnameUniqueConstraint(orgName string) *eventstore.EventUniqueConstraint {
return eventstore.NewAddEventUniqueConstraint(
uniqueOrgname,
orgName,
"Errors.Org.AlreadyExists")
}
func NewRemoveUsernameUniqueConstraint(orgName string) *eventstore.EventUniqueConstraint {
return eventstore.NewRemoveEventUniqueConstraint(
uniqueOrgname,
orgName)
}
type OrgAddedEvent struct {
eventstore.BaseEvent `json:"-"`
@@ -27,6 +47,10 @@ func (e *OrgAddedEvent) Data() interface{} {
return e
}
func (e *OrgAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return []*eventstore.EventUniqueConstraint{NewAddOrgnameUniqueConstraint(e.Name)}
}
func NewOrgAddedEvent(ctx context.Context, name string) *OrgAddedEvent {
return &OrgAddedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
@@ -59,6 +83,10 @@ func (e *OrgChangedEvent) Data() interface{} {
return e
}
func (e *OrgChangedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewOrgChangedEvent(ctx context.Context, name string) *OrgChangedEvent {
return &OrgChangedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
@@ -89,6 +117,10 @@ func (e *OrgDeactivatedEvent) Data() interface{} {
return e
}
func (e *OrgDeactivatedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewOrgDeactivatedEvent(ctx context.Context) *OrgDeactivatedEvent {
return &OrgDeactivatedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
@@ -118,6 +150,10 @@ func (e *OrgReactivatedEvent) Data() interface{} {
return e
}
func (e *OrgReactivatedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewOrgReactivatedEvent(ctx context.Context) *OrgReactivatedEvent {
return &OrgReactivatedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(