mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-26 09:37:47 +00:00
6e105f662e
* 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 <livio.a@gmail.com> * Update internal/eventstore/spooler/spooler.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * Update internal/view/query.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * merge request changes * Update internal/project/repository/view/model/application.go Co-authored-by: Livio Amstutz <livio.a@gmail.com> * 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 <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/application_query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_grant_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_grant_member_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_grant_member_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_member_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_member_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/granted_project.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * return caos errors * Update internal/project/repository/view/model/granted_project_query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_grant_member.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_grant_member_query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_member.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_member_query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_role.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update internal/project/repository/view/model/project_role_query.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/application_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/application_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * Update pkg/management/api/grpc/project_converter.go Co-authored-by: Silvan <silvan.reusser@gmail.com> * converter fix Co-authored-by: Livio Amstutz <livio.a@gmail.com> Co-authored-by: Silvan <silvan.reusser@gmail.com>
102 lines
2.5 KiB
Go
102 lines
2.5 KiB
Go
package model
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/caos/logging"
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
"github.com/caos/zitadel/internal/project/model"
|
|
)
|
|
|
|
type ProjectMember struct {
|
|
es_models.ObjectRoot
|
|
UserID string `json:"userId,omitempty"`
|
|
Roles []string `json:"roles,omitempty"`
|
|
}
|
|
|
|
func GetProjectMember(members []*ProjectMember, id string) (int, *ProjectMember) {
|
|
for i, m := range members {
|
|
if m.UserID == id {
|
|
return i, m
|
|
}
|
|
}
|
|
return -1, nil
|
|
}
|
|
|
|
func ProjectMembersToModel(members []*ProjectMember) []*model.ProjectMember {
|
|
convertedMembers := make([]*model.ProjectMember, len(members))
|
|
for i, m := range members {
|
|
convertedMembers[i] = ProjectMemberToModel(m)
|
|
}
|
|
return convertedMembers
|
|
}
|
|
|
|
func ProjectMembersFromModel(members []*model.ProjectMember) []*ProjectMember {
|
|
convertedMembers := make([]*ProjectMember, len(members))
|
|
for i, m := range members {
|
|
convertedMembers[i] = ProjectMemberFromModel(m)
|
|
}
|
|
return convertedMembers
|
|
}
|
|
|
|
func ProjectMemberFromModel(member *model.ProjectMember) *ProjectMember {
|
|
return &ProjectMember{
|
|
ObjectRoot: member.ObjectRoot,
|
|
UserID: member.UserID,
|
|
Roles: member.Roles,
|
|
}
|
|
}
|
|
|
|
func ProjectMemberToModel(member *ProjectMember) *model.ProjectMember {
|
|
return &model.ProjectMember{
|
|
ObjectRoot: member.ObjectRoot,
|
|
UserID: member.UserID,
|
|
Roles: member.Roles,
|
|
}
|
|
}
|
|
|
|
func (p *Project) appendAddMemberEvent(event *es_models.Event) error {
|
|
member := &ProjectMember{}
|
|
err := member.setData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
member.ObjectRoot.CreationDate = event.CreationDate
|
|
p.Members = append(p.Members, member)
|
|
return nil
|
|
}
|
|
|
|
func (p *Project) appendChangeMemberEvent(event *es_models.Event) error {
|
|
member := &ProjectMember{}
|
|
err := member.setData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if i, m := GetProjectMember(p.Members, member.UserID); m != nil {
|
|
p.Members[i] = member
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *Project) appendRemoveMemberEvent(event *es_models.Event) error {
|
|
member := &ProjectMember{}
|
|
err := member.setData(event)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if i, m := GetProjectMember(p.Members, member.UserID); m != nil {
|
|
p.Members[i] = p.Members[len(p.Members)-1]
|
|
p.Members[len(p.Members)-1] = nil
|
|
p.Members = p.Members[:len(p.Members)-1]
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *ProjectMember) setData(event *es_models.Event) error {
|
|
m.ObjectRoot.AppendEvent(event)
|
|
if err := json.Unmarshal(event.Data, m); err != nil {
|
|
logging.Log("EVEN-e4dkp").WithError(err).Error("could not unmarshal event data")
|
|
return err
|
|
}
|
|
return nil
|
|
}
|