mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-23 05:18:46 +00:00
feat: project view (#90)
* init for views (spooler, handler) * init for views (spooler, handler) * start view in management * granted project * implement granted project view * search granted projects * fix search column * update all projects on project change * search roles * filter org * project members * project grant members * fix tests * application view * project grant search * mock * test appendevents * test appendevents * Update internal/view/query.go Co-authored-by: Livio Amstutz <[email protected]> * Update internal/eventstore/spooler/spooler.go Co-authored-by: Livio Amstutz <[email protected]> * Update internal/view/query.go Co-authored-by: Livio Amstutz <[email protected]> * merge request changes * Update internal/project/repository/view/model/application.go Co-authored-by: Livio Amstutz <[email protected]> * merge request changes * Project view sql (#92) * sql and configs * error handling * sql start in eventstore * on error handling, config * read user on members * Update internal/project/repository/view/application_view.go Co-authored-by: Silvan <[email protected]> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <[email protected]> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <[email protected]> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <[email protected]> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <[email protected]> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <[email protected]> * Update internal/project/repository/view/model/application_query.go Co-authored-by: Silvan <[email protected]> * Update pkg/management/api/grpc/project_grant_converter.go Co-authored-by: Silvan <[email protected]> * Update pkg/management/api/grpc/project_grant_member_converter.go Co-authored-by: Silvan <[email protected]> * Update pkg/management/api/grpc/project_grant_member_converter.go Co-authored-by: Silvan <[email protected]> * Update pkg/management/api/grpc/project_member_converter.go Co-authored-by: Silvan <[email protected]> * Update pkg/management/api/grpc/project_member_converter.go Co-authored-by: Silvan <[email protected]> * Update internal/project/repository/view/model/granted_project.go Co-authored-by: Silvan <[email protected]> * return caos errors * Update internal/project/repository/view/model/granted_project_query.go Co-authored-by: Silvan <[email protected]> * Update internal/project/repository/view/model/project_grant_member.go Co-authored-by: Silvan <[email protected]> * Update internal/project/repository/view/model/project_grant_member_query.go Co-authored-by: Silvan <[email protected]> * Update internal/project/repository/view/model/project_member.go Co-authored-by: Silvan <[email protected]> * Update internal/project/repository/view/model/project_member_query.go Co-authored-by: Silvan <[email protected]> * Update internal/project/repository/view/model/project_role.go Co-authored-by: Silvan <[email protected]> * Update internal/project/repository/view/model/project_role_query.go Co-authored-by: Silvan <[email protected]> * Update pkg/management/api/grpc/application_converter.go Co-authored-by: Silvan <[email protected]> * Update pkg/management/api/grpc/application_converter.go Co-authored-by: Silvan <[email protected]> * Update pkg/management/api/grpc/project_converter.go Co-authored-by: Silvan <[email protected]> * Update pkg/management/api/grpc/project_converter.go Co-authored-by: Silvan <[email protected]> * Update pkg/management/api/grpc/project_converter.go Co-authored-by: Silvan <[email protected]> * Update pkg/management/api/grpc/project_converter.go Co-authored-by: Silvan <[email protected]> * converter fix Co-authored-by: Livio Amstutz <[email protected]> Co-authored-by: Silvan <[email protected]>
This commit is contained in:
co-authored by
Livio Amstutz
Silvan
parent
49d86fdabb
commit
6e105f662e
@@ -0,0 +1,149 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/caos/logging"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/models"
|
||||
"github.com/caos/zitadel/internal/project/model"
|
||||
es_model "github.com/caos/zitadel/internal/project/repository/eventsourcing/model"
|
||||
"github.com/lib/pq"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
GrantedProjectKeyProjectID = "project_id"
|
||||
GrantedProjectKeyGrantID = "grant_id"
|
||||
GrantedProjectKeyOrgID = "org_id"
|
||||
GrantedProjectKeyResourceOwner = "resource_owner"
|
||||
GrantedProjectKeyName = "name"
|
||||
)
|
||||
|
||||
type GrantedProjectView struct {
|
||||
ProjectID string `json:"-" gorm:"column:project_id;primary_key"`
|
||||
OrgID string `json:"-" gorm:"column:org_id;primary_key"`
|
||||
Name string `json:"name" gorm:"column:project_name"`
|
||||
CreationDate time.Time `json:"-" gorm:"column:creation_date"`
|
||||
ChangeDate time.Time `json:"-" gorm:"column:change_date"`
|
||||
State int32 `json:"-" gorm:"column:project_state"`
|
||||
Type int32 `json:"-" gorm:"column:project_type"`
|
||||
ResourceOwner string `json:"-" gorm:"column:resource_owner"`
|
||||
OrgName string `json:"-" gorm:"column:org_name"`
|
||||
OrgDomain string `json:"-" gorm:"column:org_domain"`
|
||||
Sequence uint64 `json:"-" gorm:"column:sequence"`
|
||||
GrantID string `json:"-" gorm:"column:grant_id"`
|
||||
GrantedRoleKeys pq.StringArray `json:"-" gorm:"column:granted_role_keys"`
|
||||
}
|
||||
|
||||
type ProjectGrant struct {
|
||||
GrantID string `json:"grantId"`
|
||||
GrantedOrgID string `json:"grantedOrgId"`
|
||||
RoleKeys []string `json:"roleKeys"`
|
||||
}
|
||||
|
||||
func GrantedProjectFromModel(project *model.GrantedProjectView) *GrantedProjectView {
|
||||
return &GrantedProjectView{
|
||||
ProjectID: project.ProjectID,
|
||||
OrgID: project.OrgID,
|
||||
Name: project.Name,
|
||||
ChangeDate: project.ChangeDate,
|
||||
CreationDate: project.CreationDate,
|
||||
State: int32(project.State),
|
||||
Type: int32(project.Type),
|
||||
ResourceOwner: project.ResourceOwner,
|
||||
OrgName: project.OrgName,
|
||||
GrantID: project.GrantID,
|
||||
GrantedRoleKeys: project.GrantedRoleKeys,
|
||||
Sequence: project.Sequence,
|
||||
}
|
||||
}
|
||||
|
||||
func GrantedProjectToModel(project *GrantedProjectView) *model.GrantedProjectView {
|
||||
return &model.GrantedProjectView{
|
||||
ProjectID: project.ProjectID,
|
||||
OrgID: project.OrgID,
|
||||
Name: project.Name,
|
||||
ChangeDate: project.ChangeDate,
|
||||
CreationDate: project.CreationDate,
|
||||
State: model.ProjectState(project.State),
|
||||
Type: model.ProjectType(project.Type),
|
||||
ResourceOwner: project.ResourceOwner,
|
||||
OrgName: project.OrgName,
|
||||
GrantID: project.GrantID,
|
||||
Sequence: project.Sequence,
|
||||
}
|
||||
}
|
||||
|
||||
func GrantedProjectsToModel(projects []*GrantedProjectView) []*model.GrantedProjectView {
|
||||
result := make([]*model.GrantedProjectView, len(projects))
|
||||
for i, p := range projects {
|
||||
result[i] = GrantedProjectToModel(p)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (p *GrantedProjectView) AppendEvent(event *models.Event) (err error) {
|
||||
p.ChangeDate = event.CreationDate
|
||||
p.Sequence = event.Sequence
|
||||
switch event.Type {
|
||||
case es_model.ProjectAdded:
|
||||
p.State = int32(model.PROJECTSTATE_ACTIVE)
|
||||
p.CreationDate = event.CreationDate
|
||||
p.setRootData(event)
|
||||
err = p.setData(event)
|
||||
case es_model.ProjectChanged:
|
||||
err = p.setData(event)
|
||||
case es_model.ProjectDeactivated:
|
||||
p.State = int32(model.PROJECTSTATE_INACTIVE)
|
||||
case es_model.ProjectReactivated:
|
||||
p.State = int32(model.PROJECTSTATE_ACTIVE)
|
||||
case es_model.ProjectGrantAdded:
|
||||
p.State = int32(model.PROJECTSTATE_ACTIVE)
|
||||
p.CreationDate = event.CreationDate
|
||||
p.setRootData(event)
|
||||
err = p.setProjectGrantData(event)
|
||||
case es_model.ProjectGrantChanged:
|
||||
err = p.setProjectGrantData(event)
|
||||
case es_model.ProjectGrantDeactivated:
|
||||
p.State = int32(model.PROJECTSTATE_INACTIVE)
|
||||
case es_model.ProjectGrantReactivated:
|
||||
p.State = int32(model.PROJECTSTATE_ACTIVE)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *GrantedProjectView) setRootData(event *models.Event) {
|
||||
p.ProjectID = event.AggregateID
|
||||
p.OrgID = event.ResourceOwner
|
||||
p.ResourceOwner = event.ResourceOwner
|
||||
}
|
||||
|
||||
func (p *GrantedProjectView) setData(event *models.Event) error {
|
||||
if err := json.Unmarshal(event.Data, p); err != nil {
|
||||
logging.Log("EVEN-dlo92").WithError(err).Error("could not unmarshal event data")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *GrantedProjectView) setProjectGrantData(event *models.Event) error {
|
||||
grant := new(ProjectGrant)
|
||||
err := grant.SetData(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if grant.GrantedOrgID != "" {
|
||||
p.OrgID = grant.GrantedOrgID
|
||||
}
|
||||
p.GrantID = grant.GrantID
|
||||
p.GrantedRoleKeys = grant.RoleKeys
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ProjectGrant) SetData(event *models.Event) error {
|
||||
if err := json.Unmarshal(event.Data, p); err != nil {
|
||||
logging.Log("EVEN-dlo92").WithError(err).Error("could not unmarshal event data")
|
||||
return caos_errs.ThrowInternal(err, "MODEL-s9ols", "Could not unmarshal data")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user