From d1284082a1b54babc78664e129d64136e072c3ce Mon Sep 17 00:00:00 2001 From: Fabi <38692350+fgerschwiler@users.noreply.github.com> Date: Wed, 31 Mar 2021 11:10:06 +0200 Subject: [PATCH] fix: todos (#1502) * fix: remove console log * fix: remove todos * fix: setup uniqueness * fix: setup uniqueness --- internal/api/grpc/user/converter.go | 7 ------ .../repository/eventsourcing/view/sequence.go | 1 - .../repository/eventsourcing/view/sequence.go | 1 - internal/command/user_machine.go | 1 - internal/command/user_machine_key_model.go | 2 -- .../repository/eventsourcing/view/sequence.go | 1 - .../repository/eventsourcing/view/sequence.go | 1 - internal/repository/iam/events_step.go | 23 ++++++++++++++++++- internal/static/i18n/de.yaml | 5 ++++ internal/static/i18n/en.yaml | 5 ++++ .../resources/scripts/webauthn_login.js | 1 - 11 files changed, 32 insertions(+), 16 deletions(-) diff --git a/internal/api/grpc/user/converter.go b/internal/api/grpc/user/converter.go index d0020a86d1..01f717c55a 100644 --- a/internal/api/grpc/user/converter.go +++ b/internal/api/grpc/user/converter.go @@ -65,13 +65,6 @@ func HumanToPb(view *model.HumanView) *user_pb.Human { Phone: view.Phone, IsPhoneVerified: view.IsPhoneVerified, }, - Address: &user_pb.Address{ //TODO: remove? - Country: view.Country, - Locality: view.Locality, - PostalCode: view.PostalCode, - Region: view.Region, - StreetAddress: view.StreetAddress, - }, } } diff --git a/internal/auth/repository/eventsourcing/view/sequence.go b/internal/auth/repository/eventsourcing/view/sequence.go index 15b7c15d62..2ca2ca634b 100644 --- a/internal/auth/repository/eventsourcing/view/sequence.go +++ b/internal/auth/repository/eventsourcing/view/sequence.go @@ -29,7 +29,6 @@ func (v *View) updateSpoolerRunSequence(viewName string) error { } currentSequence.LastSuccessfulSpoolerRun = time.Now() //update all aggregate types - //TODO: not sure if all scenarios work as expected currentSequence.AggregateType = "" return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence) } diff --git a/internal/authz/repository/eventsourcing/view/sequence.go b/internal/authz/repository/eventsourcing/view/sequence.go index 5ac2f37443..806165af4c 100644 --- a/internal/authz/repository/eventsourcing/view/sequence.go +++ b/internal/authz/repository/eventsourcing/view/sequence.go @@ -29,7 +29,6 @@ func (v *View) updateSpoolerRunSequence(viewName string) error { } currentSequence.LastSuccessfulSpoolerRun = time.Now() //update all aggregate types - //TODO: not sure if all scenarios work as expected currentSequence.AggregateType = "" return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence) } diff --git a/internal/command/user_machine.go b/internal/command/user_machine.go index 3f330d8603..9804f15676 100644 --- a/internal/command/user_machine.go +++ b/internal/command/user_machine.go @@ -74,7 +74,6 @@ func (c *Commands) ChangeMachine(ctx context.Context, machine *domain.Machine) ( return writeModelToMachine(existingMachine), nil } -//TODO: adlerhurst we should check userID on the same level, in user.go userID is checked in public funcs func (c *Commands) machineWriteModelByID(ctx context.Context, userID, resourceOwner string) (writeModel *MachineWriteModel, err error) { if userID == "" { return nil, caos_errs.ThrowInvalidArgument(nil, "COMMAND-0Plof", "Errors.User.UserIDMissing") diff --git a/internal/command/user_machine_key_model.go b/internal/command/user_machine_key_model.go index 286b038f06..de6968096b 100644 --- a/internal/command/user_machine_key_model.go +++ b/internal/command/user_machine_key_model.go @@ -32,8 +32,6 @@ func (wm *MachineKeyWriteModel) AppendEvents(events ...eventstore.EventReader) { for _, event := range events { switch e := event.(type) { case *user.MachineKeyAddedEvent: - //TODO: adlerhurst we should decide who should handle the correct event appending - // IMO in this append events we should only get events with the correct keyID if wm.KeyID != e.KeyID { continue } diff --git a/internal/management/repository/eventsourcing/view/sequence.go b/internal/management/repository/eventsourcing/view/sequence.go index 047d8db560..f4f980929f 100644 --- a/internal/management/repository/eventsourcing/view/sequence.go +++ b/internal/management/repository/eventsourcing/view/sequence.go @@ -29,7 +29,6 @@ func (v *View) updateSpoolerRunSequence(viewName string) error { } currentSequence.LastSuccessfulSpoolerRun = time.Now() //update all aggregate types - //TODO: not sure if all scenarios work as expected currentSequence.AggregateType = "" return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence) } diff --git a/internal/notification/repository/eventsourcing/view/sequence.go b/internal/notification/repository/eventsourcing/view/sequence.go index 17d8fe9b55..0908432b8b 100644 --- a/internal/notification/repository/eventsourcing/view/sequence.go +++ b/internal/notification/repository/eventsourcing/view/sequence.go @@ -29,7 +29,6 @@ func (v *View) updateSpoolerRunSequence(viewName string) error { } currentSequence.LastSuccessfulSpoolerRun = time.Now() //update all aggregate types - //TODO: not sure if all scenarios work as expected currentSequence.AggregateType = "" return repository.UpdateCurrentSequence(v.Db, sequencesTable, currentSequence) } diff --git a/internal/repository/iam/events_step.go b/internal/repository/iam/events_step.go index 50e324e2e2..0d505bdd9b 100644 --- a/internal/repository/iam/events_step.go +++ b/internal/repository/iam/events_step.go @@ -3,6 +3,7 @@ package iam import ( "context" "encoding/json" + "strconv" "github.com/caos/zitadel/internal/eventstore" @@ -12,6 +13,8 @@ import ( ) const ( + UniqueStepStarted = "stepstarted" + UniqueStepDone = "stepdone" SetupDoneEventType eventstore.EventType = "iam.setup.done" SetupStartedEventType eventstore.EventType = "iam.setup.started" ) @@ -23,12 +26,30 @@ type SetupStepEvent struct { Done bool `json:"-"` } +func NewAddSetupStepStartedUniqueConstraint(step domain.Step) *eventstore.EventUniqueConstraint { + return eventstore.NewAddEventUniqueConstraint( + UniqueStepStarted, + strconv.Itoa(int(step)), + "Errors.Step.Started.AlreadyExists") +} + +func NewAddSetupStepDoneUniqueConstraint(step domain.Step) *eventstore.EventUniqueConstraint { + return eventstore.NewAddEventUniqueConstraint( + UniqueStepDone, + strconv.Itoa(int(step)), + "Errors.Step.Done.AlreadyExists") +} + func (e *SetupStepEvent) Data() interface{} { return e } func (e *SetupStepEvent) UniqueConstraints() []*eventstore.EventUniqueConstraint { - return nil + if e.Done { + return []*eventstore.EventUniqueConstraint{NewAddSetupStepDoneUniqueConstraint(e.Step)} + } else { + return []*eventstore.EventUniqueConstraint{NewAddSetupStepStartedUniqueConstraint(e.Step)} + } } func SetupStepMapper(event *repository.Event) (eventstore.EventReader, error) { diff --git a/internal/static/i18n/de.yaml b/internal/static/i18n/de.yaml index 186b173d6f..106d8ecd57 100644 --- a/internal/static/i18n/de.yaml +++ b/internal/static/i18n/de.yaml @@ -309,6 +309,11 @@ Errors: LoginPolicy: MFA: ForceAndNotConfigured: Multifaktor ist als zwingend konfiguriert, jedoch sind keine möglichen Provider hinterlegt. Bitte melde dich beim Administrator des Systems. + Step: + Started: + AlreadyExists: Schritt gestartet existiert bereits + Done: + AlreadyExists: Schritt ausgeführt existiert bereits EventTypes: user: added: Benutzer hinzugefügt diff --git a/internal/static/i18n/en.yaml b/internal/static/i18n/en.yaml index 620e4fe1dc..eb207855f6 100644 --- a/internal/static/i18n/en.yaml +++ b/internal/static/i18n/en.yaml @@ -310,6 +310,11 @@ Errors: LoginPolicy: MFA: ForceAndNotConfigured: Multifactor is configured as required, but no possible providers are configured. Please contact your system administrator. + Step: + Started: + AlreadyExists: Step started already exists + Done: + AlreadyExists: Step done already exists EventTypes: user: added: User added diff --git a/internal/ui/login/static/resources/scripts/webauthn_login.js b/internal/ui/login/static/resources/scripts/webauthn_login.js index a9264ffe1f..3b0542799a 100644 --- a/internal/ui/login/static/resources/scripts/webauthn_login.js +++ b/internal/ui/login/static/resources/scripts/webauthn_login.js @@ -8,7 +8,6 @@ function login() { makeAssertionOptions.publicKey.allowCredentials.forEach(function (listItem) { listItem.id = bufferDecode(listItem.id) }); - console.log(makeAssertionOptions); navigator.credentials.get({ publicKey: makeAssertionOptions.publicKey }).then(function (credential) {