@@ -16,9 +16,7 @@ import (
1616 "github.com/theopenlane/core/pkg/logx"
1717)
1818
19- // RegisterGalaOrganizationCleanupListeners registers the organization cascade delete on Gala.
20- // This is deliberately independent of the entitlement listeners, the cascade has to run whether or
21- // not billing is configured, otherwise the records an organization owns are left behind entirely
19+ // RegisterGalaOrganizationCleanupListeners registers the organization cascade delete on Gala
2220func RegisterGalaOrganizationCleanupListeners (registry * gala.Registry ) ([]gala.ListenerID , error ) {
2321 return gala .RegisterListeners (registry ,
2422 gala.Definition [eventqueue.MutationGalaPayload ]{
@@ -35,8 +33,7 @@ func RegisterGalaOrganizationCleanupListeners(registry *gala.Registry) ([]gala.L
3533}
3634
3735// handleOrganizationCascadeDelete removes everything an organization owns once it is deleted.
38- // The records are hard deleted and their history rows purged, leaving them soft deleted would keep
39- // the rows, the uploaded objects and the full field values in the history tables indefinitely
36+ // The records are hard deleted and their history rows purged along with files stored in object storage
4037func handleOrganizationCascadeDelete (ctx gala.HandlerContext , payload eventqueue.MutationGalaPayload ) error {
4138 handlerCtx , client , ok := eventqueue .ClientFromHandler (ctx )
4239 if ! ok {
@@ -50,30 +47,34 @@ func handleOrganizationCascadeDelete(ctx gala.HandlerContext, payload eventqueue
5047
5148 cleanupCtx := entgen .NewContext (organizationCleanupContext (handlerCtx .Context ), client )
5249
50+ cleanupCtx = logx .WithFields (cleanupCtx , logx.LogFields {
51+ "organization_id" : orgID ,
52+ })
53+
5354 if err := entgen .OrganizationEdgeCleanup (cleanupCtx , orgID ); err != nil {
54- logx .FromContext (cleanupCtx ).Error ().Err (err ).Str ( "organization_id" , orgID ).
55+ logx .FromContext (cleanupCtx ).Error ().Err (err ).
5556 Msg ("failed to cascade delete organization edges" )
5657
5758 return err
5859 }
5960
6061 // this has to run before the organization row is removed
6162 if err := entgen .PurgeOrganizationHistory (cleanupCtx , organization .ID (orgID )); err != nil {
62- logx .FromContext (cleanupCtx ).Error ().Err (err ).Str ( "organization_id" , orgID ).
63+ logx .FromContext (cleanupCtx ).Error ().Err (err ).
6364 Msg ("failed to purge organization history" )
6465
6566 return err
6667 }
6768
6869 // the organization row goes last, once everything it owned is gone
6970 if _ , err := client .Organization .Delete ().Where (organization .ID (orgID )).Exec (cleanupCtx ); err != nil {
70- logx .FromContext (cleanupCtx ).Error ().Err (err ).Str ( "organization_id" , orgID ).
71+ logx .FromContext (cleanupCtx ).Error ().Err (err ).
7172 Msg ("failed to delete organization" )
7273
7374 return err
7475 }
7576
76- logx .FromContext (cleanupCtx ).Info ().Str ( "organization_id" , orgID ). Msg ("organization cascade delete completed" )
77+ logx .FromContext (cleanupCtx ).Info ().Msg ("organization cascade delete completed" )
7778
7879 return nil
7980}
@@ -84,8 +85,6 @@ func organizationCleanupContext(ctx context.Context) context.Context {
8485 allowCtx := privacy .DecisionContext (ctx , privacy .Allow )
8586 allowCtx = auth .WithCaller (allowCtx , auth .NewWebhookCaller ("" ))
8687
87- // without this the cascaded deletes are rewritten into soft deletes by the mixin, which also
88- // means the file hook never fires and the uploaded objects are orphaned in object storage
8988 allowCtx = entx .SkipSoftDelete (allowCtx )
9089
9190 return contextx .WithPurgeHistory (allowCtx )
0 commit comments