add persistance function & userstate

Signed-off-by: Christian Richter <c.richter@opencloud.eu>
This commit is contained in:
Christian Richter
2025-10-08 16:45:16 +02:00
committed by Ralf Haferkamp
parent 07a9308c4c
commit cd295dfd9e
2 changed files with 101 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
package userstate
import (
"fmt"
"time"
)
const (
_ = iota
UserStateUnspecified
UserStateEnabled
UserStateDisabled
UserStateSoftDeleted
)
type UserState struct {
UserId string `json:"userid"`
State uint8 `json:"state"`
TimeStamp time.Time `json:"timestamp,omitempty"`
RetentionPeriod time.Duration `json:"retentionPeriod,omitempty"`
Reason string `json:"reason,omitempty,omitempty"`
}
func IsValidUserState(us *UserState) (bool, error) {
if us.State == UserStateSoftDeleted {
if us.RetentionPeriod <= 0 {
return false, fmt.Errorf("retention period must be greater than 0 for soft deleted users")
}
if us.Reason == "" {
return false, fmt.Errorf("reason must be provided for soft deleted users")
}
}
return true, nil
}