Skip to content

Commit

Permalink
DGRAPHCORE-355: Allow data deletion for non-internal predicates
Browse files Browse the repository at this point in the history
  • Loading branch information
jbhamra1 committed Aug 8, 2023
1 parent d8d661f commit ab19652
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions query/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func ApplyMutations(ctx context.Context, m *pb.Mutations) (*api.TxnContext, erro
}
m.Edges = edges

err = checkIfDeletingAclOperation(ctx, m.Edges)
err = checkIfDeletingAclOperation(ctx, m.Edges, m.Schema)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -263,7 +263,7 @@ func ToDirectedEdges(gmuList []*dql.Mutation, newUids map[string]uint64) (
return edges, nil
}

func checkIfDeletingAclOperation(ctx context.Context, edges []*pb.DirectedEdge) error {
func checkIfDeletingAclOperation(ctx context.Context, edges []*pb.DirectedEdge, schemas []*pb.SchemaUpdate) error {
// Don't need to make any checks if ACL is not enabled
if !x.WorkerConfig.AclEnabled {
return nil
Expand All @@ -286,6 +286,15 @@ func checkIfDeletingAclOperation(ctx context.Context, edges []*pb.DirectedEdge)

isDeleteAclOperation := false
for _, edge := range edges {
unReservedPredicate := false
for _, schema := range schemas {
if !x.IsReservedPredicate(schema.Predicate) {
unReservedPredicate = true
}
}
if unReservedPredicate {
continue
}
// Disallow deleting of guardians group
if edge.Entity == guardianUid && edge.Op == pb.DirectedEdge_DEL {
isDeleteAclOperation = true
Expand All @@ -298,7 +307,7 @@ func checkIfDeletingAclOperation(ctx context.Context, edges []*pb.DirectedEdge)
}
}
if isDeleteAclOperation {
return errors.Errorf("Properties of guardians group and groot user cannot be deleted.")
return errors.Errorf("Reserved properties of guardians group and groot user cannot be deleted.")
}
return nil
}

0 comments on commit ab19652

Please sign in to comment.