fix: add check to prevent overwriting of final fraud states

This commit is contained in:
Florian Schlegel 2020-11-05 11:54:16 +01:00
parent 4ef3605738
commit 4ed9734ff0

View File

@ -11,6 +11,8 @@ import (
"github.com/foomo/shop/version"
)
var ErrorInconsistentStateTransition = errors.New("state transition now allowed")
//------------------------------------------------------------------
// ~ SIMPLE GETTERS ON ORDER
//------------------------------------------------------------------
@ -207,6 +209,16 @@ func (order *Order) SetFraudInvestigationState(state FraudInvestigationState) er
if order.Processing == nil {
return errors.New("Processing is nil")
}
currentState := order.Processing.FraudInvestigationState
if currentState == state {
return nil // state is already set
}
// avoid overriding of "final" states approved and rejected
if currentState == FraudInvestigationStateApproved || currentState == FraudInvestigationStateRejected {
return ErrorInconsistentStateTransition
}
order.Processing.FraudInvestigationState = state
return order.Upsert()
}