mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-01 20:02:15 +00:00
* begin init checks for projections * first projection checks * debug notification providers with query fixes * more projections and first index * more projections * more projections * finish projections * fix tests (remove db name) * create tables in setup * fix logging / error handling * add tenant to views * rename tenant to instance_id * add instance_id to all projections * add instance_id to all queries * correct instance_id on projections * add instance_id to failed_events * use separate context for instance * implement features projection * implement features projection * remove unique constraint from setup when migration failed * add error to failed setup event * add instance_id to primary keys * fix IAM projection * remove old migrations folder * fix keysFromYAML test
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package models
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/caos/zitadel/internal/api/authz"
|
|
)
|
|
|
|
type AggregateCreator struct {
|
|
serviceName string
|
|
}
|
|
|
|
func NewAggregateCreator(serviceName string) *AggregateCreator {
|
|
return &AggregateCreator{serviceName: serviceName}
|
|
}
|
|
|
|
type option func(*Aggregate)
|
|
|
|
func (c *AggregateCreator) NewAggregate(ctx context.Context, id string, typ AggregateType, version Version, previousSequence uint64, opts ...option) (*Aggregate, error) {
|
|
ctxData := authz.GetCtxData(ctx)
|
|
instance := authz.GetInstance(ctx)
|
|
editorUser := ctxData.UserID
|
|
resourceOwner := ctxData.OrgID
|
|
instanceID := instance.ID
|
|
|
|
aggregate := &Aggregate{
|
|
ID: id,
|
|
typ: typ,
|
|
PreviousSequence: previousSequence,
|
|
version: version,
|
|
Events: make([]*Event, 0, 2),
|
|
editorService: c.serviceName,
|
|
editorUser: editorUser,
|
|
resourceOwner: resourceOwner,
|
|
instanceID: instanceID,
|
|
}
|
|
|
|
for _, opt := range opts {
|
|
opt(aggregate)
|
|
}
|
|
|
|
if err := aggregate.Validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return aggregate, nil
|
|
}
|
|
|
|
func OverwriteEditorUser(userID string) func(*Aggregate) {
|
|
return func(a *Aggregate) {
|
|
a.editorUser = userID
|
|
}
|
|
}
|
|
|
|
func OverwriteResourceOwner(resourceOwner string) func(*Aggregate) {
|
|
return func(a *Aggregate) {
|
|
a.resourceOwner = resourceOwner
|
|
}
|
|
}
|