mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-18 05:52:51 +00:00
This pull request introduces a new set of domain models and repositories for managing users within the new v3 structure. The goal is to establish a clean, robust, and extensible foundation for user management. ### Summary This PR accomplishes the following: - **Polymorphic User Model**: Introduces a `User` model in user.go that can represent either a `Human` or a `Machine` user. This provides a unified way to handle different user types while allowing for specific attributes and logic for each. - **Repository Pattern**: Implements the repository pattern for accessing and manipulating user data. This decouples the business logic from the data storage implementation. The main repository interfaces (`UserRepository`, `HumanUserRepository`, `MachineUserRepository`) are now defined in `backend/v3/domain/user_repository.go`. - **Comprehensive User Models**: The user.go file now also defines the domain models for associated user data, including `UserMetadata`, `IdentityProviderLink`, `Passkey`, `PersonalAccessToken`, and `MachineKey`. - **Generic Verification and Check System**: Introduces verification.go and check.go to provide a standardized way of handling various verification flows (e.g., email verification, OTP checks). - **Generated Code**: Adds new generated files for enums (`humangender_enumer.go`, `machinekeytype_enumer.go`, `passkeytype_enumer.go`, `personalaccesstokentype_enumer.go`, `userstate_enumer.go`, `usertype_enumer.go`) and mocks for the new repositories. - **Session Domain Refactoring**: Updates the session domain (`backend/v3/domain/session*.go`) to align with the new user model structure. This foundational work paves the way for migrating user management logic to the new `v3` backend, with a more maintainable and testable architecture. part of #10224 --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Marco A. <[email protected]>
122 lines
3.1 KiB
Go
122 lines
3.1 KiB
Go
// Code generated by "enumer -type UserState -transform lower -trimprefix UserState -sql"; DO NOT EDIT.
|
|
|
|
package domain
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
const _UserStateName = "unspecifiedactiveinactivelockedinitial"
|
|
|
|
var _UserStateIndex = [...]uint8{0, 11, 17, 25, 31, 38}
|
|
|
|
const _UserStateLowerName = "unspecifiedactiveinactivelockedinitial"
|
|
|
|
func (i UserState) String() string {
|
|
if i >= UserState(len(_UserStateIndex)-1) {
|
|
return fmt.Sprintf("UserState(%d)", i)
|
|
}
|
|
return _UserStateName[_UserStateIndex[i]:_UserStateIndex[i+1]]
|
|
}
|
|
|
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
|
// Re-run the stringer command to generate them again.
|
|
func _UserStateNoOp() {
|
|
var x [1]struct{}
|
|
_ = x[UserStateUnspecified-(0)]
|
|
_ = x[UserStateActive-(1)]
|
|
_ = x[UserStateInactive-(2)]
|
|
_ = x[UserStateLocked-(3)]
|
|
_ = x[UserStateInitial-(4)]
|
|
}
|
|
|
|
var _UserStateValues = []UserState{UserStateUnspecified, UserStateActive, UserStateInactive, UserStateLocked, UserStateInitial}
|
|
|
|
var _UserStateNameToValueMap = map[string]UserState{
|
|
_UserStateName[0:11]: UserStateUnspecified,
|
|
_UserStateLowerName[0:11]: UserStateUnspecified,
|
|
_UserStateName[11:17]: UserStateActive,
|
|
_UserStateLowerName[11:17]: UserStateActive,
|
|
_UserStateName[17:25]: UserStateInactive,
|
|
_UserStateLowerName[17:25]: UserStateInactive,
|
|
_UserStateName[25:31]: UserStateLocked,
|
|
_UserStateLowerName[25:31]: UserStateLocked,
|
|
_UserStateName[31:38]: UserStateInitial,
|
|
_UserStateLowerName[31:38]: UserStateInitial,
|
|
}
|
|
|
|
var _UserStateNames = []string{
|
|
_UserStateName[0:11],
|
|
_UserStateName[11:17],
|
|
_UserStateName[17:25],
|
|
_UserStateName[25:31],
|
|
_UserStateName[31:38],
|
|
}
|
|
|
|
// UserStateString retrieves an enum value from the enum constants string name.
|
|
// Throws an error if the param is not part of the enum.
|
|
func UserStateString(s string) (UserState, error) {
|
|
if val, ok := _UserStateNameToValueMap[s]; ok {
|
|
return val, nil
|
|
}
|
|
|
|
if val, ok := _UserStateNameToValueMap[strings.ToLower(s)]; ok {
|
|
return val, nil
|
|
}
|
|
return 0, fmt.Errorf("%s does not belong to UserState values", s)
|
|
}
|
|
|
|
// UserStateValues returns all values of the enum
|
|
func UserStateValues() []UserState {
|
|
return _UserStateValues
|
|
}
|
|
|
|
// UserStateStrings returns a slice of all String values of the enum
|
|
func UserStateStrings() []string {
|
|
strs := make([]string, len(_UserStateNames))
|
|
copy(strs, _UserStateNames)
|
|
return strs
|
|
}
|
|
|
|
// IsAUserState returns "true" if the value is listed in the enum definition. "false" otherwise
|
|
func (i UserState) IsAUserState() bool {
|
|
for _, v := range _UserStateValues {
|
|
if i == v {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (i UserState) Value() (driver.Value, error) {
|
|
return i.String(), nil
|
|
}
|
|
|
|
func (i *UserState) Scan(value interface{}) error {
|
|
if value == nil {
|
|
return nil
|
|
}
|
|
|
|
var str string
|
|
switch v := value.(type) {
|
|
case []byte:
|
|
str = string(v)
|
|
case string:
|
|
str = v
|
|
case fmt.Stringer:
|
|
str = v.String()
|
|
default:
|
|
return fmt.Errorf("invalid value of UserState: %[1]T(%[1]v)", value)
|
|
}
|
|
|
|
val, err := UserStateString(str)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
*i = val
|
|
return nil
|
|
}
|