mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-06 10:58:48 +00:00
fix: cleanup (#1312)
* fix: remove unused code * fix: remove unused code * fix: remove unused code * fix: remove unused code
This commit is contained in:
@@ -1,16 +1,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/caos/logging"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
||||
"github.com/caos/zitadel/internal/usergrant/model"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
const (
|
||||
UserGrantVersion = "v1"
|
||||
)
|
||||
|
||||
type UserGrant struct {
|
||||
@@ -22,77 +13,3 @@ type UserGrant struct {
|
||||
GrantID string `json:"grantId,omitempty"`
|
||||
RoleKeys []string `json:"roleKeys,omitempty"`
|
||||
}
|
||||
|
||||
type UserGrantID struct {
|
||||
es_models.ObjectRoot
|
||||
GrantID string `json:"grantId"`
|
||||
}
|
||||
|
||||
func (g *UserGrant) Changes(changed *UserGrant) map[string]interface{} {
|
||||
changes := make(map[string]interface{}, 1)
|
||||
if !reflect.DeepEqual(g.RoleKeys, changed.RoleKeys) {
|
||||
changes["roleKeys"] = changed.RoleKeys
|
||||
}
|
||||
return changes
|
||||
}
|
||||
|
||||
func UserGrantFromModel(grant *model.UserGrant) *UserGrant {
|
||||
return &UserGrant{
|
||||
ObjectRoot: grant.ObjectRoot,
|
||||
UserID: grant.UserID,
|
||||
ProjectID: grant.ProjectID,
|
||||
GrantID: grant.GrantID,
|
||||
State: int32(grant.State),
|
||||
RoleKeys: grant.RoleKeys,
|
||||
}
|
||||
}
|
||||
|
||||
func UserGrantToModel(grant *UserGrant) *model.UserGrant {
|
||||
return &model.UserGrant{
|
||||
ObjectRoot: grant.ObjectRoot,
|
||||
UserID: grant.UserID,
|
||||
ProjectID: grant.ProjectID,
|
||||
GrantID: grant.GrantID,
|
||||
State: model.UserGrantState(grant.State),
|
||||
RoleKeys: grant.RoleKeys,
|
||||
}
|
||||
}
|
||||
|
||||
func (g *UserGrant) AppendEvents(events ...*es_models.Event) error {
|
||||
for _, event := range events {
|
||||
if err := g.AppendEvent(event); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *UserGrant) AppendEvent(event *es_models.Event) error {
|
||||
g.ObjectRoot.AppendEvent(event)
|
||||
switch event.Type {
|
||||
case UserGrantAdded,
|
||||
UserGrantChanged,
|
||||
UserGrantCascadeChanged:
|
||||
return g.setData(event)
|
||||
case UserGrantDeactivated:
|
||||
g.appendGrantStateEvent(model.UserGrantStateInactive)
|
||||
case UserGrantReactivated:
|
||||
g.appendGrantStateEvent(model.UserGrantStateActive)
|
||||
case UserGrantRemoved,
|
||||
UserGrantCascadeRemoved:
|
||||
g.appendGrantStateEvent(model.UserGrantStateRemoved)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *UserGrant) appendGrantStateEvent(state model.UserGrantState) {
|
||||
g.State = int32(state)
|
||||
}
|
||||
|
||||
func (g *UserGrant) setData(event *es_models.Event) error {
|
||||
if err := json.Unmarshal(event.Data, g); err != nil {
|
||||
logging.Log("EVEN-lso9x").WithError(err).Error("could not unmarshal event data")
|
||||
return caos_errs.ThrowInternal(err, "MODEL-o0se3", "could not unmarshal event")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user