mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 18:57:32 +00:00
feat: add action v2 execution on requests and responses (#7637)
* feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: add execution of targets to grpc calls * feat: split request and response logic to handle the different context information * feat: split request and response logic to handle the different context information * fix: integration test * fix: import alias * fix: refactor execution package * fix: refactor execution interceptor integration and unit tests * fix: refactor execution interceptor integration and unit tests * fix: refactor execution interceptor integration and unit tests * fix: refactor execution interceptor integration and unit tests * fix: refactor execution interceptor integration and unit tests * docs: basic documentation for executions and targets * fix: change order for interceptors * fix: merge back origin/main * fix: change target definition command and query side (#7735) * fix: change target definition command and query side * fix: correct refactoring name changes * fix: correct refactoring name changes * fix: changing execution defintion with target list and type * fix: changing execution definition with target list and type * fix: add back search queries for target and include * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * fix: projections change for execution with targets suffix table * docs: add example to actions v2 * docs: add example to actions v2 * fix: correct integration tests on query for executions * fix: add separate event for execution v2 as content changed * fix: add separate event for execution v2 as content changed * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes --------- Co-authored-by: adlerhurst <silvan.reusser@gmail.com> * fix: added review comment changes * fix: added review comment changes * Update internal/api/grpc/server/middleware/execution_interceptor.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes * fix: added review comment changes --------- Co-authored-by: adlerhurst <silvan.reusser@gmail.com> Co-authored-by: Elio Bischof <elio@zitadel.com>
This commit is contained in:
@@ -2,6 +2,7 @@ package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/domain"
|
||||
"github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
||||
@@ -9,6 +10,10 @@ import (
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
const (
|
||||
EventGroupSuffix = ".*"
|
||||
)
|
||||
|
||||
type ExecutionAPICondition struct {
|
||||
Method string
|
||||
Service string
|
||||
@@ -134,7 +139,11 @@ func (e *ExecutionEventCondition) ID() string {
|
||||
return execution.ID(domain.ExecutionTypeEvent, e.Event)
|
||||
}
|
||||
if e.Group != "" {
|
||||
return execution.ID(domain.ExecutionTypeEvent, e.Group)
|
||||
group := e.Group
|
||||
if !strings.HasSuffix(e.Group, EventGroupSuffix) {
|
||||
group += EventGroupSuffix
|
||||
}
|
||||
return execution.ID(domain.ExecutionTypeEvent, group)
|
||||
}
|
||||
if e.All {
|
||||
return execution.IDAll(domain.ExecutionTypeEvent)
|
||||
@@ -168,25 +177,43 @@ func (c *Commands) SetExecutionEvent(ctx context.Context, cond *ExecutionEventCo
|
||||
type SetExecution struct {
|
||||
models.ObjectRoot
|
||||
|
||||
Targets []string
|
||||
Includes []string
|
||||
Targets []*execution.Target
|
||||
}
|
||||
|
||||
func (t SetExecution) GetIncludes() []string {
|
||||
includes := make([]string, 0)
|
||||
for i := range t.Targets {
|
||||
if t.Targets[i].Type == domain.ExecutionTargetTypeInclude {
|
||||
includes = append(includes, t.Targets[i].Target)
|
||||
}
|
||||
}
|
||||
return includes
|
||||
}
|
||||
|
||||
func (t SetExecution) GetTargets() []string {
|
||||
targets := make([]string, 0)
|
||||
for i := range t.Targets {
|
||||
if t.Targets[i].Type == domain.ExecutionTargetTypeTarget {
|
||||
targets = append(targets, t.Targets[i].Target)
|
||||
}
|
||||
}
|
||||
return targets
|
||||
}
|
||||
|
||||
func (e *SetExecution) IsValid() error {
|
||||
if len(e.Targets) == 0 && len(e.Includes) == 0 {
|
||||
if len(e.Targets) == 0 {
|
||||
return zerrors.ThrowInvalidArgument(nil, "COMMAND-56bteot2uj", "Errors.Execution.NoTargets")
|
||||
}
|
||||
if len(e.Targets) > 0 && len(e.Includes) > 0 {
|
||||
return zerrors.ThrowInvalidArgument(nil, "COMMAND-5zleae34r1", "Errors.Execution.Invalid")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *SetExecution) Existing(c *Commands, ctx context.Context, resourceOwner string) error {
|
||||
if len(e.Targets) > 0 && !c.existsTargetsByIDs(ctx, e.Targets, resourceOwner) {
|
||||
targets := e.GetTargets()
|
||||
if len(targets) > 0 && !c.existsTargetsByIDs(ctx, targets, resourceOwner) {
|
||||
return zerrors.ThrowNotFound(nil, "COMMAND-17e8fq1ggk", "Errors.Target.NotFound")
|
||||
}
|
||||
if len(e.Includes) > 0 && !c.existsExecutionsByIDs(ctx, e.Includes, resourceOwner) {
|
||||
includes := e.GetIncludes()
|
||||
if len(includes) > 0 && !c.existsExecutionsByIDs(ctx, includes, resourceOwner) {
|
||||
return zerrors.ThrowNotFound(nil, "COMMAND-slgj0l4cdz", "Errors.Execution.IncludeNotFound")
|
||||
}
|
||||
return nil
|
||||
@@ -206,11 +233,10 @@ func (c *Commands) setExecution(ctx context.Context, set *SetExecution, resource
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := c.pushAppendAndReduce(ctx, wm, execution.NewSetEvent(
|
||||
if err := c.pushAppendAndReduce(ctx, wm, execution.NewSetEventV2(
|
||||
ctx,
|
||||
ExecutionAggregateFromWriteModel(&wm.WriteModel),
|
||||
set.Targets,
|
||||
set.Includes,
|
||||
)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user