mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:37:32 +00:00
feat: add schema user create and remove (#8494)
# Which Problems Are Solved Added functionality that user with a userschema can be created and removed. # How the Problems Are Solved Added logic and moved APIs so that everything is API v3 conform. # Additional Changes - move of user and userschema API to resources folder - changed testing and parameters - some renaming # Additional Context closes #7308 --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
This commit is contained in:
@@ -12,9 +12,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
UserSchemaTable = "projections.user_schemas"
|
||||
UserSchemaTable = "projections.user_schemas1"
|
||||
|
||||
UserSchemaIDCol = "id"
|
||||
UserSchemaCreationDateCol = "creation_date"
|
||||
UserSchemaChangeDateCol = "change_date"
|
||||
UserSchemaSequenceCol = "sequence"
|
||||
UserSchemaInstanceIDCol = "instance_id"
|
||||
@@ -39,6 +40,7 @@ func (*userSchemaProjection) Init() *old_handler.Check {
|
||||
return handler.NewTableCheck(
|
||||
handler.NewTable([]*handler.InitColumn{
|
||||
handler.NewColumn(UserSchemaIDCol, handler.ColumnTypeText),
|
||||
handler.NewColumn(UserSchemaCreationDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(UserSchemaChangeDateCol, handler.ColumnTypeTimestamp),
|
||||
handler.NewColumn(UserSchemaSequenceCol, handler.ColumnTypeInt64),
|
||||
handler.NewColumn(UserSchemaStateCol, handler.ColumnTypeEnum),
|
||||
@@ -102,6 +104,7 @@ func (p *userSchemaProjection) reduceCreated(event eventstore.Event) (*handler.S
|
||||
event,
|
||||
[]handler.Column{
|
||||
handler.NewCol(UserSchemaIDCol, event.Aggregate().ID),
|
||||
handler.NewCol(UserSchemaCreationDateCol, handler.OnlySetValueOnInsert(UserSchemaTable, e.CreationDate())),
|
||||
handler.NewCol(UserSchemaChangeDateCol, event.CreatedAt()),
|
||||
handler.NewCol(UserSchemaSequenceCol, event.Sequence()),
|
||||
handler.NewCol(UserSchemaInstanceIDCol, event.Aggregate().InstanceID),
|
||||
@@ -130,7 +133,10 @@ func (p *userSchemaProjection) reduceUpdated(event eventstore.Event) (*handler.S
|
||||
|
||||
if len(e.Schema) > 0 {
|
||||
cols = append(cols, handler.NewCol(UserSchemaSchemaCol, e.Schema))
|
||||
cols = append(cols, handler.NewIncrementCol(UserSchemaRevisionCol, 1))
|
||||
}
|
||||
|
||||
if e.SchemaRevision != nil {
|
||||
cols = append(cols, handler.NewCol(UserSchemaRevisionCol, *e.SchemaRevision))
|
||||
}
|
||||
|
||||
if len(e.PossibleAuthenticators) > 0 {
|
||||
|
@@ -39,10 +39,11 @@ func TestUserSchemaProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "INSERT INTO projections.user_schemas (id, change_date, sequence, instance_id, state, type, revision, schema, possible_authenticators) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
|
||||
expectedStmt: "INSERT INTO projections.user_schemas1 (id, creation_date, change_date, sequence, instance_id, state, type, revision, schema, possible_authenticators) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
anyArg{},
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"instance-id",
|
||||
domain.UserSchemaStateActive,
|
||||
@@ -61,9 +62,9 @@ func TestUserSchemaProjection_reduces(t *testing.T) {
|
||||
args: args{
|
||||
event: getEvent(
|
||||
testEvent(
|
||||
schema.CreatedType,
|
||||
schema.UpdatedType,
|
||||
schema.AggregateType,
|
||||
[]byte(`{"schemaType": "type", "schema": {"$schema":"urn:zitadel:schema:v1","properties":{"name":{"type":"string","urn:zitadel:schema:permission":{"self":"rw"}}},"type":"object"}, "possibleAuthenticators": [1,2]}`),
|
||||
[]byte(`{"schemaType": "type", "schemaRevision": 2, "schema": {"$schema":"urn:zitadel:schema:v1","properties":{"name":{"type":"string","urn:zitadel:schema:permission":{"self":"rw"}}},"type":"object"}, "possibleAuthenticators": [1,2]}`),
|
||||
), eventstore.GenericEventMapper[schema.UpdatedEvent]),
|
||||
},
|
||||
reduce: (&userSchemaProjection{}).reduceUpdated,
|
||||
@@ -73,13 +74,13 @@ func TestUserSchemaProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.user_schemas SET (change_date, sequence, type, schema, revision, possible_authenticators) = ($1, $2, $3, $4, revision + $5, $6) WHERE (id = $7) AND (instance_id = $8)",
|
||||
expectedStmt: "UPDATE projections.user_schemas1 SET (change_date, sequence, type, schema, revision, possible_authenticators) = ($1, $2, $3, $4, $5, $6) WHERE (id = $7) AND (instance_id = $8)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
"type",
|
||||
json.RawMessage(`{"$schema":"urn:zitadel:schema:v1","properties":{"name":{"type":"string","urn:zitadel:schema:permission":{"self":"rw"}}},"type":"object"}`),
|
||||
1,
|
||||
uint64(2),
|
||||
[]domain.AuthenticatorType{domain.AuthenticatorTypeUsername, domain.AuthenticatorTypePassword},
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
@@ -106,7 +107,7 @@ func TestUserSchemaProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.user_schemas SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedStmt: "UPDATE projections.user_schemas1 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -136,7 +137,7 @@ func TestUserSchemaProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "UPDATE projections.user_schemas SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedStmt: "UPDATE projections.user_schemas1 SET (change_date, sequence, state) = ($1, $2, $3) WHERE (id = $4) AND (instance_id = $5)",
|
||||
expectedArgs: []interface{}{
|
||||
anyArg{},
|
||||
uint64(15),
|
||||
@@ -166,7 +167,7 @@ func TestUserSchemaProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM projections.user_schemas WHERE (id = $1) AND (instance_id = $2)",
|
||||
expectedStmt: "DELETE FROM projections.user_schemas1 WHERE (id = $1) AND (instance_id = $2)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
"instance-id",
|
||||
@@ -193,7 +194,7 @@ func TestUserSchemaProjection_reduces(t *testing.T) {
|
||||
executer: &testExecuter{
|
||||
executions: []execution{
|
||||
{
|
||||
expectedStmt: "DELETE FROM projections.user_schemas WHERE (instance_id = $1)",
|
||||
expectedStmt: "DELETE FROM projections.user_schemas1 WHERE (instance_id = $1)",
|
||||
expectedArgs: []interface{}{
|
||||
"agg-id",
|
||||
},
|
||||
|
Reference in New Issue
Block a user