mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-18 05:52:51 +00:00
Introduces the `administrators` relational table and repository layer for the v3 backend, unifying instance, organization, project, and project-grant membership into a single scoped model. Closes #10220 ## Changes - **Domain**: `Administrator` struct, `AdministratorScope` enum, `AdministratorRepository` interface with typed CRUD, column, condition, and change helpers. Generated enumer and GoMock. - **Migration** (`016`): `zitadel.administrators` table with a generated `id`, scope-alignment check constraint, cascading foreign keys, and a child `administrator_roles` table. - **Repository**: CTE-based role mutations (`AddRole`, `RemoveRole`, `SetRoles`) for atomicity. Roles aggregated via `ARRAY_AGG`. - **Projection**: Event reducers for `member.added/changed/removed/cascade_removed` across all four admin scopes. - **Fixes**: `Rows.Close()` error wrapping; `TextArray` nil-safe scan + full `pgtype` array interface; `authorization` and `projectGrant` scan helpers fixed for `ARRAY_AGG` under `database/sql`; removed unused `ctx` parameter from `callReduce`. --------- Co-authored-by: Marco Ardizzone <[email protected]>
118 lines
3.5 KiB
Go
118 lines
3.5 KiB
Go
// Code generated by "enumer -type AdministratorScope -transform snake -trimprefix AdministratorScope -sql"; DO NOT EDIT.
|
|
|
|
package domain
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
const _AdministratorScopeName = "instanceorganizationprojectproject_grant"
|
|
|
|
var _AdministratorScopeIndex = [...]uint8{0, 8, 20, 27, 40}
|
|
|
|
const _AdministratorScopeLowerName = "instanceorganizationprojectproject_grant"
|
|
|
|
func (i AdministratorScope) String() string {
|
|
if i >= AdministratorScope(len(_AdministratorScopeIndex)-1) {
|
|
return fmt.Sprintf("AdministratorScope(%d)", i)
|
|
}
|
|
return _AdministratorScopeName[_AdministratorScopeIndex[i]:_AdministratorScopeIndex[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 _AdministratorScopeNoOp() {
|
|
var x [1]struct{}
|
|
_ = x[AdministratorScopeInstance-(0)]
|
|
_ = x[AdministratorScopeOrganization-(1)]
|
|
_ = x[AdministratorScopeProject-(2)]
|
|
_ = x[AdministratorScopeProjectGrant-(3)]
|
|
}
|
|
|
|
var _AdministratorScopeValues = []AdministratorScope{AdministratorScopeInstance, AdministratorScopeOrganization, AdministratorScopeProject, AdministratorScopeProjectGrant}
|
|
|
|
var _AdministratorScopeNameToValueMap = map[string]AdministratorScope{
|
|
_AdministratorScopeName[0:8]: AdministratorScopeInstance,
|
|
_AdministratorScopeLowerName[0:8]: AdministratorScopeInstance,
|
|
_AdministratorScopeName[8:20]: AdministratorScopeOrganization,
|
|
_AdministratorScopeLowerName[8:20]: AdministratorScopeOrganization,
|
|
_AdministratorScopeName[20:27]: AdministratorScopeProject,
|
|
_AdministratorScopeLowerName[20:27]: AdministratorScopeProject,
|
|
_AdministratorScopeName[27:40]: AdministratorScopeProjectGrant,
|
|
_AdministratorScopeLowerName[27:40]: AdministratorScopeProjectGrant,
|
|
}
|
|
|
|
var _AdministratorScopeNames = []string{
|
|
_AdministratorScopeName[0:8],
|
|
_AdministratorScopeName[8:20],
|
|
_AdministratorScopeName[20:27],
|
|
_AdministratorScopeName[27:40],
|
|
}
|
|
|
|
// AdministratorScopeString retrieves an enum value from the enum constants string name.
|
|
// Throws an error if the param is not part of the enum.
|
|
func AdministratorScopeString(s string) (AdministratorScope, error) {
|
|
if val, ok := _AdministratorScopeNameToValueMap[s]; ok {
|
|
return val, nil
|
|
}
|
|
|
|
if val, ok := _AdministratorScopeNameToValueMap[strings.ToLower(s)]; ok {
|
|
return val, nil
|
|
}
|
|
return 0, fmt.Errorf("%s does not belong to AdministratorScope values", s)
|
|
}
|
|
|
|
// AdministratorScopeValues returns all values of the enum
|
|
func AdministratorScopeValues() []AdministratorScope {
|
|
return _AdministratorScopeValues
|
|
}
|
|
|
|
// AdministratorScopeStrings returns a slice of all String values of the enum
|
|
func AdministratorScopeStrings() []string {
|
|
strs := make([]string, len(_AdministratorScopeNames))
|
|
copy(strs, _AdministratorScopeNames)
|
|
return strs
|
|
}
|
|
|
|
// IsAAdministratorScope returns "true" if the value is listed in the enum definition. "false" otherwise
|
|
func (i AdministratorScope) IsAAdministratorScope() bool {
|
|
for _, v := range _AdministratorScopeValues {
|
|
if i == v {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (i AdministratorScope) Value() (driver.Value, error) {
|
|
return i.String(), nil
|
|
}
|
|
|
|
func (i *AdministratorScope) 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 AdministratorScope: %[1]T(%[1]v)", value)
|
|
}
|
|
|
|
val, err := AdministratorScopeString(str)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
*i = val
|
|
return nil
|
|
}
|