mirror of
https://github.com/foomo/shop.git
synced 2025-10-16 12:35:39 +00:00
fix: add check to prevent overwriting of final fraud states
This commit is contained in:
parent
4ef3605738
commit
4ed9734ff0
@ -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()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user