-
Notifications
You must be signed in to change notification settings - Fork 350
feat: support for rel and namespace deprecation #2504
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 |
|---|---|---|
|
|
@@ -306,6 +306,214 @@ func TestValidateRelationshipOperations(t *testing.T) { | |
| core.RelationTupleUpdate_CREATE, | ||
| "subjects of type `user with somecaveat and expiration` are not allowed on relation `resource#viewer`", | ||
| }, | ||
| { | ||
| "deprecation relation test", | ||
| `use deprecation | ||
| definition testuser {} | ||
| definition user {} | ||
|
|
||
| definition document { | ||
| @deprecated(error,"deprecated, migrate away") | ||
| relation editor: testuser | ||
| relation viewer: user | ||
| }`, | ||
| "document:foo#editor@testuser:tom", | ||
| core.RelationTupleUpdate_CREATE, | ||
| "relation document#editor is deprecated: deprecated, migrate away", | ||
| }, | ||
| { | ||
| "deprecated namespace test", | ||
| `use deprecation | ||
| @deprecated(error, "deprecated, migrate away") | ||
| definition testuser {} | ||
| definition user {} | ||
|
|
||
| definition document { | ||
| relation editor: testuser | ||
| }`, | ||
| "document:foo#editor@testuser:tom", | ||
| core.RelationTupleUpdate_CREATE, | ||
| "resource_type testuser is deprecated: deprecated, migrate away", | ||
| }, | ||
| { | ||
| "deprecated relation subject type", | ||
| `use deprecation | ||
| definition user {} | ||
| definition testuser {} | ||
|
|
||
| definition platform { | ||
| relation viewer: user | @deprecated(warn, "comments") testuser | ||
| relation auditor: user | @deprecated(error, "test") testuser | ||
| }`, | ||
| "platform:foo#auditor@testuser:test", | ||
| core.RelationTupleUpdate_CREATE, | ||
| "resource_type testuser is deprecated: test", | ||
| }, | ||
| { | ||
| "deprecated relation same subject type with wildcard", | ||
| `use deprecation | ||
|
Member
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. add tests for deprecation of, say, a subject type without expiration but the one with expiration is still valid (and vice versa) and caveats as well
Contributor
Author
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. added tests of these scenarios including the log and err messages, example "resource_type user with caveat |
||
| definition user {} | ||
| definition testuser {} | ||
|
|
||
| definition platform { | ||
| relation viewer: user | @deprecated(warn, "comments") testuser | ||
| relation auditor: testuser | @deprecated(error, "no wildcard please") testuser:* | ||
| }`, | ||
| "platform:foo#auditor@testuser:*", | ||
| core.RelationTupleUpdate_CREATE, | ||
| "wildcard allowed type testuser:* is deprecated: no wildcard please", | ||
|
Member
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. add the same test with writing the non-wildcard and ensure it does not return an error/warning |
||
| }, | ||
| { | ||
| "deprecated relation same subject type with write on non-wildcard relation", | ||
| `use deprecation | ||
| definition user {} | ||
| definition testuser {} | ||
|
|
||
| definition platform { | ||
| relation viewer: user | @deprecated(warn, "comments") testuser | ||
| relation auditor: testuser | @deprecated(error, "no wildcard please") testuser:* | ||
| }`, | ||
| "platform:foo#auditor@testuser:test1", | ||
| core.RelationTupleUpdate_CREATE, | ||
| "", | ||
| }, | ||
| { | ||
| "deprecated subject without expiration when expiration required", | ||
| `use expiration | ||
| use deprecation | ||
|
|
||
| @deprecated(error, "do not use testuser") | ||
| definition testuser {} | ||
|
|
||
| definition document { | ||
| relation viewer: testuser with expiration | ||
| }`, | ||
| "document:foo#viewer@testuser:tom", | ||
| core.RelationTupleUpdate_CREATE, | ||
| "subjects of type `testuser` are not allowed on relation `document#viewer`; did you mean `testuser with expiration`?", | ||
| }, | ||
| { | ||
| "deprecated subject with expiration", | ||
| `use expiration | ||
| use deprecation | ||
|
|
||
| @deprecated(error, "do not use testuser") | ||
| definition testuser {} | ||
|
|
||
| definition document { | ||
| relation viewer: testuser with expiration | ||
| }`, | ||
| "document:foo#viewer@testuser:tom[expiration:2021-01-01T00:00:00Z]", | ||
| core.RelationTupleUpdate_CREATE, | ||
| "resource_type testuser is deprecated: do not use testuser", | ||
| }, | ||
| { | ||
| "deprecated subject with wrong caveat", | ||
| `use deprecation | ||
|
|
||
| caveat somecaveat(somecondition int) { | ||
| somecondition == 42 | ||
| } | ||
|
|
||
| caveat anothercaveat(somecondition int) { | ||
| somecondition == 42 | ||
| } | ||
|
|
||
| @deprecated(error, "do not use testuser") | ||
| definition testuser {} | ||
|
|
||
| definition document { | ||
| relation viewer: testuser with somecaveat | ||
| }`, | ||
| "document:foo#viewer@testuser:tom[anothercaveat]", | ||
| core.RelationTupleUpdate_CREATE, | ||
| "subjects of type `testuser with anothercaveat` are not allowed on relation `document#viewer`", | ||
| }, | ||
| { | ||
| "deprecated subject with correct caveat", | ||
| `use deprecation | ||
|
|
||
| caveat somecaveat(somecondition int) { | ||
| somecondition == 42 | ||
| } | ||
|
|
||
| @deprecated(error, "do not use testuser") | ||
| definition testuser {} | ||
|
|
||
| definition document { | ||
| relation viewer: testuser with somecaveat | ||
| }`, | ||
| "document:foo#viewer@testuser:tom[somecaveat]", | ||
| core.RelationTupleUpdate_CREATE, | ||
| "resource_type testuser is deprecated: do not use testuser", | ||
| }, | ||
| { | ||
| "deprecated subject without caveat when required", | ||
| `use deprecation | ||
|
|
||
| caveat somecaveat(somecondition int) { | ||
| somecondition == 42 | ||
| } | ||
|
|
||
| @deprecated(error, "do not use testuser") | ||
| definition testuser {} | ||
|
|
||
| definition document { | ||
| relation viewer: testuser with somecaveat | ||
| }`, | ||
| "document:foo#viewer@testuser:tom", | ||
| core.RelationTupleUpdate_CREATE, | ||
| "subjects of type `testuser` are not allowed on relation `document#viewer` without one of the following caveats: somecaveat", | ||
| }, | ||
| { | ||
| "deprecated user with caveat and expiration", | ||
| `use expiration | ||
| use deprecation | ||
|
|
||
| caveat somecaveat(somecondition int) { | ||
| somecondition == 42 | ||
| } | ||
|
|
||
| definition user {} | ||
|
|
||
| definition document { | ||
| relation viewer: user | @deprecated(error, "don't use this") user with somecaveat and expiration | ||
| }`, | ||
| "document:foo#viewer@user:tom[somecaveat][expiration:2021-01-01T00:00:00Z]", | ||
| core.RelationTupleUpdate_CREATE, | ||
| "resource_type user with caveat `somecaveat` and expiration is deprecated: don't use this", | ||
| }, | ||
| { | ||
| "deprecated user with caveat only", | ||
| `use deprecation | ||
|
|
||
| caveat somecaveat(somecondition int) { | ||
| somecondition == 42 | ||
| } | ||
|
|
||
| definition user {} | ||
|
|
||
| definition document { | ||
| relation viewer: user | @deprecated(error, "caveated access deprecated") user with somecaveat | ||
| }`, | ||
| "document:foo#viewer@user:tom[somecaveat]", | ||
| core.RelationTupleUpdate_CREATE, | ||
| "resource_type user with caveat `somecaveat` is deprecated: caveated access deprecated", | ||
| }, | ||
| { | ||
| "deprecated user with expiration only", | ||
| `use expiration | ||
| use deprecation | ||
|
|
||
| definition user {} | ||
|
|
||
| definition document { | ||
| relation viewer: user | @deprecated(error, "expiring access deprecated") user with expiration | ||
| }`, | ||
| "document:foo#viewer@user:tom[expiration:2021-01-01T00:00:00Z]", | ||
| core.RelationTupleUpdate_CREATE, | ||
| "resource_type user with expiration is deprecated: expiring access deprecated", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tcs { | ||
|
|
@@ -325,7 +533,7 @@ func TestValidateRelationshipOperations(t *testing.T) { | |
| op = tuple.Delete | ||
| } | ||
|
|
||
| // Validate update. | ||
| // Validate update for delete. | ||
| err = ValidateRelationshipUpdates(t.Context(), reader, caveattypes.Default.TypeSet, []tuple.RelationshipUpdate{ | ||
| op(tuple.MustParse(tc.relationship)), | ||
| }) | ||
|
|
||
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.
doc comment