2020-04-23 05:54:40 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2021-08-24 06:34:10 +00:00
|
|
|
"reflect"
|
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
"github.com/zitadel/logging"
|
2021-08-24 06:34:10 +00:00
|
|
|
|
2022-04-26 23:01:45 +00:00
|
|
|
es_models "github.com/zitadel/zitadel/internal/eventstore/v1/models"
|
2020-04-23 05:54:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ProjectGrant struct {
|
|
|
|
es_models.ObjectRoot
|
|
|
|
State int32 `json:"-"`
|
|
|
|
GrantID string `json:"grantId,omitempty"`
|
|
|
|
GrantedOrgID string `json:"grantedOrgId,omitempty"`
|
|
|
|
RoleKeys []string `json:"roleKeys,omitempty"`
|
|
|
|
Members []*ProjectGrantMember `json:"-"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProjectGrantID struct {
|
|
|
|
es_models.ObjectRoot
|
|
|
|
GrantID string `json:"grantId"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *ProjectGrant) Changes(changed *ProjectGrant) map[string]interface{} {
|
|
|
|
changes := make(map[string]interface{}, 1)
|
|
|
|
changes["grantId"] = g.GrantID
|
|
|
|
if !reflect.DeepEqual(g.RoleKeys, changed.RoleKeys) {
|
|
|
|
changes["roleKeys"] = changed.RoleKeys
|
|
|
|
}
|
|
|
|
return changes
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *ProjectGrant) getData(event *es_models.Event) error {
|
|
|
|
g.ObjectRoot.AppendEvent(event)
|
|
|
|
if err := json.Unmarshal(event.Data, g); err != nil {
|
|
|
|
logging.Log("EVEN-4h6gd").WithError(err).Error("could not unmarshal event data")
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|