mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 02:54:20 +00:00
fix: handle events of PATs correctly (#4024)
This commit is contained in:
parent
3855ec2ab5
commit
9fc8a43642
@ -66,7 +66,8 @@ func TokenViewToModel(token *TokenView) *usr_model.TokenView {
|
||||
func (t *TokenView) AppendEventIfMyToken(event *es_models.Event) (err error) {
|
||||
view := new(TokenView)
|
||||
switch eventstore.EventType(event.Type) {
|
||||
case user_repo.UserTokenAddedType:
|
||||
case user_repo.UserTokenAddedType,
|
||||
user_repo.PersonalAccessTokenAddedType:
|
||||
view.setRootData(event)
|
||||
err = view.setData(event)
|
||||
case user_repo.UserTokenRemovedType:
|
||||
@ -94,6 +95,8 @@ func (t *TokenView) AppendEventIfMyToken(event *es_models.Event) (err error) {
|
||||
t.Deactivated = false
|
||||
}
|
||||
return nil
|
||||
case user_repo.PersonalAccessTokenRemovedType:
|
||||
return t.appendPATRemoved(event)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
@ -168,6 +171,17 @@ func (t *TokenView) appendRefreshTokenRemoved(event *es_models.Event) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TokenView) appendPATRemoved(event *es_models.Event) error {
|
||||
pat, err := eventToMap(event)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if pat["tokenId"] == t.ID && t.IsPAT {
|
||||
t.Deactivated = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func eventToMap(event *es_models.Event) (map[string]interface{}, error) {
|
||||
m := make(map[string]interface{})
|
||||
if err := json.Unmarshal(event.Data, &m); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user