fix: set project changes correctly in application view model (#1469)

This commit is contained in:
Livio Amstutz 2021-03-25 11:03:27 +01:00 committed by GitHub
parent 08b066b3a2
commit d7255130a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}