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
@@ -31,6 +31,10 @@ func (e *ApplicationAddedEvent) Data() interface{} {
return e
}
func (e *ApplicationAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewApplicationAddedEvent(ctx context.Context, appID, name string, appType domain.AppType) *ApplicationAddedEvent {
return &ApplicationAddedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
@@ -45,6 +45,10 @@ func (e *OIDCConfigAddedEvent) Data() interface{} {
return e
}
func (e *OIDCConfigAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return nil
}
func NewOIDCConfigAddedEvent(
ctx context.Context,
version domain.OIDCVersion,
+21 -2
View File
@@ -10,6 +10,7 @@ import (
)
const (
uniqueProjectnameTable = "project_names"
projectEventTypePrefix = eventstore.EventType("project.")
ProjectAdded = projectEventTypePrefix + "added"
ProjectChanged = projectEventTypePrefix + "changed"
@@ -18,6 +19,19 @@ const (
ProjectRemoved = projectEventTypePrefix + "removed"
)
func NewAddProjectNameUniqueConstraint(projectName, resourceOwner string) *eventstore.EventUniqueConstraint {
return eventstore.NewAddEventUniqueConstraint(
uniqueProjectnameTable,
projectName+resourceOwner,
"Errors.Project.AlreadyExists")
}
func NewRemoveProjectNameUniqueConstraint(projectName, resourceOwner string) *eventstore.EventUniqueConstraint {
return eventstore.NewRemoveEventUniqueConstraint(
uniqueProjectnameTable,
projectName+resourceOwner)
}
type ProjectAddedEvent struct {
eventstore.BaseEvent `json:"-"`
@@ -30,11 +44,16 @@ func (e *ProjectAddedEvent) Data() interface{} {
return e
}
func NewProjectAddedEvent(ctx context.Context, name string) *ProjectAddedEvent {
func (e *ProjectAddedEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint {
return []*eventstore.EventUniqueConstraint{NewAddProjectNameUniqueConstraint(e.Name, e.ResourceOwner())}
}
func NewProjectAddedEvent(ctx context.Context, name, resourceOwner string) *ProjectAddedEvent {
return &ProjectAddedEvent{
BaseEvent: *eventstore.NewBaseEventForPush(
BaseEvent: *eventstore.NewBaseEventForPushWithResourceOwner(
ctx,
ProjectAdded,
resourceOwner,
),
Name: name,
}