Fabi 74688394d8
feat: set private labeling setting on project (#2184)
* 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>
2021-08-24 08:34:10 +02:00

68 lines
1.6 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"
)
type ProjectRole struct {
es_models.ObjectRoot
Key string `json:"key,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Group string `json:"group,omitempty"`
}
func GetProjectRole(roles []*ProjectRole, key string) (int, *ProjectRole) {
for i, r := range roles {
if r.Key == key {
return i, r
}
}
return -1, nil
}
func ProjectRolesToModel(roles []*ProjectRole) []*model.ProjectRole {
convertedRoles := make([]*model.ProjectRole, len(roles))
for i, r := range roles {
convertedRoles[i] = ProjectRoleToModel(r)
}
return convertedRoles
}
func ProjectRolesFromModel(roles []*model.ProjectRole) []*ProjectRole {
convertedRoles := make([]*ProjectRole, len(roles))
for i, r := range roles {
convertedRoles[i] = ProjectRoleFromModel(r)
}
return convertedRoles
}
func ProjectRoleFromModel(role *model.ProjectRole) *ProjectRole {
return &ProjectRole{
ObjectRoot: role.ObjectRoot,
Key: role.Key,
DisplayName: role.DisplayName,
Group: role.Group,
}
}
func ProjectRoleToModel(role *ProjectRole) *model.ProjectRole {
return &model.ProjectRole{
ObjectRoot: role.ObjectRoot,
Key: role.Key,
DisplayName: role.DisplayName,
Group: role.Group,
}
}
func (r *ProjectRole) setData(event *es_models.Event) error {
r.ObjectRoot.AppendEvent(event)
if err := json.Unmarshal(event.Data, r); err != nil {
logging.Log("EVEN-d9euw").WithError(err).Error("could not unmarshal event data")
return err
}
return nil
}