mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-14 20:08:02 +00:00
74688394d8
* docs: add scope to request private labeling * feat: add enum to project * fix: remove unused code, add private labeling setting to query side * fix: set private labeling depending on setting * fix: private labeling depending on project setting * Update proto/zitadel/management.proto Co-authored-by: Livio Amstutz <livio.a@gmail.com> * fix: rename sql file * fix: private labeling setting Co-authored-by: Livio Amstutz <livio.a@gmail.com>
96 lines
2.3 KiB
Go
96 lines
2.3 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/caos/logging"
|
|
|
|
es_models "github.com/caos/zitadel/internal/eventstore/v1/models"
|
|
"github.com/caos/zitadel/internal/project/model"
|
|
)
|
|
|
|
const (
|
|
ProjectVersion = "v1"
|
|
)
|
|
|
|
type Project struct {
|
|
es_models.ObjectRoot
|
|
Name string `json:"name,omitempty"`
|
|
ProjectRoleAssertion bool `json:"projectRoleAssertion,omitempty"`
|
|
ProjectRoleCheck bool `json:"projectRoleCheck,omitempty"`
|
|
HasProjectCheck bool `json:"hasProjectCheck,omitempty"`
|
|
State int32 `json:"-"`
|
|
}
|
|
|
|
func ProjectToModel(project *Project) *model.Project {
|
|
return &model.Project{
|
|
ObjectRoot: project.ObjectRoot,
|
|
Name: project.Name,
|
|
ProjectRoleAssertion: project.ProjectRoleAssertion,
|
|
ProjectRoleCheck: project.ProjectRoleCheck,
|
|
State: model.ProjectState(project.State),
|
|
}
|
|
}
|
|
|
|
func ProjectFromEvents(project *Project, events ...*es_models.Event) (*Project, error) {
|
|
if project == nil {
|
|
project = &Project{}
|
|
}
|
|
|
|
return project, project.AppendEvents(events...)
|
|
}
|
|
|
|
func (p *Project) AppendEvents(events ...*es_models.Event) error {
|
|
for _, event := range events {
|
|
if err := p.AppendEvent(event); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *Project) AppendEvent(event *es_models.Event) error {
|
|
p.ObjectRoot.AppendEvent(event)
|
|
|
|
switch event.Type {
|
|
case ProjectAdded, ProjectChanged:
|
|
return p.AppendAddProjectEvent(event)
|
|
case ProjectDeactivated:
|
|
return p.appendDeactivatedEvent()
|
|
case ProjectReactivated:
|
|
return p.appendReactivatedEvent()
|
|
case ProjectRemoved:
|
|
return p.appendRemovedEvent()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *Project) AppendAddProjectEvent(event *es_models.Event) error {
|
|
p.SetData(event)
|
|
p.State = int32(model.ProjectStateActive)
|
|
return nil
|
|
}
|
|
|
|
func (p *Project) appendDeactivatedEvent() error {
|
|
p.State = int32(model.ProjectStateInactive)
|
|
return nil
|
|
}
|
|
|
|
func (p *Project) appendReactivatedEvent() error {
|
|
p.State = int32(model.ProjectStateActive)
|
|
return nil
|
|
}
|
|
|
|
func (p *Project) appendRemovedEvent() error {
|
|
p.State = int32(model.ProjectStateRemoved)
|
|
return nil
|
|
}
|
|
|
|
func (p *Project) SetData(event *es_models.Event) error {
|
|
if err := json.Unmarshal(event.Data, p); err != nil {
|
|
logging.Log("EVEN-lo9sr").WithError(err).Error("could not unmarshal event data")
|
|
return err
|
|
}
|
|
return nil
|
|
}
|