Skip to content

Commit 69c0123

Browse files
author
Daniil Kukharau
authored
Add support of nested fields (#7)
* Add support of nested fields * Change generated files extension to pb.atlas.query.perm.go * Minor refactoring * Add missing generated file
1 parent 78c039d commit 69c0123

File tree

8 files changed

+239
-200
lines changed

8 files changed

+239
-200
lines changed

example/example.pb.atlas.query.perm.go

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/example.pb.perm.go

Lines changed: 0 additions & 53 deletions
This file was deleted.

example/example.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ message User {
1717
repeated string array = 8;
1818
CustomType custom_type = 9;
1919
CustomType custom_type_string = 10 [(atlas.query.permissions) = {filter_type: STRING}];
20+
Address home_address = 11 [(atlas.query.permissions) = {enable_nested_fields: true}];
21+
Address work_address = 12;
2022
}
2123

2224
message CustomType {
2325
}
2426

27+
message Address {
28+
string city = 1 [(atlas.query.permissions) = {filters: {allow: "EQ"}, disable_sorting: true}];
29+
string country = 2;
30+
}
2531

2632
message ListRequest {
2733
infoblox.api.Filtering filter = 1;

example/example_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ func TestFilteringPermissionsValidation(t *testing.T) {
2727
{`array=="array"`, true},
2828
{`custom_type=="custom_type"`, true},
2929
{`custom_type_string~"custom_type"`, false},
30+
{`home_address.city=="city"`, false},
31+
{`home_address.city~"city"`, true},
32+
{`home_address.country~"country"`, false},
33+
{`work_address.city=="city"`, true},
3034
}
3135

3236
for _, test := range tests {
3337
f, err := query.ParseFiltering(test.Query)
3438
if err != nil {
3539
t.Fatalf("Invalid filtering data '%s'", test.Query)
3640
}
37-
err = Validate(f, nil, "/example.TestService/List")
41+
err = ExampleValidateQuery(f, nil, "/example.TestService/List")
3842
if err != nil {
3943
if test.Err == false {
4044
t.Errorf("Unexpected error for %s query: %s", test.Query, err)
@@ -57,14 +61,20 @@ func TestSortingPermissionsValidation(t *testing.T) {
5761
{`on_vacation`, true},
5862
{`speciality`, true},
5963
{`unknown_field`, true},
64+
{`array`, true},
65+
{`custom_type`, true},
66+
{`custom_type_string`, false},
67+
{`home_address.city`, true},
68+
{`home_address.country`, false},
69+
{`work_address.city`, true},
6070
}
6171

6272
for _, test := range tests {
6373
s, err := query.ParseSorting(test.Query)
6474
if err != nil {
6575
t.Fatalf("Invalid sorting data '%s'", test.Query)
6676
}
67-
err = Validate(nil, s, "/example.TestService/List")
77+
err = ExampleValidateQuery(nil, s, "/example.TestService/List")
6878
if err != nil {
6979
if test.Err == false {
7080
t.Errorf("Unexpected error for %s query: %s", test.Query, err)

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
func main() {
99
plugin := &plugin.PermPlugin{}
10-
response := command.GeneratePlugin(command.Read(), plugin, ".pb.perm.go")
10+
response := command.GeneratePlugin(command.Read(), plugin, ".pb.atlas.query.perm.go")
1111
plugin.CleanFiles(response)
1212
command.Write(response)
1313
}

options/collection_permissions.pb.go

Lines changed: 46 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

options/collection_permissions.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ message CollectionPermissions {
1919
NUMBER = 2;
2020
}
2121
optional FilterType filter_type = 3;
22+
optional bool enable_nested_fields = 4;
2223
}
2324

2425
message FilterOptions {

0 commit comments

Comments
 (0)