Skip to content
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

Add user and client to schema, replacing subject #72

Merged
merged 3 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ build: ## Builds permissions-api binary.
.PHONY: test
test: ## Runs unit tests.
@echo Running unit tests...
@docker exec devcontainer-app-1 go test -timeout 30s -cover -short -tags testtools ./...
@docker exec devcontainer-app-1 go test -v -timeout 30s -cover -short -tags testtools ./...

.PHONY: coverage
coverage: ## Generates a test coverage report.
Expand Down
5 changes: 4 additions & 1 deletion internal/query/tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,10 @@ func GetResourceTypes() []types.ResourceType {
},
},
{
Name: "subject",
Name: "user",
},
{
Name: "client",
},
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/query/tenants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func testEngine(ctx context.Context, t *testing.T, namespace string) *Engine {
}

func cleanDB(ctx context.Context, t *testing.T, client *authzed.Client, namespace string) {
for _, dbType := range []string{"subject", "role", "tenant"} {
for _, dbType := range []string{"user", "client", "role", "tenant"} {
namespacedType := namespace + "/" + dbType
delRequest := &pb.DeleteRelationshipsRequest{
RelationshipFilter: &pb.RelationshipFilter{
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestAssignments(t *testing.T) {
require.NoError(t, err)
tenRes, err := e.NewResourceFromURN(tenURN)
require.NoError(t, err)
subjURN, err := urnx.Build(namespace, "subject", uuid.New())
subjURN, err := urnx.Build(namespace, "user", uuid.New())
require.NoError(t, err)
subjRes, err := e.NewResourceFromURN(subjURN)
require.NoError(t, err)
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestSubjectActions(t *testing.T) {
require.NoError(t, err)
otherRes, err := e.NewResourceFromURN(otherURN)
require.NoError(t, err)
subjURN, err := urnx.Build(namespace, "subject", uuid.New())
subjURN, err := urnx.Build(namespace, "user", uuid.New())
require.NoError(t, err)
subjRes, err := e.NewResourceFromURN(subjURN)
require.NoError(t, err)
Expand Down
6 changes: 4 additions & 2 deletions internal/spicedbx/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (
var (
schemaTemplate = template.Must(template.New("schema").Parse(`
{{- $namespace := .Namespace -}}
definition {{$namespace}}/subject {}
definition {{$namespace}}/user {}

definition {{$namespace}}/client {}

definition {{$namespace}}/role {
relation tenant: {{$namespace}}/tenant
relation subject: {{$namespace}}/subject
relation subject: {{$namespace}}/user | {{$namespace}}/client
}

definition {{$namespace}}/tenant {
Expand Down
6 changes: 4 additions & 2 deletions internal/spicedbx/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ func TestSchema(t *testing.T) {
},
}

schemaOutput := `definition foo/subject {}
schemaOutput := `definition foo/user {}

definition foo/client {}

definition foo/role {
relation tenant: foo/tenant
relation subject: foo/subject
relation subject: foo/user | foo/client
}

definition foo/tenant {
Expand Down