mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-02 14:12:27 +00:00
# Which Problems Are Solved As part of our efforts to simplify the structure and versions of our APIs, were moving all existing v2beta endpoints to v2 and deprecate them. They will be removed in Zitadel V5. # How the Problems Are Solved - This PR moves app v2beta service and its endpoints to a corresponding to application v2 version. The v2beta service and endpoints are deprecated. - The comments and have been improved and, where not already done, moved from swagger annotations to proto. - All required fields have been marked with (google.api.field_behavior) = REQUIRED and validation rules have been added where missing. - Name ID of the application always `application_id`, previously was also `id` and `app_id`. - Get rid of all `app` abbreviations and name it `application` including the service name, `AppState` -> `ApplicationState` and `AppSorting` -> `ApplicationSorting` - Updated `CreateApplicationRequest`: - renamed `creation_request_type` to `application_type` and all its options to `XY_configuration` instead of `XY_request` - `RegenerateClientSecret` - renamed method to `GenerateClientSecret` - removed `app_type` from request - `ListApplicationRequest`: - removed required `project_id` and provided it as a filter - Type `ApplicationNameQuery` has been renamed to `ApplicationNameFilter` as its usage in the request - Renamed all fields and types from `config` to `configuration` - Updated `DeleteApplicationKeyRequest` - removed `organization_id` - Updated `GetApplicationKeyRequest`: - removed `project_id`, `application_id` and `organization_id`` - Updated `ListApplicationKeysRequest`: - removed oneOf `resource_id` and moved the options into filters - Name ID of the application key always `key_id`. - removed unnecessary package prefixed (`zitadel.application.v2`) - formatted using `buf` # Additional Changes None # Additional Context - part of https://github.com/zitadel/zitadel/issues/10772 - requires backport to v4.x
135 lines
4.1 KiB
Go
135 lines
4.1 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/eventstore"
|
|
"github.com/zitadel/zitadel/internal/repository/project"
|
|
)
|
|
|
|
type ProjectWriteModel struct {
|
|
eventstore.WriteModel
|
|
|
|
Name string
|
|
ProjectRoleAssertion bool
|
|
ProjectRoleCheck bool
|
|
HasProjectCheck bool
|
|
PrivateLabelingSetting domain.PrivateLabelingSetting
|
|
State domain.ProjectState
|
|
}
|
|
|
|
func NewProjectWriteModel(projectID string, resourceOwner string) *ProjectWriteModel {
|
|
return &ProjectWriteModel{
|
|
WriteModel: eventstore.WriteModel{
|
|
AggregateID: projectID,
|
|
ResourceOwner: resourceOwner,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (wm *ProjectWriteModel) Reduce() error {
|
|
for _, event := range wm.Events {
|
|
switch e := event.(type) {
|
|
case *project.ProjectAddedEvent:
|
|
wm.Name = e.Name
|
|
wm.ProjectRoleAssertion = e.ProjectRoleAssertion
|
|
wm.ProjectRoleCheck = e.ProjectRoleCheck
|
|
wm.HasProjectCheck = e.HasProjectCheck
|
|
wm.PrivateLabelingSetting = e.PrivateLabelingSetting
|
|
wm.State = domain.ProjectStateActive
|
|
case *project.ProjectChangeEvent:
|
|
if e.Name != nil {
|
|
wm.Name = *e.Name
|
|
}
|
|
if e.ProjectRoleAssertion != nil {
|
|
wm.ProjectRoleAssertion = *e.ProjectRoleAssertion
|
|
}
|
|
if e.ProjectRoleCheck != nil {
|
|
wm.ProjectRoleCheck = *e.ProjectRoleCheck
|
|
}
|
|
if e.HasProjectCheck != nil {
|
|
wm.HasProjectCheck = *e.HasProjectCheck
|
|
}
|
|
if e.PrivateLabelingSetting != nil {
|
|
wm.PrivateLabelingSetting = *e.PrivateLabelingSetting
|
|
}
|
|
case *project.ProjectDeactivatedEvent:
|
|
if wm.State == domain.ProjectStateRemoved {
|
|
continue
|
|
}
|
|
wm.State = domain.ProjectStateInactive
|
|
case *project.ProjectReactivatedEvent:
|
|
if wm.State == domain.ProjectStateRemoved {
|
|
continue
|
|
}
|
|
wm.State = domain.ProjectStateActive
|
|
case *project.ProjectRemovedEvent:
|
|
wm.State = domain.ProjectStateRemoved
|
|
}
|
|
}
|
|
return wm.WriteModel.Reduce()
|
|
}
|
|
|
|
func (wm *ProjectWriteModel) Query() *eventstore.SearchQueryBuilder {
|
|
return eventstore.NewSearchQueryBuilder(eventstore.ColumnsEvent).
|
|
ResourceOwner(wm.ResourceOwner).
|
|
AddQuery().
|
|
AggregateTypes(project.AggregateType).
|
|
AggregateIDs(wm.AggregateID).
|
|
EventTypes(project.ProjectAddedType,
|
|
project.ProjectChangedType,
|
|
project.ProjectDeactivatedType,
|
|
project.ProjectReactivatedType,
|
|
project.ProjectRemovedType).
|
|
Builder()
|
|
}
|
|
|
|
func (wm *ProjectWriteModel) NewChangedEvent(
|
|
ctx context.Context,
|
|
aggregate *eventstore.Aggregate,
|
|
name *string,
|
|
projectRoleAssertion,
|
|
projectRoleCheck,
|
|
hasProjectCheck *bool,
|
|
privateLabelingSetting *domain.PrivateLabelingSetting,
|
|
) *project.ProjectChangeEvent {
|
|
changes := make([]project.ProjectChanges, 0)
|
|
|
|
oldName := ""
|
|
if name != nil && wm.Name != *name {
|
|
oldName = wm.Name
|
|
changes = append(changes, project.ChangeName(*name))
|
|
}
|
|
if projectRoleAssertion != nil && wm.ProjectRoleAssertion != *projectRoleAssertion {
|
|
changes = append(changes, project.ChangeProjectRoleAssertion(*projectRoleAssertion))
|
|
}
|
|
if projectRoleCheck != nil && wm.ProjectRoleCheck != *projectRoleCheck {
|
|
changes = append(changes, project.ChangeProjectRoleCheck(*projectRoleCheck))
|
|
}
|
|
if hasProjectCheck != nil && wm.HasProjectCheck != *hasProjectCheck {
|
|
changes = append(changes, project.ChangeHasProjectCheck(*hasProjectCheck))
|
|
}
|
|
if privateLabelingSetting != nil && wm.PrivateLabelingSetting != *privateLabelingSetting {
|
|
changes = append(changes, project.ChangePrivateLabelingSetting(*privateLabelingSetting))
|
|
}
|
|
if len(changes) == 0 {
|
|
return nil
|
|
}
|
|
return project.NewProjectChangeEvent(ctx, aggregate, oldName, changes)
|
|
}
|
|
|
|
func isProjectStateExists(state domain.ProjectState) bool {
|
|
return !slices.Contains([]domain.ProjectState{domain.ProjectStateRemoved, domain.ProjectStateUnspecified}, state)
|
|
}
|
|
|
|
// Deprecated: use ProjectAggregateFromWriteModelWithCTX
|
|
func ProjectAggregateFromWriteModel(wm *eventstore.WriteModel) *eventstore.Aggregate {
|
|
return eventstore.AggregateFromWriteModel(wm, project.AggregateType, project.AggregateVersion)
|
|
}
|
|
|
|
func ProjectAggregateFromWriteModelWithCTX(ctx context.Context, wm *eventstore.WriteModel) *eventstore.Aggregate {
|
|
return project.AggregateFromWriteModel(ctx, wm)
|
|
}
|