fix: user with state initial can only be deleted not deactivated (#3110)

This commit is contained in:
Fabi 2022-01-25 11:54:36 +01:00 committed by GitHub
parent 159d82ad8e
commit ce53fe7814
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 0 deletions

View File

@ -70,6 +70,9 @@ func (c *Commands) DeactivateUser(ctx context.Context, userID, resourceOwner str
if !isUserStateExists(existingUser.UserState) {
return nil, caos_errs.ThrowNotFound(nil, "COMMAND-3M9ds", "Errors.User.NotFound")
}
if isUserStateInitial(existingUser.UserState) {
return nil, caos_errs.ThrowNotFound(nil, "COMMAND-ke0fw", "Errors.User.CantDeactivateInitial")
}
if isUserStateInactive(existingUser.UserState) {
return nil, caos_errs.ThrowPreconditionFailed(nil, "COMMAND-5M0sf", "Errors.User.AlreadyInactive")
}

View File

@ -140,6 +140,10 @@ func isUserStateInactive(state domain.UserState) bool {
return hasUserState(state, domain.UserStateInactive)
}
func isUserStateInitial(state domain.UserState) bool {
return hasUserState(state, domain.UserStateInitial)
}
func hasUserState(check domain.UserState, states ...domain.UserState) bool {
for _, state := range states {
if check == state {

View File

@ -39,6 +39,7 @@ Errors:
DomainNotAllowedAsUsername: Domäne ist bereits reserviert und kann nicht verwendet werden
AlreadyInactive: Benutzer ist bereits deaktiviert
NotInactive: Benutzer ist nicht inaktiv
CantDeactivateInitial: Benutzer mit dem Status initial kann nur gelöscht und nicht deaktiviert werden
ShouldBeActiveOrInitial: Benutzer ist nicht aktiv oder initialisiert
AlreadyInitialised: Benutzer ist bereits initialisiert
NotInitialised: Benutzer ist noch nicht initialisiert

View File

@ -39,6 +39,7 @@ Errors:
DomainNotAllowedAsUsername: Domain is already reserved and cannot be used
AlreadyInactive: User already inactive
NotInactive: User is not inactive
CantDeactivateInitial: User with state initial can only be deleted not deactivated
ShouldBeActiveOrInitial: User is not active or inital
AlreadyInitialised: User is already initialised
NotInitialised: User is not yet initialised

View File

@ -39,6 +39,7 @@ Errors:
DomainNotAllowedAsUsername: Il dominio è già riservato e non può essere utilizzato
AlreadyInactive: Utente già inattivo
NotInactive: L'utente non è inattivo
CantDeactivateInitial: Gli utenti con lo stato iniziale possono solo essere cancellati e non disattivati
ShouldBeActiveOrInitial: L'utente non è attivo o inizializzato
AlreadyInitialised: L'utente è già inizializzato
NotInitialised: L'utente non è ancora inizializzato