Skip to content

Commit

Permalink
Allow creation of object-types with an empty relations block (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkajla12 authored Apr 2, 2024
1 parent d99e34d commit 0b7eb1b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/authz/objecttype/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type ObjectTypeSpec struct {
type CreateObjectTypeSpec struct {
Type string `json:"type" validate:"required,valid_object_type"`
Source *Source `json:"source,omitempty"`
Relations map[string]RelationRule `json:"relations" validate:"required,min=1,dive"` // NOTE: map key = name of relation
Relations map[string]RelationRule `json:"relations" validate:"required,dive"` // NOTE: map key = name of relation
}

func (spec CreateObjectTypeSpec) ToObjectType() (*ObjectType, error) {
Expand Down
32 changes: 30 additions & 2 deletions tests/v1/object-types-crud.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
],
"tests": [
{
"name": "failToCreateObjectWithoutRelations",
"name": "failToCreateObjectTypeWithoutRelations",
"request": {
"method": "POST",
"url": "/v1/object-types",
Expand All @@ -21,6 +21,34 @@
}
}
},
{
"name": "createObjectTypeWithEmptyRelations",
"request": {
"method": "POST",
"url": "/v1/object-types",
"body": {
"type": "A",
"relations": {}
}
},
"expectedResponse": {
"statusCode": 200,
"body": {
"type": "A",
"relations": {}
}
}
},
{
"name": "deleteObjectTypeWithEmptyRelations",
"request": {
"method": "DELETE",
"url": "/v1/object-types/A"
},
"expectedResponse": {
"statusCode": 200
}
},
{
"name": "createObjectTypeReport",
"request": {
Expand Down Expand Up @@ -342,4 +370,4 @@
}
}
]
}
}
30 changes: 29 additions & 1 deletion tests/v2/object-types-crud.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
],
"tests": [
{
"name": "failToCreateObjectWithoutRelations",
"name": "failToCreateObjectTypeWithoutRelations",
"request": {
"method": "POST",
"url": "/v2/object-types",
Expand All @@ -21,6 +21,34 @@
}
}
},
{
"name": "createObjectTypeWithEmptyRelations",
"request": {
"method": "POST",
"url": "/v2/object-types",
"body": {
"type": "A",
"relations": {}
}
},
"expectedResponse": {
"statusCode": 200,
"body": {
"type": "A",
"relations": {}
}
}
},
{
"name": "deleteObjectTypeWithEmptyRelations",
"request": {
"method": "DELETE",
"url": "/v2/object-types/A"
},
"expectedResponse": {
"statusCode": 200
}
},
{
"name": "createObjectTypeReport",
"request": {
Expand Down

0 comments on commit 0b7eb1b

Please sign in to comment.