mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 01:37:31 +00:00
fix: app by id, views with computed objects (#583)
* feat: read app by id if my events * fix: handlers if no sublist * fix: removed app * fix: removed project * fix: removed app * fix: removed app * fix: app by id with projectid
This commit is contained in:
@@ -33,6 +33,7 @@ type AppState int32
|
||||
const (
|
||||
AppStateActive AppState = iota
|
||||
AppStateInactive
|
||||
AppStateRemoved
|
||||
)
|
||||
|
||||
type AppType int32
|
||||
|
@@ -9,9 +9,11 @@ import (
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
func ApplicationByID(db *gorm.DB, table, appID string) (*model.ApplicationView, error) {
|
||||
func ApplicationByID(db *gorm.DB, table, projectID, appID string) (*model.ApplicationView, error) {
|
||||
app := new(model.ApplicationView)
|
||||
query := repository.PrepareGetByKey(table, model.ApplicationSearchKey(proj_model.AppSearchKeyAppID), appID)
|
||||
projectIDQuery := &model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyProjectID, Value: projectID, Method: global_model.SearchMethodEquals}
|
||||
appIDQuery := &model.ApplicationSearchQuery{Key: proj_model.AppSearchKeyAppID, Value: appID, Method: global_model.SearchMethodEquals}
|
||||
query := repository.PrepareGetByQuery(table, projectIDQuery, appIDQuery)
|
||||
err := query(db, app)
|
||||
if caos_errs.IsNotFound(err) {
|
||||
return nil, caos_errs.ThrowNotFound(nil, "VIEW-DGdfx", "Errors.Application.NotFound")
|
||||
|
@@ -130,6 +130,32 @@ func ApplicationViewsToModel(roles []*ApplicationView) []*model.ApplicationView
|
||||
return result
|
||||
}
|
||||
|
||||
func (a *ApplicationView) AppendEventIfMyApp(event *models.Event) (err error) {
|
||||
view := new(ApplicationView)
|
||||
switch event.Type {
|
||||
case es_model.ApplicationAdded:
|
||||
err = view.SetData(event)
|
||||
case es_model.ApplicationChanged,
|
||||
es_model.OIDCConfigAdded,
|
||||
es_model.OIDCConfigChanged,
|
||||
es_model.ApplicationDeactivated,
|
||||
es_model.ApplicationReactivated:
|
||||
err := view.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case es_model.ApplicationRemoved:
|
||||
return view.SetData(event)
|
||||
case es_model.ProjectRemoved:
|
||||
return a.AppendEvent(event)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
if view.ID == a.ID {
|
||||
return a.AppendEvent(event)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (a *ApplicationView) AppendEvent(event *models.Event) (err error) {
|
||||
a.Sequence = event.Sequence
|
||||
a.ChangeDate = event.CreationDate
|
||||
@@ -156,6 +182,8 @@ func (a *ApplicationView) AppendEvent(event *models.Event) (err error) {
|
||||
a.State = int32(model.AppStateInactive)
|
||||
case es_model.ApplicationReactivated:
|
||||
a.State = int32(model.AppStateActive)
|
||||
case es_model.ApplicationRemoved, es_model.ProjectRemoved:
|
||||
a.State = int32(model.AppStateRemoved)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user