-
Notifications
You must be signed in to change notification settings - Fork 47
feat(store): policy, relation, and resource reads skip soft-deleted rows #1936
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -323,3 +323,26 @@ func (s *RelationRepositoryTestSuite) TestDeleteByID() { | |
| func TestRelationRepository(t *testing.T) { | ||
| suite.Run(t, new(RelationRepositoryTestSuite)) | ||
| } | ||
|
|
||
| func (s *RelationRepositoryTestSuite) TestSkipsSoftDeletedRelations() { | ||
| deleted := s.relations[0] | ||
| _, err := s.client.ExecContext(s.ctx, "UPDATE relations SET deleted_at = now() WHERE id = $1", deleted.ID) | ||
| if err != nil { | ||
| s.T().Fatal(err) | ||
| } | ||
|
|
||
| _, err = s.repository.Get(s.ctx, deleted.ID) | ||
| s.Assert().ErrorIs(err, relation.ErrNotExist) | ||
|
|
||
| got, err := s.repository.List(s.ctx, relation.Filter{Subject: deleted.Subject, Object: deleted.Object}) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only one relation matches this subject and object, and we just soft-deleted it. So |
||
| s.Assert().NoError(err) | ||
| for _, r := range got { | ||
| s.Assert().NotEqual(deleted.ID, r.ID) | ||
| } | ||
|
|
||
| byFields, err := s.repository.GetByFields(s.ctx, deleted) | ||
| s.Assert().NoError(err) | ||
| for _, r := range byFields { | ||
| s.Assert().NotEqual(deleted.ID, r.ID) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -411,3 +411,40 @@ func (s *ResourceRepositoryTestSuite) TestUpdate() { | |
| func TestResourceRepository(t *testing.T) { | ||
| suite.Run(t, new(ResourceRepositoryTestSuite)) | ||
| } | ||
|
|
||
| func (s *ResourceRepositoryTestSuite) TestSkipsSoftDeletedResources() { | ||
| deleted := s.resources[0] | ||
| _, err := s.client.ExecContext(s.ctx, "UPDATE resources SET deleted_at = now() WHERE id = $1", deleted.ID) | ||
| if err != nil { | ||
| s.T().Fatal(err) | ||
| } | ||
|
|
||
| _, err = s.repository.GetByID(s.ctx, deleted.ID) | ||
| s.Assert().ErrorIs(err, resource.ErrNotExist) | ||
|
|
||
| _, err = s.repository.GetByURN(s.ctx, deleted.URN) | ||
| s.Assert().ErrorIs(err, resource.ErrNotExist) | ||
|
|
||
| got, err := s.repository.List(s.ctx, resource.Filter{ProjectID: deleted.ProjectID}) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This project has only one resource, and we just soft-deleted it. So |
||
| s.Assert().NoError(err) | ||
| for _, r := range got { | ||
| s.Assert().NotEqual(deleted.ID, r.ID) | ||
| } | ||
|
|
||
| updated := deleted | ||
| updated.Title = "changed" | ||
| _, err = s.repository.Update(s.ctx, updated) | ||
| s.Assert().ErrorIs(err, resource.ErrNotExist) | ||
|
|
||
| // the id of a deleted row is still taken; a create that reuses it with a new URN must conflict | ||
| _, err = s.repository.Create(s.ctx, resource.Resource{ | ||
| ID: deleted.ID, | ||
| URN: "urn-reusing-a-deleted-id", | ||
| Name: "reused-id", | ||
| ProjectID: deleted.ProjectID, | ||
| NamespaceID: deleted.NamespaceID, | ||
| PrincipalID: deleted.PrincipalID, | ||
| PrincipalType: deleted.PrincipalType, | ||
| }) | ||
| s.Assert().ErrorIs(err, resource.ErrConflict) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lookups only fill the org id and title on the audit record. Once projects and groups are soft-deleted, a policy removed under one of them gets no org id and drops out of the org's audit view. The org title lookup in the audit insert reads all rows today. Can we keep these three on the plain From so the trail stays attributed?