Skip to content

Commit

Permalink
associate object relationship only on create (#294)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Siwiec <rizzza@users.noreply.github.com>
  • Loading branch information
rizzza authored Dec 19, 2023
1 parent 6bb9a56 commit b3afa82
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions internal/manualhooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func LoadBalancerHooks() []ent.Hook {
}
}

if len(relationships) != 0 {
if len(relationships) != 0 && eventType(m.Op()) == string(events.CreateChangeType) {
if err := permissions.CreateAuthRelationships(ctx, "load-balancer", objID, relationships...); err != nil {
return nil, fmt.Errorf("relationship request failed with error: %w", err)
}
Expand Down Expand Up @@ -506,7 +506,7 @@ func OriginHooks() []ent.Hook {
}
}

if len(relationships) != 0 {
if len(relationships) != 0 && eventType(m.Op()) == string(events.CreateChangeType) {
if err := permissions.CreateAuthRelationships(ctx, "load-balancer-origin", objID, relationships...); err != nil {
return nil, fmt.Errorf("relationship request failed with error: %w", err)
}
Expand Down Expand Up @@ -789,7 +789,7 @@ func PoolHooks() []ent.Hook {
}
}

if len(relationships) != 0 {
if len(relationships) != 0 && eventType(m.Op()) == string(events.CreateChangeType) {
if err := permissions.CreateAuthRelationships(ctx, "load-balancer-pool", objID, relationships...); err != nil {
return nil, fmt.Errorf("relationship request failed with error: %w", err)
}
Expand Down Expand Up @@ -1055,7 +1055,7 @@ func PortHooks() []ent.Hook {
}
}

if len(relationships) != 0 {
if len(relationships) != 0 && eventType(m.Op()) == string(events.CreateChangeType) {
if err := permissions.CreateAuthRelationships(ctx, "load-balancer-port", objID, relationships...); err != nil {
return nil, fmt.Errorf("relationship request failed with error: %w", err)
}
Expand Down Expand Up @@ -1098,7 +1098,7 @@ func PortHooks() []ent.Hook {
Relation: "loadbalancer",
SubjectID: dbObj.LoadBalancerID,
})

// we have all the info we need, now complete the mutation before we process the event
retValue, err := next.Mutate(ctx, m)
if err != nil {
Expand Down

0 comments on commit b3afa82

Please sign in to comment.