( ctx context.Context, exec sqlExecutor, actor MutationActor, kind ResourceKind, id string, expectedVersion int64, )
| 610 | } |
| 611 | |
| 612 | func (k *Kernel) deleteRawWithExecutor( |
| 613 | ctx context.Context, |
| 614 | exec sqlExecutor, |
| 615 | actor MutationActor, |
| 616 | kind ResourceKind, |
| 617 | id string, |
| 618 | expectedVersion int64, |
| 619 | ) error { |
| 620 | if expectedVersion < 0 { |
| 621 | return fmt.Errorf("%w: expected_version cannot be negative: %d", ErrValidation, expectedVersion) |
| 622 | } |
| 623 | |
| 624 | existing, found, err := lookupRecordWithExecutor(ctx, exec, kind, id) |
| 625 | if err != nil { |
| 626 | return err |
| 627 | } |
| 628 | if !found { |
| 629 | return ErrNotFound |
| 630 | } |
| 631 | if err := validateActorWriteAccess(actor, existing.Kind, existing.Scope); err != nil { |
| 632 | return err |
| 633 | } |
| 634 | if existing.Source != actor.Source { |
| 635 | return fmt.Errorf( |
| 636 | "%w: actor cannot mutate source %q/%q", |
| 637 | ErrPermissionDenied, |
| 638 | existing.Source.Kind, |
| 639 | existing.Source.ID, |
| 640 | ) |
| 641 | } |
| 642 | |
| 643 | result, err := exec.ExecContext(ctx, deleteRecordByVersionQuery, kind, id, expectedVersion) |
| 644 | if err != nil { |
| 645 | return fmt.Errorf("resources: delete record %q/%q: %w", kind, id, err) |
| 646 | } |
| 647 | rowsAffected, err := result.RowsAffected() |
| 648 | if err != nil { |
| 649 | return fmt.Errorf("resources: rows affected for delete %q/%q: %w", kind, id, err) |
| 650 | } |
| 651 | if rowsAffected == 0 { |
| 652 | return fmt.Errorf("%w: expected version %d", ErrConflict, expectedVersion) |
| 653 | } |
| 654 | return nil |
| 655 | } |
| 656 | |
| 657 | func (k *Kernel) prepareListRaw( |
| 658 | actor MutationActor, |
no test coverage detected