Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entx: mutate before publishing relationship #133

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions entx/template/event_hooks.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@
}
{{ end }}
{{ end }}

if len(relationships) != 0 {
if err := permissions.CreateAuthRelationships(ctx, "{{ $nodeAnnotation.SubjectName }}", objID, relationships...); err != nil {
return nil, fmt.Errorf("relationship request failed with error: %w", err)
}
}

msg := events.ChangeMessage{
EventType: eventType(m.Op()),
Expand All @@ -133,6 +127,12 @@
return retValue, err
}

if len(relationships) != 0 {
if err := permissions.CreateAuthRelationships(ctx, "{{ $nodeAnnotation.SubjectName }}", objID, relationships...); err != nil {
return nil, fmt.Errorf("relationship request failed with error: %w", err)
}
}

if _, err := m.EventsPublisher.PublishChange(ctx, "{{ $nodeAnnotation.SubjectName }}", msg); err != nil {
return nil, fmt.Errorf("failed to publish change: %w", err)
}
Expand Down Expand Up @@ -184,18 +184,18 @@
{{ end }}
{{ end }}

if len(relationships) != 0 {
if err := permissions.DeleteAuthRelationships(ctx, "{{ $nodeAnnotation.SubjectName }}", objID, relationships...); err != nil {
return nil, fmt.Errorf("relationship request failed with error: %w", err)
}
}

// 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 {
return retValue, err
}

if len(relationships) != 0 {
if err := permissions.DeleteAuthRelationships(ctx, "{{ $nodeAnnotation.SubjectName }}", objID, relationships...); err != nil {
return nil, fmt.Errorf("relationship request failed with error: %w", err)
}
}

msg := events.ChangeMessage{
EventType: eventType(m.Op()),
SubjectID: objID,
Expand Down
Loading