Skip to content

Commit 4a722ea

Browse files
fix feature tuple deletion
Signed-off-by: Sarah Funkhouser <147884153+golanglemonade@users.noreply.github.com>
1 parent 1485269 commit 4a722ea

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

internal/ent/hooks/orgmodule.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,14 @@ func HookOrgModuleUpdate() ent.Hook {
6262
return handleOrgModuleUpdate(ctx, omm, next)
6363
case ent.OpDeleteOne:
6464
return handleOrgModuleDelete(ctx, omm, next)
65-
case ent.OpUpdate:
65+
case ent.OpUpdate, ent.OpDelete:
66+
// OpUpdate is a soft delete, OpDelete is the hard delete the organization cascade uses
6667
return handleOrgModuleBulkDelete(ctx, omm, next)
6768
default:
6869
return next.Mutate(ctx, omm)
6970
}
7071
})
71-
}, ent.OpUpdateOne|ent.OpDeleteOne|ent.OpUpdate)
72+
}, ent.OpUpdateOne|ent.OpDeleteOne|ent.OpUpdate|ent.OpDelete)
7273
}
7374

7475
func handleOrgModuleUpdate(ctx context.Context, omm *generated.OrgModuleMutation, next ent.Mutator) (generated.Value, error) {
@@ -163,7 +164,8 @@ func handleOrgModuleDelete(ctx context.Context, omm *generated.OrgModuleMutation
163164
}
164165

165166
func handleOrgModuleBulkDelete(ctx context.Context, omm *generated.OrgModuleMutation, next ent.Mutator) (generated.Value, error) {
166-
if !entx.CheckIsSoftDeleteType(ctx, omm.Type()) {
167+
// a bulk update is only a delete when it is the soft delete rewrite, a bulk delete always is
168+
if !omm.Op().Is(ent.OpDelete) && !entx.CheckIsSoftDeleteType(ctx, omm.Type()) {
167169
return next.Mutate(ctx, omm)
168170
}
169171

internal/graphapi/organization_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,15 @@ func TestMutationOrganizationCascadeDelete(t *testing.T) {
11351135
orgTuples, err := suite.client.fga.GetTuplesForObject(context.Background(), "organization:"+org.ID)
11361136
assert.NilError(t, err)
11371137
assert.Check(t, is.Len(orgTuples, 0), "organization relationship tuples should be cleaned out of FGA")
1138+
1139+
// ensure all tuples, like feature tuples are cleaned up
1140+
allTuples, err := suite.client.fga.GetAllTuples(context.Background())
1141+
assert.NilError(t, err)
1142+
1143+
for _, tup := range allTuples {
1144+
assert.Check(t, tup.Key.User != "organization:"+org.ID,
1145+
"tuple %s#%s@%s should have been cleaned out of FGA", tup.Key.Object, tup.Key.Relation, tup.Key.User)
1146+
}
11381147
}
11391148

11401149
// assertHistoryExists checks whether the history rows for the given task and file are present

0 commit comments

Comments
 (0)