From d7255130a47ec5318a5ac86a23625e596b88e611 Mon Sep 17 00:00:00 2001 From: Livio Amstutz Date: Thu, 25 Mar 2021 11:03:27 +0100 Subject: [PATCH] fix: set project changes correctly in application view model (#1469) --- .../repository/view/model/application.go | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/internal/project/repository/view/model/application.go b/internal/project/repository/view/model/application.go index f47711425b..5a5a3a836e 100644 --- a/internal/project/repository/view/model/application.go +++ b/internal/project/repository/view/model/application.go @@ -179,10 +179,7 @@ func (a *ApplicationView) AppendEvent(event *models.Event) (err error) { case es_model.APIConfigChanged: return a.SetData(event) case es_model.ProjectChanged: - project := &es_model.Project{} - project.SetData(event) - a.ProjectRoleAssertion = project.ProjectRoleAssertion - a.ProjectRoleCheck = project.ProjectRoleAssertion + return a.setProjectChanges(event) case es_model.ApplicationDeactivated: a.State = int32(model.AppStateInactive) case es_model.ApplicationReactivated: @@ -225,3 +222,21 @@ func (a *ApplicationView) setCompliance() { a.NoneCompliant = compliance.NoneCompliant a.ComplianceProblems = compliance.Problems } + +func (a *ApplicationView) setProjectChanges(event *models.Event) error { + changes := struct { + ProjectRoleAssertion *bool `json:"projectRoleAssertion,omitempty"` + ProjectRoleCheck *bool `json:"projectRoleCheck,omitempty"` + }{} + if err := json.Unmarshal(event.Data, &changes); err != nil { + logging.Log("EVEN-DFbfg").WithError(err).Error("could not unmarshal event data") + return caos_errs.ThrowInternal(err, "MODEL-Bw221", "Could not unmarshal data") + } + if changes.ProjectRoleAssertion != nil { + a.ProjectRoleAssertion = *changes.ProjectRoleAssertion + } + if changes.ProjectRoleCheck != nil { + a.ProjectRoleCheck = *changes.ProjectRoleCheck + } + return nil +}