From 6be07b8f671ceddc929eedf4992b97ab179519f6 Mon Sep 17 00:00:00 2001 From: Alex Snast Date: Thu, 19 Mar 2020 14:35:32 +0200 Subject: [PATCH] entc/privacy: rename Read/Write types to Query/Mutation Signed-off-by: Alex Snast --- entc/gen/internal/bindata.go | 8 +- entc/gen/template/privacy.tmpl | 124 +++--- entc/gen/template/runtime.tmpl | 2 +- .../integration/config/ent/privacy/privacy.go | 126 +++--- .../customid/ent/privacy/privacy.go | 230 +++++----- entc/integration/ent/privacy/privacy.go | 412 +++++++++--------- .../gremlin/ent/privacy/privacy.go | 412 +++++++++--------- entc/integration/hooks/ent/privacy/privacy.go | 152 +++---- .../integration/idtype/ent/privacy/privacy.go | 126 +++--- entc/integration/json/ent/privacy/privacy.go | 126 +++--- .../migrate/entv1/privacy/privacy.go | 152 +++---- .../migrate/entv2/privacy/privacy.go | 204 ++++----- .../privacy/ent/privacy/privacy.go | 126 +++--- .../privacy/ent/runtime/runtime.go | 2 +- entc/integration/privacy/ent/schema/planet.go | 4 +- entc/integration/privacy/rule/rule.go | 8 +- .../template/ent/privacy/privacy.go | 178 ++++---- examples/edgeindex/ent/privacy/privacy.go | 152 +++---- examples/entcpkg/ent/privacy/privacy.go | 126 +++--- examples/m2m2types/ent/privacy/privacy.go | 152 +++---- examples/m2mbidi/ent/privacy/privacy.go | 126 +++--- examples/m2mrecur/ent/privacy/privacy.go | 126 +++--- examples/o2m2types/ent/privacy/privacy.go | 152 +++---- examples/o2mrecur/ent/privacy/privacy.go | 126 +++--- examples/o2o2types/ent/privacy/privacy.go | 152 +++---- examples/o2obidi/ent/privacy/privacy.go | 126 +++--- examples/o2orecur/ent/privacy/privacy.go | 126 +++--- examples/start/ent/privacy/privacy.go | 178 ++++---- examples/traversal/ent/privacy/privacy.go | 178 ++++---- 29 files changed, 2080 insertions(+), 2032 deletions(-) diff --git a/entc/gen/internal/bindata.go b/entc/gen/internal/bindata.go index b3c81eb22..32617ec67 100644 --- a/entc/gen/internal/bindata.go +++ b/entc/gen/internal/bindata.go @@ -1004,7 +1004,7 @@ func templatePredicateTmpl() (*asset, error) { return a, nil } -var _templatePrivacyTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x58\x4d\x6f\xdb\x38\x13\x3e\x4b\xbf\x62\x20\x24\x80\xdd\xd7\xa5\xfb\xf6\xb6\x29\x72\x28\xda\x14\x28\xb0\x1b\x14\x6d\xb1\x7b\x28\x8a\x05\x23\x8e\x6c\x22\x12\x29\x90\x94\x1d\x43\xd5\x7f\x5f\x0c\x45\xc9\xb4\x1d\xbb\x09\x92\x2e\xf6\x14\x58\x9c\x8f\x67\x3e\x9e\x19\x32\x6d\x3b\x7f\x91\xbe\xd3\xf5\xc6\xc8\xc5\xd2\xc1\xeb\x57\xff\xff\xed\x65\x6d\xd0\xa2\x72\xf0\x81\xe7\x78\xa3\xf5\x2d\x7c\x54\x39\x83\xb7\x65\x09\x5e\xc8\x02\x9d\x9b\x15\x0a\x96\x7e\x5d\x4a\x0b\x56\x37\x26\x47\xc8\xb5\x40\x90\x16\x4a\x99\xa3\xb2\x28\xa0\x51\x02\x0d\xb8\x25\xc2\xdb\x9a\xe7\x4b\x84\xd7\xec\xd5\x70\x0a\x85\x6e\x94\x48\xa5\xf2\xe7\xbf\x7f\x7c\x77\x75\xfd\xe5\x0a\x0a\x59\x22\x84\x6f\x46\x6b\x07\x42\x1a\xcc\x9d\x36\x1b\xd0\x05\xb8\xc8\x99\x33\x88\x2c\x7d\x31\xef\xba\x34\x6d\x5b\x10\x58\x48\x85\x90\xd5\x46\xae\x78\xbe\xc9\xa0\xff\xfe\x12\xd6\xd2\x2d\x01\xef\x1c\x2a\x01\x67\x90\x7d\xe2\xf9\x2d\x5f\x60\x16\x49\xbe\xec\xba\x34\x69\x5b\x70\x58\xd5\x25\x77\x08\xd9\x12\xb9\x40\x93\x01\x23\x2b\x6d\x0b\xa4\x4b\xf6\x64\x55\x6b\xe3\x20\x6b\x5b\x38\x63\xef\xb4\x2a\xe4\x82\x05\x83\xd0\x75\x99\x07\x72\x56\xdf\x2e\xe0\xe2\x12\x6e\xb8\xc5\xfb\xa4\xd2\x74\xc5\x0d\x4c\xd2\x64\x3e\xa7\x8c\xea\x35\x54\x7c\x03\x37\x08\x06\x5d\x63\x14\x0a\xb8\xd9\x80\x41\x2e\xe6\x6b\x23\x1d\x82\x69\x4a\xb4\xe0\x34\x48\x25\x64\x4e\xf0\xdc\x92\x3b\x9f\xa0\x5a\x97\x32\xdf\x78\x4b\xb8\xe2\x65\xc3\x9d\xd4\x0a\xec\x52\x37\xa5\x00\x87\xa6\x92\x8a\xe4\x7d\x06\xb8\x02\xee\xbd\x09\xcc\xa5\x95\x5a\xb1\x34\xe9\xdd\x5f\x02\x1a\xa3\x8d\x65\xd7\xb8\x9e\x64\xa8\xdc\x3c\x64\xe6\x22\x68\x10\x82\x6c\x9a\x7a\x3f\xef\x51\x6d\xfe\x35\xc0\x82\x9c\x45\x78\xbd\xf3\x13\x70\xbd\x7c\x8c\xf6\xcb\xad\xac\x7f\x11\xda\x5c\x2b\x27\x55\x83\xa4\x4a\xc2\x0a\xef\x9c\x37\xc6\xd2\xc4\xbb\x3d\x81\xd3\xd2\x79\xc0\x39\xed\xbb\xd4\x70\xb5\x40\x38\x1b\x82\xa5\x06\x2a\xa5\x75\x90\xf9\x1a\x65\x90\x51\xec\x19\x64\x64\xda\xf7\x36\xa1\xa2\x6e\x1b\x35\xba\xae\x08\x31\x5a\xca\x5d\xa1\x4d\xc5\x9d\x43\x01\x6b\xc3\xeb\x1a\xc5\xbe\x74\x9c\xd8\xa2\x51\xf9\x81\xb5\x49\x6f\x02\xac\x33\x52\x2d\x66\xc0\x81\x31\x26\x95\x43\x53\xf0\x1c\xdb\x6e\xda\x07\x08\x6d\x9a\x24\xbd\x63\x28\x2a\xc7\xae\xe8\xe3\xa0\xfc\xbf\xec\x02\xce\xd7\xd9\x0c\x08\x82\x12\x13\x3e\xdb\x77\x33\x65\x8c\x4d\xd3\xa4\xf3\x59\x18\x78\xe6\x36\x35\x06\x8a\x7c\x46\x2e\x3e\xf9\x42\x40\xae\xab\x1b\xa9\xd0\x42\xd5\x94\x4e\xd6\x25\xfa\x3a\x86\x0a\x4a\xe5\x34\x70\xb0\x52\x2d\xca\xa1\x74\x2c\x4d\x22\xf5\x6f\xdf\xe9\xc7\xe7\xa6\xc4\x74\xb4\x4c\xbf\xc2\xe8\xb0\xbe\x8c\x63\x7c\x3e\x3d\x42\xaa\x05\xac\x97\xe8\x96\x68\x80\xf7\xee\xa4\xed\x69\x41\xc3\x2f\x19\x6d\x6c\xf5\x28\x1d\x57\x2b\x5e\xd2\xd1\x84\xba\x04\xef\x1c\x4d\x01\xfa\xdb\x47\x4f\x03\xa2\xeb\xd8\x9f\xbc\x6c\x30\x24\x91\x12\x30\x4d\xd3\xf9\x1c\x06\xd5\xa1\xe5\xd0\x02\x87\x52\x73\x01\x7c\xc1\xa5\xb2\x6e\xc0\x31\x84\xe8\x6b\x37\xe9\x7f\x45\xd9\x9a\xc2\x16\x84\xbb\x83\x03\x20\xab\x63\x50\x28\x80\x42\x1b\xf8\x7b\xe6\x33\x4b\x9d\xd8\x37\x67\x70\x41\xf1\xd9\xb5\x74\xf9\x92\xe4\xfd\x31\x75\x7d\xec\x6d\x06\xab\xe9\x1b\x2f\x98\xd3\x10\x24\xb1\xcb\x4b\x50\xb2\x84\x1f\x3f\x06\x56\x7c\xb4\x13\x34\x66\xe6\x29\x3a\xbd\x88\x44\xe3\x43\xdf\xfc\xfe\x74\xe8\x30\x25\xcb\x34\x49\x04\x16\xbc\x29\x5d\x7c\x80\xc6\xa4\x49\xd2\x51\x22\x63\xd9\xce\x27\x75\x28\xd3\x07\xca\x95\x6f\x2e\xe9\x49\xc2\x05\xaf\x1d\x6d\x28\x1d\x46\x1d\xb5\x40\x63\x11\x74\x41\x6a\xda\x08\xa9\xb8\xd9\x00\xe5\x98\xc8\x6f\x81\xdb\xa8\xe9\x58\xdf\xa8\x3b\xd6\x49\xf4\xe1\x65\x1f\x2a\x0e\x39\x2f\x4b\x0b\xc5\x90\xbd\xa1\xac\xc5\x8e\xf1\x27\xd5\x74\xa0\xe8\xe0\x22\xdd\xe5\xd9\x5f\x34\x0d\x8f\x12\x2d\x9e\x95\x47\x98\x16\x1b\xf8\xf6\xdd\xff\xda\x72\x6d\xfc\xf9\x70\xb2\xf5\x2e\x77\xd8\xb6\xb5\x72\x48\x37\x7f\x76\x32\xf1\x7f\x34\xce\x4f\xf0\x7b\x29\xe7\xd5\x77\x38\x57\x05\xf1\x88\x77\x3d\xa4\x7b\x89\x17\x45\x3f\x85\x08\xcf\x7d\x65\xaa\x4e\xa0\x7a\x02\xfb\x46\x8f\x33\xa8\xfe\x5b\xf4\x1b\xeb\xf6\x2c\xfc\x8b\x7a\x31\x10\x70\xd7\xfe\x4f\x19\xb8\xdf\x08\xf7\x93\xb0\x8a\x48\xb8\xe3\xe0\xc9\xf5\xdd\x65\x62\x35\x0d\x59\x0a\xdc\x59\x18\xdd\xd4\x61\xca\x70\x25\xe2\xa6\x93\x63\xc4\x41\xd6\x3a\xd3\xe4\x8e\x6c\xfa\x95\xb1\x9d\xfe\x81\x2b\x71\x5b\x06\x2f\xe3\x7e\x29\xb4\x59\x73\x23\x6c\x7c\xb7\x71\xfa\xc4\x6e\x79\x86\xbd\x12\x22\x0f\xe6\xc9\xc8\xc1\xde\x88\x60\xf6\x21\x1c\xc1\x79\x82\x8b\xcf\x44\xc3\x5d\xb0\xde\xd0\x21\xcf\xa2\x05\x13\x4d\xa7\xfd\xf1\xe6\xaf\x94\xf7\x17\x76\x7f\x91\x1c\x99\x71\xe3\xd5\x65\x3b\x04\x83\xeb\xb7\xe5\x9a\x6f\xac\xa7\xaa\x57\x1b\xef\x80\xfb\xb7\xdc\x1e\x45\x74\x45\xdc\x7f\x0f\xf8\x24\xee\x99\x9b\x4c\xf7\x50\x45\xfd\x2b\xef\x50\xbc\x0f\xda\x74\xd6\x7a\xad\x6e\x07\x17\x5d\x5b\x1f\x05\x6b\xff\xd2\x1f\x81\x1a\x6c\x3d\x0a\x13\x29\x75\xe3\xae\x3b\x38\x1f\x29\xe4\xc7\x64\x5f\xfb\x2e\x1d\x89\x7f\x20\x1f\xb7\xff\x03\x97\x3c\xb4\x30\xa0\x63\xe4\xa4\xfb\x99\xf5\x47\xaf\xb2\x43\x0f\xf1\x9b\xc2\x3f\x26\xce\xd8\xb5\x16\x68\x21\x3c\x75\xcf\x14\xaf\xfc\x72\xa9\x8d\x54\x0e\xce\x14\xbb\xa6\x0f\x59\x7c\xdb\xc8\x46\x61\x9f\xba\x41\xb8\x80\xec\xc5\xb9\x65\xe7\x36\xeb\xe1\x0c\xba\xe1\x4d\xf2\x75\x89\x30\x3a\xe8\xba\x07\x4e\xfb\x71\xd4\x7b\x1b\x3b\xe3\x9e\x6f\x2f\x5c\x2c\x4d\xbc\xb9\xd8\xfe\xf1\x69\xef\x45\xbb\x6e\x9c\xf2\x49\x3c\xfd\x0e\xee\x5b\xc9\x50\x94\xc8\xf8\x93\x66\x5d\x22\x0b\x58\xcd\x40\xdf\x52\xe6\x56\x6c\x12\x43\x7a\x43\x9f\xdb\x68\x7d\x6e\x6f\x65\x7e\x89\x0e\x9f\xa9\x79\x8b\xbd\xc7\x63\xa3\xf0\xae\xc6\x9c\x5e\x76\x34\x10\xb1\xcf\xf0\xf9\xd7\x19\xf4\xdf\xe3\xd8\xb3\xde\x64\x97\x46\x45\x3f\xa8\xf9\xce\x72\xdb\x2b\xfa\xf1\x9a\x0f\x2d\xf8\x8b\x6b\xbf\x9d\x13\xcf\x53\xfc\x7e\xa7\x1c\x2c\xfa\xe3\xd5\x7f\xc2\x02\xa1\x0e\xa8\x86\x0e\xa8\x1e\xd6\x01\xd5\xe3\x3a\x60\xbc\xa4\x9e\x6e\x82\xea\xe0\x85\xbd\xfd\xa7\xd6\x3f\x01\x00\x00\xff\xff\x84\x96\x87\x48\x00\x14\x00\x00") +var _templatePrivacyTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x58\x41\x6f\xdb\x38\x13\x3d\x4b\xbf\x62\x20\x38\x80\xdd\xcf\x95\xfb\xf5\xb6\x29\x72\x28\xda\x14\x28\xb0\x1b\x74\xb7\xbd\x15\xc5\x82\x11\x47\x36\x11\x89\x54\x48\x2a\x8e\xa1\xea\xbf\x2f\x86\x12\x65\x4a\x8e\xdd\x74\x93\x02\x7b\x0a\x4c\x0e\x67\x1e\x67\xde\x9b\xa1\xd2\x34\xab\x17\xf1\x3b\x55\xed\xb4\x58\x6f\x2c\xbc\x7e\xf5\xff\xdf\x5e\x56\x1a\x0d\x4a\x0b\x1f\x58\x86\xd7\x4a\xdd\xc0\x47\x99\xa5\xf0\xb6\x28\xc0\x19\x19\xa0\x7d\x7d\x87\x3c\x8d\xbf\x6c\x84\x01\xa3\x6a\x9d\x21\x64\x8a\x23\x08\x03\x85\xc8\x50\x1a\xe4\x50\x4b\x8e\x1a\xec\x06\xe1\x6d\xc5\xb2\x0d\xc2\xeb\xf4\x95\xdf\x85\x5c\xd5\x92\xc7\x42\xba\xfd\xdf\x3f\xbe\xbb\xbc\xfa\x7c\x09\xb9\x28\x10\xfa\x35\xad\x94\x05\x2e\x34\x66\x56\xe9\x1d\xa8\x1c\x6c\x10\xcc\x6a\xc4\x34\x7e\xb1\x6a\xdb\x38\x6e\x1a\xe0\x98\x0b\x89\x90\x54\x5a\xdc\xb1\x6c\x97\x40\xb7\xfe\x12\xb6\xc2\x6e\x00\xef\x2d\x4a\x0e\x33\x48\x3e\xb1\xec\x86\xad\x31\x09\x2c\x5f\xb6\x6d\x1c\x35\x0d\x58\x2c\xab\x82\x59\x84\x64\x83\x8c\xa3\x4e\x20\x25\x2f\x4d\x03\x74\x96\xfc\x89\xb2\x52\xda\x42\xd2\x34\x30\x4b\xdf\x29\x99\x8b\x75\xda\x3b\x84\xb6\x4d\x1c\x90\x59\x75\xb3\x86\xf3\x0b\xb8\x66\x06\x1f\xb2\x8a\xe3\x3b\xa6\x61\x1e\x47\xab\x15\x65\x54\x6d\xa1\x64\x3b\xb8\x46\xd0\x68\x6b\x2d\x91\xc3\xf5\x0e\x74\x5d\xa0\x01\xab\x40\x48\x2e\x32\xc2\x64\x37\xcc\xba\xac\x54\xaa\x10\xd9\xce\x1d\xc7\x3b\x56\xd4\xcc\x0a\x25\xc1\x6c\x54\x5d\x70\xb0\xa8\x4b\x21\xc9\xde\x5d\x9b\x49\x60\x2e\x04\xc7\x4c\x18\xa1\x64\x1a\x47\x5d\xcc\x0b\x40\xad\x95\x36\xe9\x15\x6e\xe7\x09\x4a\xbb\xea\xd3\x71\xde\x9f\x20\x04\xc9\x22\x76\x71\xde\xa3\xdc\xfd\x5a\x94\x9c\x22\x04\x20\x5d\xc4\x13\x18\x9d\x7d\x08\xf1\xf3\x8d\xa8\x9e\x13\x62\xa6\xa4\x15\xb2\x46\x3a\x4a\xc6\x12\xef\xad\x73\x96\xc6\x91\x8b\x75\x02\x9c\xa1\xfd\x1e\xdc\xa2\x23\xa1\x66\x72\x8d\x30\xf3\x37\x24\x7e\x14\xc2\x58\x48\x5c\x35\x12\x48\xe8\xc2\x09\x24\xe4\xda\x51\x97\x50\x11\x99\x86\x13\x6d\x9b\xf7\x17\x33\x94\xb0\x5c\xe9\x92\x59\x8b\x1c\xb6\x9a\x55\x15\xf2\xa9\x75\x98\xcd\xbc\x96\xd9\x81\xb7\x79\xe7\x02\x8c\xd5\x42\xae\x97\xc0\x20\x4d\x53\x21\x2d\xea\x9c\x65\xd8\xb4\x8b\xee\x82\xd0\xc4\x51\xd4\x05\x86\xbc\xb4\xe9\x25\x2d\xfa\xc3\xff\x4b\xce\xe1\x6c\x9b\x2c\x81\x20\x48\x3e\x67\xcb\x69\x98\x45\x9a\xa6\x8b\x38\x6a\x5d\x16\xbc\x8c\xec\xae\xc2\x5e\x01\x7f\xd6\xa8\x77\x9f\x5c\x25\x20\x53\xe5\xb5\x90\x68\xa0\xac\x0b\x2b\xaa\x02\xe1\x96\x76\xfb\x1a\x0a\x69\x15\x30\x30\x42\xae\x0b\x5f\xbc\x34\x8e\x42\x07\x5f\xbf\xb9\x5f\x7f\xd5\x05\xc6\x7b\xef\xf4\xb3\x6f\x0f\xc6\xd5\x72\xb8\xa4\xcb\x11\x17\x72\x0d\xdb\x0d\xda\x0d\x6a\x60\xee\x58\x17\x56\x98\x4e\x0a\xc8\x81\x49\x0e\xaa\x22\x7e\xb0\xa2\xd8\x41\xa9\xb8\xc8\x77\x20\xac\x8f\xef\x42\xec\xdd\x52\xca\x2e\xef\x58\xe1\xf6\xe6\x44\x25\xbc\xb7\xd4\x09\xe8\x6f\x97\x22\x6a\x12\x6d\x9b\x3a\x8b\x3e\xd3\x94\xa5\x45\x1c\xaf\x56\x30\x9c\xf5\xc4\x44\x03\xac\x47\xc5\xd6\x4c\x48\x63\x87\xdf\x3e\x11\xae\xc6\xf3\xee\x57\x98\xd5\x05\x04\x48\xec\x3d\x1c\xa0\xb9\x3d\x86\x87\xae\x91\x2b\x0d\x7f\x2f\x5d\x05\x88\xb3\x1d\x8d\xfb\x20\x74\x4b\xb3\x15\x36\xdb\x90\xbd\xdb\x26\x7d\x8c\xc2\x2d\xe1\x76\xf1\xc6\x59\x66\xd4\x0e\xc9\xee\xe2\x02\xa4\x28\xe0\xfb\x77\x2f\xa0\x8f\x66\x8e\x5a\x2f\x9d\x84\x17\xe7\x81\x69\xb8\xe9\x74\xe2\x76\x3d\x19\xa5\x28\xe2\x28\xe2\x98\xb3\xba\xb0\xe1\x06\x6a\x1d\x47\x51\x4b\xe9\x0c\x6d\x5b\x97\xda\xa1\x5c\x1f\x28\x5f\x8e\x88\xc2\x09\x8a\x71\x56\x59\x1a\x56\xaa\x6f\x80\xc4\x94\xda\x20\xa8\x9c\xce\x29\xcd\x85\x64\x7a\x07\x94\x67\x22\x82\x01\x66\x42\x7e\xa6\x1d\xab\xc7\xfe\xc9\xf8\xf1\xf5\xf7\xa5\x1f\x74\x9e\xfb\x14\xfa\xf2\xe6\x63\xff\x4f\xab\xad\x17\xb5\x0f\x12\x8f\x95\xf9\x47\x6d\x5d\x47\x3c\x2a\xce\xb2\x37\x38\xad\xcf\x89\x9b\xaf\xdf\xfc\xc2\x5e\xa5\xe1\xca\xcf\x09\x75\x80\xf0\x38\xad\x8e\x02\x1d\xca\xd5\x6f\x9f\xac\x98\x37\x7a\x50\xb4\x7e\x73\xa4\xdb\x01\xe4\x5e\xba\xc3\xd2\x83\xea\x1d\xa7\x6c\x01\x63\x6c\x0f\xd5\xb9\x3c\x81\xf0\x09\x32\x0e\x83\x2e\xa1\xfc\x6f\x29\x39\x2c\xe6\xb3\x88\x79\xcc\xe7\x5e\xcf\x07\x51\x7e\x28\xe9\x29\x41\x0e\xb8\x31\x51\x77\x19\xa8\x7b\x1a\xed\x39\x6a\x3f\x96\x79\xb9\xe8\xd3\xd7\xeb\x71\xad\x55\x5d\xf9\x46\x46\xd2\x19\x53\x53\x0c\x89\xe8\xed\x8d\xd5\x75\x66\xc9\x6f\x37\xa0\x82\x49\xb3\xd7\xd7\x84\xc1\x7d\xc4\xfd\x54\xcb\x95\xde\x32\xcd\x4d\xf8\xee\xb2\xea\xd4\x40\x7b\x8e\x59\xd6\x27\xa2\xf7\xef\x76\x0f\x87\x55\x80\x75\xb8\xcd\x11\xb8\xa7\x45\xfc\x7c\xe2\x1d\xe3\xf6\x06\x0f\x0a\x34\x1c\x72\xe3\x66\x37\x6d\xa8\xee\x15\x7c\xbc\xf8\x07\x23\xed\x78\xeb\xdc\x3f\xb9\x46\xfd\xb5\x87\xf2\xb6\xd8\xb2\x9d\x71\x9a\x77\x47\x87\x27\x6c\xd7\x8c\x1c\x8c\xe0\x59\x3b\xfd\x5a\x71\x29\x9d\xf8\x98\x2f\x1e\x80\x14\x10\x5d\xdc\x23\x7f\xdf\x7b\xa0\xbd\xc6\x9d\x6c\x47\x80\xe8\xb9\xfd\x63\x3c\xd3\xcf\x92\x00\x8d\x77\xf0\xd3\x60\xe8\x60\x3b\x8c\xda\x83\xfd\x41\x60\xae\xc3\x76\x1c\x68\xe3\xa1\x41\x1c\xd8\x8f\x24\xf1\xc8\x87\x06\x34\xe0\xe1\xa5\x14\xa5\xfd\x91\xfb\x7f\x33\x18\x0f\x83\x84\x1f\x42\xee\x0b\x68\x96\x5e\x29\x8e\x06\xfa\xcf\xef\x99\x64\xa5\x1b\x4f\x95\x16\xd2\xc2\x4c\xa6\x57\xb4\x90\x8c\x9e\x3c\xc9\x60\xed\xf2\xe7\xad\x73\x48\x5e\x9c\x99\xf4\xcc\x24\x1d\x9e\x99\xec\x6e\xec\x3c\xf4\x9f\x53\x5f\x36\x08\x43\x98\xb6\x7d\xe4\xbc\x18\x86\x85\xf3\x31\x1a\x18\x2c\x78\xff\xa5\x71\xe4\xfc\x85\x01\x8e\x8f\x0a\x67\xda\xb6\xc3\x88\x88\x46\xed\x71\xfa\x30\xf3\x5f\x70\xf3\x3c\x74\xff\xb4\x66\x18\x89\x1c\x6e\x97\xa0\x6e\x28\x85\xb7\xe9\x3c\x44\xf5\x86\x96\x9b\x60\x0e\xef\x9f\x88\x6e\x1a\xfb\x65\xa2\x72\x3e\xf9\xf6\xad\x25\xde\x57\x98\xd1\x87\x69\x97\x1c\xe7\xf4\xec\xcb\x12\xba\xf5\xf0\xfa\x49\xe7\xb2\x8d\x83\xf2\x1f\x54\x7f\x3a\x12\x27\x04\x38\x5e\x7f\x7f\xf0\x17\x53\x60\xd4\x32\x9f\x87\x05\xc3\xe0\xc9\x58\x51\x8c\xde\x09\xc7\x79\xf0\xb4\x11\x43\x6c\x28\x3d\x1b\xca\xc7\xb1\xa1\xfc\x39\x36\x0c\x79\x3a\x4d\x88\xf2\xe0\x9f\x05\xfb\x7f\xbf\xfd\x13\x00\x00\xff\xff\x18\xc0\x4a\xcd\xaa\x14\x00\x00") func templatePrivacyTmplBytes() ([]byte, error) { return bindataRead( @@ -1019,12 +1019,12 @@ func templatePrivacyTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/privacy.tmpl", size: 5120, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + info := bindataFileInfo{name: "template/privacy.tmpl", size: 5290, mode: os.FileMode(420), modTime: time.Unix(1, 0)} a := &asset{bytes: bytes, info: info} return a, nil } -var _templateRuntimeTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x58\x5b\x6f\x1b\xbb\x11\x7e\xd6\xfe\x8a\xa9\xa0\x02\x52\x2a\x53\x76\xde\xea\x42\x0f\xa7\xb9\xe0\x18\x68\xd2\x00\x4e\x72\x1e\x8c\x20\xa0\x76\x67\xb5\x3c\x5e\x91\x5b\x92\xeb\x58\x10\xf6\xbf\x17\xc3\xcb\x2e\x57\x17\xa7\x38\x45\x81\xbe\x58\x4b\x72\x66\x38\xf3\xcd\x95\x3e\x1c\x56\xaf\xb2\x37\xaa\xd9\x6b\xb1\xad\x2c\xbc\xbe\xbe\xf9\xeb\x55\xa3\xd1\xa0\xb4\xf0\x9e\xe7\xb8\x51\xea\x11\xee\x64\xce\xe0\x97\xba\x06\x47\x64\x80\xce\xf5\x13\x16\x2c\xfb\x5c\x09\x03\x46\xb5\x3a\x47\xc8\x55\x81\x20\x0c\xd4\x22\x47\x69\xb0\x80\x56\x16\xa8\xc1\x56\x08\xbf\x34\x3c\xaf\x10\x5e\xb3\xeb\x78\x0a\xa5\x6a\x65\x91\x09\xe9\xce\xff\x71\xf7\xe6\xdd\xc7\xfb\x77\x50\x8a\x1a\x21\xec\x69\xa5\x2c\x14\x42\x63\x6e\x95\xde\x83\x2a\xc1\x26\x97\x59\x8d\xc8\xb2\x57\xab\xae\xcb\x32\x67\xc3\x67\x62\x69\xa5\x15\x3b\x04\x8b\xbb\xa6\xe6\x16\x61\x8b\x12\x35\xb7\x68\x9c\x44\x93\x57\xb8\xe3\x57\xc6\x0a\x9b\x57\x42\x6e\xa1\x56\x5b\x91\x03\x97\x05\x54\xaa\x2e\x1c\x51\xb6\x53\x45\x5b\x23\x3c\xa1\x36\x42\x91\x26\xdc\xc2\x0f\x6e\xa0\x25\x8b\xac\xea\x45\x3a\x89\xdc\x18\xb4\x86\x65\xd9\x9d\x85\x8a\x1b\x78\x0d\xa5\xd2\x3b\x6e\x0d\x83\x5f\x60\x1a\xd4\x99\x42\xc3\xf3\x47\xbe\x45\x2f\xcc\x54\xaa\xad\x0b\xd8\x20\xe0\xae\xb1\xfb\x2b\xb1\x6b\x94\xb6\x58\x04\xbb\xb3\x1d\x17\xb2\xe7\x28\x95\x0e\x6a\x1b\xf8\x21\x6c\x05\x95\x52\x8f\x06\x94\x86\x46\xd5\x22\x17\x68\x60\xde\x28\x8b\xd2\x0a\x5e\x43\xbe\xcf\x6b\x91\x07\x89\x0b\xe6\x30\x31\x98\x2b\x59\x04\xbd\xc8\x3d\xd1\x80\xd4\x3f\x53\x94\xb6\x57\x73\xe9\x10\x49\x95\x03\x61\x32\xa9\x2c\x48\xcc\xd1\x18\xae\xf7\x30\x97\x0a\x54\x63\x09\x21\x52\xf1\xe8\x62\x38\xbd\x38\xc2\xf7\x88\xd8\x64\x1b\x9e\x3f\xfe\xe0\xba\x30\x57\xb9\xda\x35\xdc\x8a\x8d\xa8\x85\xdd\x7b\x0b\x1b\x8d\x4f\x42\xb5\x26\xba\xc0\x90\xeb\x51\xda\xc1\xdb\x50\x60\x29\x24\xf6\x00\xaf\x9c\xf6\x5d\x97\x01\x00\x1c\x0e\x83\xfb\x07\x0f\xcc\xe8\xf8\x70\x00\x94\x05\x5c\x10\xd2\x3c\x6e\x53\x21\x4e\x17\x7c\xb6\xc4\x31\x83\xe9\x27\x8f\xcd\x34\x91\x19\x68\x2f\x5f\xca\x12\x71\xe1\xe2\xc9\xe1\x00\xb3\x10\x62\xb7\x6b\x98\xb1\x0f\xee\xfb\x4e\x96\x2a\x1e\x8b\x92\xdc\x1b\x88\xd8\xd7\x10\x87\x71\x7d\xdf\xee\x1c\x61\xae\xa4\xb1\x30\xcf\x26\x93\xc3\xe1\xca\x2b\x7b\xcc\x42\x64\x93\x49\x5c\xad\x61\x7a\x38\x38\x95\xa6\xb0\x5a\x41\xdc\xf6\xd8\xba\xdc\xdd\xa2\x64\x41\x5e\xd4\xf6\x54\x78\xbc\x7f\x32\xa1\xaf\x23\xa1\xb4\xf5\xb2\xc0\x85\x33\x31\xac\x5e\xf4\xc7\x34\xee\x0f\xc0\x56\xc8\x0b\xd4\x01\x57\x3a\x9a\xf9\x6c\xb8\x5d\xc3\x75\x90\xa7\xb9\xdc\x22\xcc\xa4\x07\xf7\xa3\x2a\xd0\xf4\xb0\xcb\x76\xf7\x6b\xa4\x9f\x49\xf6\x31\x2e\xbb\xce\xa3\x3e\x93\xec\x57\x6e\x3e\x51\x5e\xed\xfd\xe6\xc0\xb2\x06\x5e\x14\xc9\xfa\xc6\x13\xa4\x5e\xad\x52\x42\xbf\x18\xe8\x47\xd6\x12\xb5\xb6\xcd\xe3\x96\x34\x29\x79\x6d\xb0\xd7\xa1\xe2\xe6\xbd\xc0\xda\x85\xdc\x7d\xae\x1a\x07\xc3\x40\xbf\x06\xfc\x17\xcc\x98\x3b\x61\x21\x24\x47\x88\x8d\x21\x25\xa3\x3c\x63\xd7\x01\x55\x49\xb8\x31\x36\x66\xe4\x55\x2c\x97\xab\xf0\xcb\xb6\x0a\x5c\x8a\x85\x28\x0c\x46\xc4\x20\x9e\x9c\x0b\xf2\x95\xc6\xad\x30\x96\xbc\x32\x8b\x48\xa0\x37\x28\x9b\x4c\x56\x2b\x5f\x09\xce\xd7\xdd\x51\x2d\x12\x92\xb2\x64\xc6\xde\x28\x59\x8a\x6d\x6f\x5b\xd7\x25\xda\x1d\xc7\x4e\x04\x6e\xf5\x0a\x5e\x0f\x95\x86\x82\xcd\x5e\xb2\x89\xaa\xd8\xff\x97\x5d\x2f\xd8\x77\x92\x25\xae\xd3\x41\x54\x2d\xdc\x0f\x15\x97\x45\x8d\xda\x50\x79\xb5\xfb\x06\x63\x1d\x37\xde\xf2\x33\xa5\x6e\x30\xae\xeb\xb2\x50\xe2\xe7\x59\x92\xec\x51\xdd\x7b\x7f\x83\x33\xba\xcf\xf4\x6c\x94\xd1\xf4\x7d\x29\xeb\x1c\xcf\x39\xdb\x5d\x6e\x25\x1b\x63\x99\xd9\x64\xba\x15\xb6\x6a\x37\x2c\x57\xbb\x55\x19\xa6\x10\x21\xf3\x76\xc3\xad\xd2\xae\xdc\x67\x8b\x2c\xcb\x82\x1f\x84\x14\x16\xca\x56\xe6\xae\x1f\x69\xe4\x85\x01\x5e\xd7\x11\x9f\x02\x4d\xae\x45\x63\x95\x0e\x3d\x34\xc0\x40\xec\x6e\x66\x99\x17\x58\xf2\xb6\xb6\xf0\xc4\xeb\x16\xcd\x92\x7e\x45\xc1\x1d\x83\xd2\xbe\xe5\x2e\x5c\x53\xf4\xae\x46\x03\xc2\x12\x37\x01\x5e\xa1\xd0\x7d\xbb\x7e\xe2\x5a\xf0\x4d\x8d\x86\x65\xa4\x8f\xd3\x6c\xbe\x80\x43\xf6\x12\x4a\x74\x36\x0b\xd5\x60\x0c\x4b\x38\x0b\x76\xdc\xae\x61\xc3\x0d\x9e\xf5\x0e\xd1\x9d\x96\xb0\x6c\x32\x69\xfc\xf7\xed\xda\x85\xa1\x89\x1c\xcc\x7b\xe0\x23\xdf\xb9\x14\xea\x98\xe7\x99\x2f\x5c\xbd\x86\x46\x0b\x69\xbd\x52\x53\xe6\x2a\x18\x85\xca\xc3\xf5\x37\x58\x3b\xa0\xe7\x12\x9f\xad\x6b\xca\x1f\x5a\x4b\x40\x2d\xd2\x05\x1c\xa8\x3f\x68\xb4\xad\x96\xc3\x3e\xbe\x27\x46\xc7\x9d\xdb\x67\xc8\x95\xb4\xf8\x6c\xc9\x16\xfa\x5d\xc2\x6e\x20\x15\x4a\x2e\x60\x4e\xcb\xaf\xe4\x91\x25\xa0\xd6\x74\x87\x93\x3b\x11\x25\xad\xc9\x24\x6f\x1c\x7b\xf7\xc4\xeb\xdf\xb4\xb0\x48\x82\x97\xb0\x5b\xfc\xcd\x11\xfc\x69\x0d\x52\xd4\x81\x29\xaa\x23\x45\xed\xc4\xb9\x4d\xd7\xc7\xfa\x13\xd2\xc6\x6b\x1a\xe5\xd0\x71\x47\x7f\xbb\xd3\x98\xf7\x68\x27\x4d\xe4\x14\xb9\x1e\xb8\x9f\xc3\xef\x48\x1d\xfa\x34\x4e\x89\x25\x54\xc4\xe3\x23\xe6\xa2\x54\x67\xd9\x65\x6f\x89\xb3\x6d\xed\x2f\x37\x7d\x41\x21\x6f\x56\x17\xad\xa3\x21\xc4\xb1\xbe\x0d\xd9\xe1\x57\x5f\x87\xdc\x38\x9a\x10\x24\xfb\x20\x9e\xb1\xb8\x93\xbf\x09\x5b\x05\xa6\x7f\xea\x9e\x3e\x8c\x0d\x64\xb9\xef\x48\x1f\xc4\xb3\x90\x3f\x87\xc6\x91\x39\x68\x8e\x79\x5d\xa7\x74\xed\xfc\x81\x31\xf6\xed\xe1\x1b\x45\x8c\xdb\xf4\x3e\x4f\x92\x4e\x2c\x61\xf6\x9d\x28\x9f\x63\x16\x92\xeb\xbc\x06\x5e\xaf\x13\xe9\x0f\xb4\x16\x04\x93\x97\x69\xe6\x8b\x65\x2f\xb6\x1f\x90\x26\xdd\xe5\x91\x49\x06\xc6\x13\xcb\x07\xc5\x5f\x36\x3d\xde\x4b\xdc\xdf\xc1\x53\xa7\x12\xce\x5d\x9d\x18\x5c\x86\x49\xe7\x48\x8b\x2b\x98\x51\x49\x74\x09\x94\x44\xce\x5b\x34\xf9\x14\x66\x25\xbb\xb7\xba\xcd\xad\x1f\x43\x06\x9e\xd5\x2b\x40\xd9\xee\x60\x5c\x2b\x43\xf3\x29\x40\x22\xd7\xa1\x18\x16\x98\xd7\x5c\xbb\x2c\x36\x30\xa7\x57\x4d\xd2\x94\x16\x2c\xf4\xe3\x49\x12\x67\x73\xaa\xad\xb3\x92\xc5\x48\x9b\xbb\x36\x5d\xb2\x3b\xf3\x4e\xb6\xbb\xc5\x82\xbe\xbf\x34\x05\xb7\xd8\xc7\x62\xc9\x8e\x03\xb1\x17\x38\x2b\xd9\x27\x65\x04\xdd\x1f\x23\xb2\xf7\xf1\x6a\xe5\x40\x74\xf6\x77\x1d\xb5\xea\xe1\x61\x98\x34\x0a\xf7\xa8\x21\xc2\x32\x7a\x03\x4a\xc2\x83\x0d\x91\x12\x45\xdc\xa6\x6e\x49\xc2\xf2\xc1\xb3\xa7\x9a\x08\x79\x27\x0b\x7c\xa6\x90\x3a\x3e\xed\x0f\xd8\xdb\x5e\x09\xef\x77\xef\xe1\x7e\xf4\xf8\xdf\xdb\x70\x5e\xfd\x9f\x29\x28\xd3\x58\x19\x05\xa4\x28\xe1\x65\xf7\x8e\x03\xd3\x93\x1c\xc5\x26\x9b\x26\xfc\xc1\x9a\x2c\x85\xc2\x73\x75\xdd\xf0\x90\x1f\x07\x2a\x28\x09\xb9\x46\xde\xbf\x58\x89\xe2\x12\x38\x47\x22\xd7\x29\xdc\x51\x09\x36\x1f\x9e\x6a\x64\xc9\x67\xb1\x43\xff\xf5\xe5\xcb\xdd\x5b\xe8\x3a\xd7\xe8\x16\xc3\xd3\xcf\x5f\xf6\x99\x52\xa1\xeb\x16\xe7\x32\xd7\x87\xee\x38\xce\xff\x53\x68\x46\x5c\x7f\x14\xa0\xd6\x09\xf9\xef\xe0\x19\x29\x12\x41\x1a\x10\xfa\x23\xb8\xf8\x62\x7a\x26\xe1\x1d\x2c\x92\xf4\x3b\x8b\xc9\x69\xe7\xb9\x82\x99\xab\x45\x34\x68\x39\xfa\x12\xa6\x6e\x4e\x9b\xff\xd9\x2c\xfc\x90\x31\x4d\xb4\x49\x00\x94\x01\x05\x61\x80\x0f\xe3\x61\x0f\xd5\x74\x84\xd5\x34\x80\x05\x77\xee\x1f\x2e\x39\xaf\xa9\x42\x6e\xf6\x8e\x74\xd3\x8a\xba\xa0\x69\x7d\x83\xa5\xd2\x08\x86\x3f\x21\x4b\xca\x21\x3d\xf0\x46\xb6\xde\x0c\xe5\x6d\xd0\x63\x0c\xfa\x40\xfd\x70\xfd\xcd\x81\xee\xed\xf4\x80\x9e\x54\x90\xb1\xa0\xc1\x21\x91\x29\x8e\x4c\xc9\x18\x7c\x7b\xe9\x42\x4f\x59\xca\xa1\x0d\x3b\x79\x63\xaf\x7a\x68\xa3\xd8\xb4\x4d\xfd\xbe\x0c\x03\x71\xec\xcb\xe7\xea\xfa\x48\x15\x57\x98\x7e\x77\x95\x68\x7e\xf1\xaa\xd0\xa9\x8f\x6b\x53\x9c\xf8\xe2\xc8\x97\xf0\xff\xdd\xbb\x25\x76\x3d\x78\xd1\x00\x72\xfb\xf7\x25\x94\x72\x18\xd2\x08\x81\x78\x9c\x4c\xa8\xa5\x3c\x2f\xff\xec\x88\x9a\x0c\xcd\x61\x40\x1d\x34\xee\x7f\x87\x39\x36\xb5\xa8\x9b\x2f\xce\x16\xdf\x74\xa6\xeb\xdf\x93\xe7\x3e\xfd\x3f\x0c\xc2\xe2\xdf\x01\x00\x00\xff\xff\xaa\x06\xb7\x00\x15\x16\x00\x00") +var _templateRuntimeTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x58\x5b\x6f\x1b\xbb\xf1\x7f\xd6\x7e\x8a\xf9\x0b\xfa\x03\x52\x2a\x53\x76\xde\xea\x42\x0f\x69\x2e\x38\x06\x9a\x34\x80\x93\xf4\xc1\x08\x02\x6a\x77\x56\xcb\xe3\x15\xb9\x25\xb9\x8e\x05\x61\xbf\x7b\x31\xbc\xec\x72\x75\x71\x8a\x53\x14\xe8\x8b\xb5\x24\x67\x86\x33\xbf\xb9\xd2\x87\xc3\xea\x55\xf6\x56\x35\x7b\x2d\xb6\x95\x85\xd7\xd7\x37\x7f\xbe\x6a\x34\x1a\x94\x16\x3e\xf0\x1c\x37\x4a\x3d\xc2\x9d\xcc\x19\xbc\xa9\x6b\x70\x44\x06\xe8\x5c\x3f\x61\xc1\xb2\x2f\x95\x30\x60\x54\xab\x73\x84\x5c\x15\x08\xc2\x40\x2d\x72\x94\x06\x0b\x68\x65\x81\x1a\x6c\x85\xf0\xa6\xe1\x79\x85\xf0\x9a\x5d\xc7\x53\x28\x55\x2b\x8b\x4c\x48\x77\xfe\xb7\xbb\xb7\xef\x3f\xdd\xbf\x87\x52\xd4\x08\x61\x4f\x2b\x65\xa1\x10\x1a\x73\xab\xf4\x1e\x54\x09\x36\xb9\xcc\x6a\x44\x96\xbd\x5a\x75\x5d\x96\x39\x1b\xbe\x10\x4b\x2b\xad\xd8\x21\x58\xdc\x35\x35\xb7\x08\x5b\x94\xa8\xb9\x45\xe3\x24\x9a\xbc\xc2\x1d\xbf\x32\x56\xd8\xbc\x12\x72\x0b\xb5\xda\x8a\x1c\xb8\x2c\xa0\x52\x75\xe1\x88\xb2\x9d\x2a\xda\x1a\xe1\x09\xb5\x11\x8a\x34\xe1\x16\x7e\x72\x03\x2d\x59\x64\x55\x2f\xd2\x49\xe4\xc6\xa0\x35\x2c\xcb\xee\x2c\x54\xdc\xc0\x6b\x28\x95\xde\x71\x6b\x18\xbc\x81\x69\x50\x67\x0a\x0d\xcf\x1f\xf9\x16\xbd\x30\x53\xa9\xb6\x2e\x60\x83\x80\xbb\xc6\xee\xaf\xc4\xae\x51\xda\x62\x11\xec\xce\x76\x5c\xc8\x9e\xa3\x54\x3a\xa8\x6d\xe0\xa7\xb0\x15\x54\x4a\x3d\x1a\x50\x1a\x1a\x55\x8b\x5c\xa0\x81\x79\xa3\x2c\x4a\x2b\x78\x0d\xf9\x3e\xaf\x45\x1e\x24\x2e\x98\xc3\xc4\x60\xae\x64\x11\xf4\x22\xf7\x44\x03\x52\xff\x4c\x51\xda\x5e\xcd\xa5\x43\x24\x55\x0e\x84\xc9\xa4\xb2\x20\x31\x47\x63\xb8\xde\xc3\x5c\x2a\x50\x8d\x25\x84\x48\xc5\xa3\x8b\xe1\xf4\xe2\x08\xdf\x23\x62\x93\x6d\x78\xfe\xf8\x93\xeb\xc2\x5c\xe5\x6a\xd7\x70\x2b\x36\xa2\x16\x76\xef\x2d\x6c\x34\x3e\x09\xd5\x9a\xe8\x02\x43\xae\x47\x69\x07\x6f\x43\x81\xa5\x90\xd8\x03\xbc\x72\xda\x77\x5d\x06\x00\x70\x38\x0c\xee\x1f\x3c\x30\xa3\xe3\xc3\x01\x50\x16\x70\x41\x48\xf3\xb8\x4d\x85\x38\x5d\xf0\xd9\x12\xc7\x0c\xa6\x9f\x3d\x36\xd3\x44\x66\xa0\xbd\x7c\x29\x4b\xc4\x85\x8b\x27\x87\x03\xcc\x42\x88\xdd\xae\x61\xc6\x3e\xba\xef\x3b\x59\xaa\x78\x2c\x4a\x72\x6f\x20\x62\xdf\x42\x1c\xc6\xf5\x7d\xbb\x73\x84\xb9\x92\xc6\xc2\x3c\x9b\x4c\x0e\x87\x2b\xaf\xec\x31\x0b\x91\x4d\x26\x71\xb5\x86\xe9\xe1\xe0\x54\x9a\xc2\x6a\x05\x71\xdb\x63\xeb\x72\x77\x8b\x92\x05\x79\x51\xdb\x53\xe1\xf1\xfe\xc9\x84\xbe\x8e\x84\xd2\xd6\xcb\x02\x17\xce\xc4\xb0\x7a\xd1\x1f\xd3\xb8\x3f\x00\x5b\x21\x2f\x50\x07\x5c\xe9\x68\xe6\xb3\xe1\x76\x0d\xd7\x41\x9e\xe6\x72\x8b\x30\x93\x1e\xdc\x4f\xaa\x40\xd3\xc3\x2e\xdb\xdd\x6f\x91\x7e\x26\xd9\xa7\xb8\xec\x3a\x8f\xfa\x4c\xb2\xdf\xb8\xf9\x4c\x79\xb5\xf7\x9b\x03\xcb\x1a\x78\x51\x24\xeb\x1b\x4f\x90\x7a\xb5\x4a\x09\xfd\x62\xa0\x1f\x59\x4b\xd4\xda\x36\x8f\x5b\xd2\xa4\xe4\xb5\xc1\x5e\x87\x8a\x9b\x0f\x02\x6b\x17\x72\xf7\xb9\x6a\x1c\x0c\x03\xfd\x1a\xf0\x9f\x30\x63\xee\x84\x85\x90\x1c\x21\x36\x86\x94\x8c\xf2\x8c\x5d\x07\x54\x25\xe1\xc6\xd8\x98\x91\x57\xb1\x5c\xae\xc2\x2f\xdb\x2a\x70\x29\x16\xa2\x30\x18\x11\x83\x78\x72\x2e\xc8\x57\x1a\xb7\xc2\x58\xf2\xca\x2c\x22\x81\xde\xa0\x6c\x32\x59\xad\x7c\x25\x38\x5f\x77\x47\xb5\x48\x48\xca\x92\x19\x7b\xab\x64\x29\xb6\xbd\x6d\x5d\x97\x68\x77\x1c\x3b\x11\xb8\xd5\x2b\x78\x3d\x54\x1a\x0a\x36\x7b\xc9\x26\xaa\x62\xff\x5b\x76\xbd\x60\xdf\x49\x96\xb8\x4e\x07\x51\xb5\x70\x3f\x54\x5c\x16\x35\x6a\x43\xe5\xd5\xee\x1b\x8c\x75\xdc\x78\xcb\xcf\x94\xba\xc1\xb8\xae\xcb\x42\x89\x9f\x67\x49\xb2\x47\x75\xef\xfd\x0d\xce\xe8\x3e\xd3\xb3\x51\x46\xd3\xf7\xa5\xac\x73\x3c\xe7\x6c\x77\xb9\x95\x6c\x8c\x65\x66\x93\xe9\x56\xd8\xaa\xdd\xb0\x5c\xed\x56\x65\x98\x42\x84\xcc\xdb\x0d\xb7\x4a\xbb\x72\x9f\x2d\xb2\x2c\x0b\x7e\x10\x52\x58\x28\x5b\x99\xbb\x7e\xa4\x91\x17\x06\x78\x5d\x47\x7c\x0a\x34\xb9\x16\x8d\x55\x3a\xf4\xd0\x00\x03\xb1\xbb\x99\x65\x5e\x60\xc9\xdb\xda\xc2\x13\xaf\x5b\x34\x4b\xfa\x15\x05\x77\x0c\x4a\xfb\x96\xbb\x70\x4d\xd1\xbb\x1a\x0d\x08\x4b\xdc\x04\x78\x85\x42\xf7\xed\xfa\x89\x6b\xc1\x37\x35\x1a\x96\x91\x3e\x4e\xb3\xf9\x02\x0e\xd9\x4b\x28\xd1\xd9\x2c\x54\x83\x31\x2c\xe1\x2c\xd8\x71\xbb\x86\x0d\x37\x78\xd6\x3b\x44\x77\x5a\xc2\xb2\xc9\xa4\xf1\xdf\xb7\x6b\x17\x86\x26\x72\x30\xef\x81\x4f\x7c\xe7\x52\xa8\x63\x9e\x67\xbe\x70\xf5\x1a\x1a\x2d\xa4\xf5\x4a\x4d\x99\xab\x60\x14\x2a\x0f\xd7\xdf\x61\xed\x80\x9e\x4b\x7c\xb6\xae\x29\x7f\x6c\x2d\x01\xb5\x48\x17\x70\xa0\xfe\xa0\xd1\xb6\x5a\x0e\xfb\xf8\x81\x18\x1d\x77\x6e\x9f\x21\x57\xd2\xe2\xb3\x25\x5b\xe8\x77\x09\xbb\x81\x54\x28\xb9\x80\x39\x2d\xbf\x91\x47\x96\x80\x5a\xd3\x1d\x4e\xee\x44\x94\xb4\x26\x93\xbc\x71\xec\xfd\x13\xaf\x23\x1f\xc9\x5e\xc2\x6e\xf1\x17\x47\xf3\x7f\x6b\x90\xa2\x0e\x7c\x51\x23\x29\x6a\x27\xd1\x6d\xba\x56\xd6\x9f\x90\x42\x5e\xd9\x28\x87\x8e\x3b\xfa\xdb\x9d\x86\xbd\x07\x3c\xe9\x23\xa7\xe0\xf5\xd8\xfd\xda\x03\x8e\xd4\x39\x80\x26\x2a\xb1\x84\x8a\x78\x7c\xd0\x5c\x94\xea\x2c\xbb\xec\x30\x71\xb6\xb3\xfd\xe9\xa6\xaf\x29\xe4\xd0\xea\xa2\x75\x34\x87\x38\xd6\x77\x21\x41\xfc\xea\xdb\x90\x1e\x47\x43\x82\x64\x1f\xc5\x33\x16\x77\xf2\x1f\xc2\x56\x81\xe9\xef\xba\xa7\x0f\x93\x03\x59\xee\x9b\xd2\x47\xf1\x2c\xe4\xaf\xa1\x71\x64\x0e\x9a\x63\x5e\xd7\x2c\x5d\x47\x7f\x60\x8c\x7d\x7f\xf8\x4e\x41\xe3\x36\xbd\xcf\x93\xbc\x13\x4b\x98\xfd\x20\xca\xe7\x98\x88\xe4\x3a\xaf\x81\xd7\xeb\x44\xfa\x03\xad\x05\xc1\xe4\x65\x9a\xf9\x62\xd9\x8b\xed\x67\xa4\x49\x77\x79\x6a\x92\x81\xf1\xc4\xf2\x41\xf1\x97\x4d\x8f\xf7\x12\xf7\x0f\xf0\xd4\xa9\x84\x73\x57\x27\x06\x97\x61\xd8\x39\xd2\xe2\x0a\x66\x54\x15\x5d\x0e\x25\x91\xf3\x0e\x4d\x3e\x85\x59\xc9\xee\xad\x6e\x73\xeb\x27\x91\x81\x67\xf5\x0a\x50\xb6\x3b\x18\x97\xcb\xd0\x7f\x0a\x90\xc8\x75\xa8\x87\x05\xe6\x35\xd7\x2e\x21\x0d\xcc\xe9\x61\x93\xf4\xa5\x05\x0b\x2d\x79\x92\xc4\xd9\x9c\xca\xeb\xac\x64\x31\xd2\xe6\xae\x53\x97\xec\xce\xbc\x97\xed\x6e\xb1\xa0\xef\xaf\x4d\xc1\x2d\xf6\xb1\x58\xb2\xe3\x40\xec\x05\xce\x4a\xf6\x59\x19\x41\xf7\xc7\x88\xec\x7d\xbc\x5a\x39\x10\x9d\xfd\x5d\x47\xdd\x7a\x78\x1b\x26\xbd\xc2\xbd\x6b\x88\xb0\x8c\xde\x80\x92\xf0\x60\x43\xa4\x44\x11\xb7\xa9\x5b\x92\xb0\x7c\xf0\xec\xa9\x26\x42\xde\xc9\x02\x9f\x29\xa4\x8e\x4f\xfb\x03\xf6\xae\x57\xc2\xfb\xdd\x7b\xb8\x9f\x3e\xfe\xfb\x36\x9c\x57\xff\x57\x0a\xca\x34\x56\x46\x01\x29\x4a\x78\xd9\xbd\xe3\xc0\xf4\x24\x47\xb1\xc9\xa6\x09\x7f\xb0\x26\x4b\xa1\xf0\x5c\x5d\x37\xbc\xe5\xc7\x81\x0a\x4a\x42\xae\x91\xf7\x8f\x56\xa2\xb8\x04\xce\x91\xc8\x75\x0a\x77\x54\x82\xcd\x87\xd7\x1a\x59\xf2\x45\xec\xd0\x7f\x7d\xfd\x7a\xf7\x0e\xba\xce\xf5\xba\xc5\xf0\xfa\xf3\x97\x7d\xa1\x54\xe8\xba\xc5\xb9\xcc\xf5\xa1\x3b\x8e\xf3\x7f\x17\x9a\x11\xd7\x1f\x05\xa8\x75\x42\xfe\x33\x78\x46\x8a\x44\x90\x06\x84\xfe\x08\x2e\xbe\x98\x9e\x49\x78\x07\x8b\x24\xfd\xce\x62\x72\xda\x79\xae\x60\xe6\x6a\x11\xcd\x5a\x8e\xbe\x84\xa9\x1b\xd5\xe6\xff\x6f\x16\x7e\xce\x98\x26\xda\x24\x00\xca\x80\x82\x30\xc0\x87\x09\xb1\x87\x6a\x3a\xc2\x6a\x1a\xc0\x82\x3b\xf7\x3f\x97\x9c\xd7\x54\x21\x37\x7b\x47\xba\x69\x45\x5d\xd0\xc0\xbe\xc1\x52\x69\x04\xc3\x9f\x90\x25\xe5\x90\xde\x78\x23\x5b\x6f\x86\xf2\x36\xe8\x31\x06\x7d\xa0\x7e\xb8\xfe\xee\x40\xf7\x76\x7a\x40\x4f\x2a\xc8\x58\xd0\xe0\x90\xc8\x14\x47\xa6\x64\x12\xbe\xbd\x74\xa1\xa7\x2c\xe5\xd0\x86\x9d\xbc\xb1\x57\x3d\xb4\x51\x6c\xda\xa6\x7e\x5f\x86\x99\x38\xf6\xe5\x73\x75\x7d\xa4\x8a\x2b\x4c\xbf\xbb\x4a\x34\xbf\x78\x55\xe8\xd4\xc7\xb5\x29\x4e\x7c\x71\xe4\x4b\xf8\xff\xea\xdd\x12\xbb\x1e\xbc\x68\x00\xb9\xfd\xc7\x12\x4a\x39\x0c\x69\x84\x40\x3c\x4e\x86\xd4\x52\x9e\x97\x7f\x76\x44\x4d\xe6\xe6\x30\xa0\x0e\x1a\xf7\xbf\xc3\x1c\x9b\x5a\xd4\xcd\x17\x67\x8b\x6f\x3a\xd3\xf5\x4f\xca\x73\x9f\xfe\x7f\x06\x61\xf1\xaf\x00\x00\x00\xff\xff\xf2\xa3\x07\xce\x18\x16\x00\x00") func templateRuntimeTmplBytes() ([]byte, error) { return bindataRead( @@ -1039,7 +1039,7 @@ func templateRuntimeTmpl() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "template/runtime.tmpl", size: 5653, mode: os.FileMode(420), modTime: time.Unix(1, 0)} + info := bindataFileInfo{name: "template/runtime.tmpl", size: 5656, mode: os.FileMode(420), modTime: time.Unix(1, 0)} a := &asset{bytes: bytes, info: info} return a, nil } diff --git a/entc/gen/template/privacy.tmpl b/entc/gen/template/privacy.tmpl index c667e1e61..e28f68269 100644 --- a/entc/gen/template/privacy.tmpl +++ b/entc/gen/template/privacy.tmpl @@ -15,15 +15,15 @@ import "{{ $.Config.Package }}" {{ $pkg := base $.Config.Package }} var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -36,19 +36,20 @@ var ( {{- end }} type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, {{ $pkg }}.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, {{ $pkg }}.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v {{ $pkg }}.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q {{ $pkg }}.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -59,29 +60,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v {{ $pkg }}.Value) error return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, {{ $pkg }}.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, {{ $pkg }}.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v {{ $pkg }}.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q {{ $pkg }}.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, {{ $pkg }}.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, {{ $pkg }}.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m {{ $pkg }}.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m {{ $pkg }}.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -92,75 +94,75 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m {{ $pkg }}.Mutation) return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, {{ $pkg }}.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, {{ $pkg }}.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m {{ $pkg }}.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m {{ $pkg }}.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v {{ $pkg }}.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q {{ $pkg }}.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m {{ $pkg }}.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m {{ $pkg }}.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct { err error } -func (f fixedDecisionRule) EvalRead(context.Context, {{ $pkg }}.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, {{ $pkg }}.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, {{ $pkg }}.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, {{ $pkg }}.Mutation) error { return f.err } {{- range $n := $.Nodes }} - {{ $name := print $n.Name "ReadRuleFunc" }} - {{ $type := printf "*%s.%s" $pkg $n.Name }} + {{ $name := print $n.Name "QueryRuleFunc" }} + {{ $type := printf "*%s.%s" $pkg $n.QueryName }} // The {{ $name }} type is an adapter to allow the use of ordinary - // functions as a read rule. + // functions as a query rule. type {{ $name }} func(context.Context, {{ $type }}) error - // EvalRead calls f(ctx, v). - func (f {{ $name }}) EvalRead(ctx context.Context, v {{ $pkg }}.Value) error { - if v, ok := v.({{ $type }}); ok { - return f(ctx, v) + // EvalQuery return f(ctx, q). + func (f {{ $name }}) EvalQuery(ctx context.Context, q {{ $pkg }}.Query) error { + if q, ok := q.({{ $type }}); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect {{ $type }}", v) + return Denyf("ent/privacy: unexpected query type %T, expect {{ $type }}", q) } - {{ $name = print $n.Name "WriteRuleFunc" }} + {{ $name = print $n.Name "MutationRuleFunc" }} {{ $type = printf "*%s.%s" $pkg $n.MutationName }} // The {{ $name }} type is an adapter to allow the use of ordinary - // functions as a write rule. + // functions as a mutation rule. type {{ $name }} func(context.Context, {{ $type }}) error - // EvalWrite calls f(ctx, m). - func (f {{ $name }}) EvalWrite(ctx context.Context, m {{ $pkg }}.Mutation) error { + // EvalMutation calls f(ctx, m). + func (f {{ $name }}) EvalMutation(ctx context.Context, m {{ $pkg }}.Mutation) error { if m, ok := m.({{ $type }}); ok { return f(ctx, m) } diff --git a/entc/gen/template/runtime.tmpl b/entc/gen/template/runtime.tmpl index 9d08283cf..3ffa22e51 100644 --- a/entc/gen/template/runtime.tmpl +++ b/entc/gen/template/runtime.tmpl @@ -88,7 +88,7 @@ func init() { policy := {{ $schema }}.{{ $n.Name }}{}.Policy() {{ print $pkg ".Hooks" }}[0] = func(next ent.Mutator) ent.Mutator { return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if err := policy.EvalWrite(ctx, m); err != nil { + if err := policy.EvalMutation(ctx, m); err != nil { return nil, err } return next.Mutate(ctx, m) diff --git a/entc/integration/config/ent/privacy/privacy.go b/entc/integration/config/ent/privacy/privacy.go index 978a7e8ca..745270da0 100644 --- a/entc/integration/config/ent/privacy/privacy.go +++ b/entc/integration/config/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,70 +102,70 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) } diff --git a/entc/integration/customid/ent/privacy/privacy.go b/entc/integration/customid/ent/privacy/privacy.go index 0d4440c0f..58a2cc0ed 100644 --- a/entc/integration/customid/ent/privacy/privacy.go +++ b/entc/integration/customid/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,166 +102,166 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The BlobReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type BlobReadRuleFunc func(context.Context, *ent.Blob) error +// The BlobQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type BlobQueryRuleFunc func(context.Context, *ent.BlobQuery) error -// EvalRead calls f(ctx, v). -func (f BlobReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Blob); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f BlobQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.BlobQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Blob", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.BlobQuery", q) } -// The BlobWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type BlobWriteRuleFunc func(context.Context, *ent.BlobMutation) error +// The BlobMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type BlobMutationRuleFunc func(context.Context, *ent.BlobMutation) error -// EvalWrite calls f(ctx, m). -func (f BlobWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f BlobMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.BlobMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.BlobMutation", m) } -// The CarReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type CarReadRuleFunc func(context.Context, *ent.Car) error +// The CarQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type CarQueryRuleFunc func(context.Context, *ent.CarQuery) error -// EvalRead calls f(ctx, v). -func (f CarReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Car); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f CarQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.CarQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Car", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.CarQuery", q) } -// The CarWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type CarWriteRuleFunc func(context.Context, *ent.CarMutation) error +// The CarMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type CarMutationRuleFunc func(context.Context, *ent.CarMutation) error -// EvalWrite calls f(ctx, m). -func (f CarWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f CarMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.CarMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CarMutation", m) } -// The GroupReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type GroupReadRuleFunc func(context.Context, *ent.Group) error +// The GroupQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type GroupQueryRuleFunc func(context.Context, *ent.GroupQuery) error -// EvalRead calls f(ctx, v). -func (f GroupReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Group); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f GroupQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.GroupQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Group", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.GroupQuery", q) } -// The GroupWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type GroupWriteRuleFunc func(context.Context, *ent.GroupMutation) error +// The GroupMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type GroupMutationRuleFunc func(context.Context, *ent.GroupMutation) error -// EvalWrite calls f(ctx, m). -func (f GroupWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f GroupMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.GroupMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.GroupMutation", m) } -// The PetReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type PetReadRuleFunc func(context.Context, *ent.Pet) error +// The PetQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type PetQueryRuleFunc func(context.Context, *ent.PetQuery) error -// EvalRead calls f(ctx, v). -func (f PetReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Pet); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f PetQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.PetQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Pet", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.PetQuery", q) } -// The PetWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type PetWriteRuleFunc func(context.Context, *ent.PetMutation) error +// The PetMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type PetMutationRuleFunc func(context.Context, *ent.PetMutation) error -// EvalWrite calls f(ctx, m). -func (f PetWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f PetMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.PetMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.PetMutation", m) } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) } diff --git a/entc/integration/ent/privacy/privacy.go b/entc/integration/ent/privacy/privacy.go index b719a2973..8f6e18146 100644 --- a/entc/integration/ent/privacy/privacy.go +++ b/entc/integration/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,334 +102,334 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The CardReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type CardReadRuleFunc func(context.Context, *ent.Card) error +// The CardQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type CardQueryRuleFunc func(context.Context, *ent.CardQuery) error -// EvalRead calls f(ctx, v). -func (f CardReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Card); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f CardQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.CardQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Card", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.CardQuery", q) } -// The CardWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type CardWriteRuleFunc func(context.Context, *ent.CardMutation) error +// The CardMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type CardMutationRuleFunc func(context.Context, *ent.CardMutation) error -// EvalWrite calls f(ctx, m). -func (f CardWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f CardMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.CardMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CardMutation", m) } -// The CommentReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type CommentReadRuleFunc func(context.Context, *ent.Comment) error +// The CommentQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type CommentQueryRuleFunc func(context.Context, *ent.CommentQuery) error -// EvalRead calls f(ctx, v). -func (f CommentReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Comment); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f CommentQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.CommentQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Comment", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.CommentQuery", q) } -// The CommentWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type CommentWriteRuleFunc func(context.Context, *ent.CommentMutation) error +// The CommentMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type CommentMutationRuleFunc func(context.Context, *ent.CommentMutation) error -// EvalWrite calls f(ctx, m). -func (f CommentWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f CommentMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.CommentMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CommentMutation", m) } -// The FieldTypeReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type FieldTypeReadRuleFunc func(context.Context, *ent.FieldType) error +// The FieldTypeQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type FieldTypeQueryRuleFunc func(context.Context, *ent.FieldTypeQuery) error -// EvalRead calls f(ctx, v). -func (f FieldTypeReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.FieldType); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f FieldTypeQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.FieldTypeQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.FieldType", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.FieldTypeQuery", q) } -// The FieldTypeWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type FieldTypeWriteRuleFunc func(context.Context, *ent.FieldTypeMutation) error +// The FieldTypeMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type FieldTypeMutationRuleFunc func(context.Context, *ent.FieldTypeMutation) error -// EvalWrite calls f(ctx, m). -func (f FieldTypeWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f FieldTypeMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.FieldTypeMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.FieldTypeMutation", m) } -// The FileReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type FileReadRuleFunc func(context.Context, *ent.File) error +// The FileQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type FileQueryRuleFunc func(context.Context, *ent.FileQuery) error -// EvalRead calls f(ctx, v). -func (f FileReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.File); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f FileQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.FileQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.File", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.FileQuery", q) } -// The FileWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type FileWriteRuleFunc func(context.Context, *ent.FileMutation) error +// The FileMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type FileMutationRuleFunc func(context.Context, *ent.FileMutation) error -// EvalWrite calls f(ctx, m). -func (f FileWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f FileMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.FileMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.FileMutation", m) } -// The FileTypeReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type FileTypeReadRuleFunc func(context.Context, *ent.FileType) error +// The FileTypeQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type FileTypeQueryRuleFunc func(context.Context, *ent.FileTypeQuery) error -// EvalRead calls f(ctx, v). -func (f FileTypeReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.FileType); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f FileTypeQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.FileTypeQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.FileType", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.FileTypeQuery", q) } -// The FileTypeWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type FileTypeWriteRuleFunc func(context.Context, *ent.FileTypeMutation) error +// The FileTypeMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type FileTypeMutationRuleFunc func(context.Context, *ent.FileTypeMutation) error -// EvalWrite calls f(ctx, m). -func (f FileTypeWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f FileTypeMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.FileTypeMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.FileTypeMutation", m) } -// The GroupReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type GroupReadRuleFunc func(context.Context, *ent.Group) error +// The GroupQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type GroupQueryRuleFunc func(context.Context, *ent.GroupQuery) error -// EvalRead calls f(ctx, v). -func (f GroupReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Group); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f GroupQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.GroupQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Group", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.GroupQuery", q) } -// The GroupWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type GroupWriteRuleFunc func(context.Context, *ent.GroupMutation) error +// The GroupMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type GroupMutationRuleFunc func(context.Context, *ent.GroupMutation) error -// EvalWrite calls f(ctx, m). -func (f GroupWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f GroupMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.GroupMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.GroupMutation", m) } -// The GroupInfoReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type GroupInfoReadRuleFunc func(context.Context, *ent.GroupInfo) error +// The GroupInfoQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type GroupInfoQueryRuleFunc func(context.Context, *ent.GroupInfoQuery) error -// EvalRead calls f(ctx, v). -func (f GroupInfoReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.GroupInfo); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f GroupInfoQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.GroupInfoQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.GroupInfo", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.GroupInfoQuery", q) } -// The GroupInfoWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type GroupInfoWriteRuleFunc func(context.Context, *ent.GroupInfoMutation) error +// The GroupInfoMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type GroupInfoMutationRuleFunc func(context.Context, *ent.GroupInfoMutation) error -// EvalWrite calls f(ctx, m). -func (f GroupInfoWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f GroupInfoMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.GroupInfoMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.GroupInfoMutation", m) } -// The ItemReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type ItemReadRuleFunc func(context.Context, *ent.Item) error +// The ItemQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type ItemQueryRuleFunc func(context.Context, *ent.ItemQuery) error -// EvalRead calls f(ctx, v). -func (f ItemReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Item); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f ItemQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.ItemQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Item", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.ItemQuery", q) } -// The ItemWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type ItemWriteRuleFunc func(context.Context, *ent.ItemMutation) error +// The ItemMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type ItemMutationRuleFunc func(context.Context, *ent.ItemMutation) error -// EvalWrite calls f(ctx, m). -func (f ItemWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f ItemMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.ItemMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.ItemMutation", m) } -// The NodeReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type NodeReadRuleFunc func(context.Context, *ent.Node) error +// The NodeQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type NodeQueryRuleFunc func(context.Context, *ent.NodeQuery) error -// EvalRead calls f(ctx, v). -func (f NodeReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Node); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f NodeQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.NodeQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Node", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.NodeQuery", q) } -// The NodeWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type NodeWriteRuleFunc func(context.Context, *ent.NodeMutation) error +// The NodeMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type NodeMutationRuleFunc func(context.Context, *ent.NodeMutation) error -// EvalWrite calls f(ctx, m). -func (f NodeWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f NodeMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.NodeMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.NodeMutation", m) } -// The PetReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type PetReadRuleFunc func(context.Context, *ent.Pet) error +// The PetQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type PetQueryRuleFunc func(context.Context, *ent.PetQuery) error -// EvalRead calls f(ctx, v). -func (f PetReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Pet); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f PetQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.PetQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Pet", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.PetQuery", q) } -// The PetWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type PetWriteRuleFunc func(context.Context, *ent.PetMutation) error +// The PetMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type PetMutationRuleFunc func(context.Context, *ent.PetMutation) error -// EvalWrite calls f(ctx, m). -func (f PetWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f PetMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.PetMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.PetMutation", m) } -// The SpecReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type SpecReadRuleFunc func(context.Context, *ent.Spec) error +// The SpecQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type SpecQueryRuleFunc func(context.Context, *ent.SpecQuery) error -// EvalRead calls f(ctx, v). -func (f SpecReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Spec); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f SpecQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.SpecQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Spec", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.SpecQuery", q) } -// The SpecWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type SpecWriteRuleFunc func(context.Context, *ent.SpecMutation) error +// The SpecMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type SpecMutationRuleFunc func(context.Context, *ent.SpecMutation) error -// EvalWrite calls f(ctx, m). -func (f SpecWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f SpecMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.SpecMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.SpecMutation", m) } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) } diff --git a/entc/integration/gremlin/ent/privacy/privacy.go b/entc/integration/gremlin/ent/privacy/privacy.go index 837cecaff..6cb6f5db3 100644 --- a/entc/integration/gremlin/ent/privacy/privacy.go +++ b/entc/integration/gremlin/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,334 +102,334 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The CardReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type CardReadRuleFunc func(context.Context, *ent.Card) error +// The CardQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type CardQueryRuleFunc func(context.Context, *ent.CardQuery) error -// EvalRead calls f(ctx, v). -func (f CardReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Card); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f CardQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.CardQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Card", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.CardQuery", q) } -// The CardWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type CardWriteRuleFunc func(context.Context, *ent.CardMutation) error +// The CardMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type CardMutationRuleFunc func(context.Context, *ent.CardMutation) error -// EvalWrite calls f(ctx, m). -func (f CardWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f CardMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.CardMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CardMutation", m) } -// The CommentReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type CommentReadRuleFunc func(context.Context, *ent.Comment) error +// The CommentQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type CommentQueryRuleFunc func(context.Context, *ent.CommentQuery) error -// EvalRead calls f(ctx, v). -func (f CommentReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Comment); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f CommentQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.CommentQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Comment", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.CommentQuery", q) } -// The CommentWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type CommentWriteRuleFunc func(context.Context, *ent.CommentMutation) error +// The CommentMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type CommentMutationRuleFunc func(context.Context, *ent.CommentMutation) error -// EvalWrite calls f(ctx, m). -func (f CommentWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f CommentMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.CommentMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CommentMutation", m) } -// The FieldTypeReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type FieldTypeReadRuleFunc func(context.Context, *ent.FieldType) error +// The FieldTypeQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type FieldTypeQueryRuleFunc func(context.Context, *ent.FieldTypeQuery) error -// EvalRead calls f(ctx, v). -func (f FieldTypeReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.FieldType); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f FieldTypeQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.FieldTypeQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.FieldType", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.FieldTypeQuery", q) } -// The FieldTypeWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type FieldTypeWriteRuleFunc func(context.Context, *ent.FieldTypeMutation) error +// The FieldTypeMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type FieldTypeMutationRuleFunc func(context.Context, *ent.FieldTypeMutation) error -// EvalWrite calls f(ctx, m). -func (f FieldTypeWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f FieldTypeMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.FieldTypeMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.FieldTypeMutation", m) } -// The FileReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type FileReadRuleFunc func(context.Context, *ent.File) error +// The FileQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type FileQueryRuleFunc func(context.Context, *ent.FileQuery) error -// EvalRead calls f(ctx, v). -func (f FileReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.File); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f FileQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.FileQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.File", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.FileQuery", q) } -// The FileWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type FileWriteRuleFunc func(context.Context, *ent.FileMutation) error +// The FileMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type FileMutationRuleFunc func(context.Context, *ent.FileMutation) error -// EvalWrite calls f(ctx, m). -func (f FileWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f FileMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.FileMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.FileMutation", m) } -// The FileTypeReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type FileTypeReadRuleFunc func(context.Context, *ent.FileType) error +// The FileTypeQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type FileTypeQueryRuleFunc func(context.Context, *ent.FileTypeQuery) error -// EvalRead calls f(ctx, v). -func (f FileTypeReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.FileType); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f FileTypeQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.FileTypeQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.FileType", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.FileTypeQuery", q) } -// The FileTypeWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type FileTypeWriteRuleFunc func(context.Context, *ent.FileTypeMutation) error +// The FileTypeMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type FileTypeMutationRuleFunc func(context.Context, *ent.FileTypeMutation) error -// EvalWrite calls f(ctx, m). -func (f FileTypeWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f FileTypeMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.FileTypeMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.FileTypeMutation", m) } -// The GroupReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type GroupReadRuleFunc func(context.Context, *ent.Group) error +// The GroupQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type GroupQueryRuleFunc func(context.Context, *ent.GroupQuery) error -// EvalRead calls f(ctx, v). -func (f GroupReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Group); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f GroupQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.GroupQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Group", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.GroupQuery", q) } -// The GroupWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type GroupWriteRuleFunc func(context.Context, *ent.GroupMutation) error +// The GroupMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type GroupMutationRuleFunc func(context.Context, *ent.GroupMutation) error -// EvalWrite calls f(ctx, m). -func (f GroupWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f GroupMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.GroupMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.GroupMutation", m) } -// The GroupInfoReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type GroupInfoReadRuleFunc func(context.Context, *ent.GroupInfo) error +// The GroupInfoQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type GroupInfoQueryRuleFunc func(context.Context, *ent.GroupInfoQuery) error -// EvalRead calls f(ctx, v). -func (f GroupInfoReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.GroupInfo); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f GroupInfoQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.GroupInfoQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.GroupInfo", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.GroupInfoQuery", q) } -// The GroupInfoWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type GroupInfoWriteRuleFunc func(context.Context, *ent.GroupInfoMutation) error +// The GroupInfoMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type GroupInfoMutationRuleFunc func(context.Context, *ent.GroupInfoMutation) error -// EvalWrite calls f(ctx, m). -func (f GroupInfoWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f GroupInfoMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.GroupInfoMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.GroupInfoMutation", m) } -// The ItemReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type ItemReadRuleFunc func(context.Context, *ent.Item) error +// The ItemQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type ItemQueryRuleFunc func(context.Context, *ent.ItemQuery) error -// EvalRead calls f(ctx, v). -func (f ItemReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Item); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f ItemQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.ItemQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Item", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.ItemQuery", q) } -// The ItemWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type ItemWriteRuleFunc func(context.Context, *ent.ItemMutation) error +// The ItemMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type ItemMutationRuleFunc func(context.Context, *ent.ItemMutation) error -// EvalWrite calls f(ctx, m). -func (f ItemWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f ItemMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.ItemMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.ItemMutation", m) } -// The NodeReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type NodeReadRuleFunc func(context.Context, *ent.Node) error +// The NodeQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type NodeQueryRuleFunc func(context.Context, *ent.NodeQuery) error -// EvalRead calls f(ctx, v). -func (f NodeReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Node); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f NodeQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.NodeQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Node", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.NodeQuery", q) } -// The NodeWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type NodeWriteRuleFunc func(context.Context, *ent.NodeMutation) error +// The NodeMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type NodeMutationRuleFunc func(context.Context, *ent.NodeMutation) error -// EvalWrite calls f(ctx, m). -func (f NodeWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f NodeMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.NodeMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.NodeMutation", m) } -// The PetReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type PetReadRuleFunc func(context.Context, *ent.Pet) error +// The PetQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type PetQueryRuleFunc func(context.Context, *ent.PetQuery) error -// EvalRead calls f(ctx, v). -func (f PetReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Pet); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f PetQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.PetQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Pet", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.PetQuery", q) } -// The PetWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type PetWriteRuleFunc func(context.Context, *ent.PetMutation) error +// The PetMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type PetMutationRuleFunc func(context.Context, *ent.PetMutation) error -// EvalWrite calls f(ctx, m). -func (f PetWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f PetMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.PetMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.PetMutation", m) } -// The SpecReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type SpecReadRuleFunc func(context.Context, *ent.Spec) error +// The SpecQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type SpecQueryRuleFunc func(context.Context, *ent.SpecQuery) error -// EvalRead calls f(ctx, v). -func (f SpecReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Spec); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f SpecQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.SpecQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Spec", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.SpecQuery", q) } -// The SpecWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type SpecWriteRuleFunc func(context.Context, *ent.SpecMutation) error +// The SpecMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type SpecMutationRuleFunc func(context.Context, *ent.SpecMutation) error -// EvalWrite calls f(ctx, m). -func (f SpecWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f SpecMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.SpecMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.SpecMutation", m) } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) } diff --git a/entc/integration/hooks/ent/privacy/privacy.go b/entc/integration/hooks/ent/privacy/privacy.go index 060c7df6b..481a79ed3 100644 --- a/entc/integration/hooks/ent/privacy/privacy.go +++ b/entc/integration/hooks/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,94 +102,94 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The CardReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type CardReadRuleFunc func(context.Context, *ent.Card) error +// The CardQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type CardQueryRuleFunc func(context.Context, *ent.CardQuery) error -// EvalRead calls f(ctx, v). -func (f CardReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Card); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f CardQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.CardQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Card", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.CardQuery", q) } -// The CardWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type CardWriteRuleFunc func(context.Context, *ent.CardMutation) error +// The CardMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type CardMutationRuleFunc func(context.Context, *ent.CardMutation) error -// EvalWrite calls f(ctx, m). -func (f CardWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f CardMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.CardMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CardMutation", m) } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) } diff --git a/entc/integration/idtype/ent/privacy/privacy.go b/entc/integration/idtype/ent/privacy/privacy.go index 85fe1952d..ed4f26f2a 100644 --- a/entc/integration/idtype/ent/privacy/privacy.go +++ b/entc/integration/idtype/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,70 +102,70 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) } diff --git a/entc/integration/json/ent/privacy/privacy.go b/entc/integration/json/ent/privacy/privacy.go index 2b15514b1..e7b1d9369 100644 --- a/entc/integration/json/ent/privacy/privacy.go +++ b/entc/integration/json/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,70 +102,70 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) } diff --git a/entc/integration/migrate/entv1/privacy/privacy.go b/entc/integration/migrate/entv1/privacy/privacy.go index bf7d8e940..3462b20a3 100644 --- a/entc/integration/migrate/entv1/privacy/privacy.go +++ b/entc/integration/migrate/entv1/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, entv1.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, entv1.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v entv1.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q entv1.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v entv1.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, entv1.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, entv1.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v entv1.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q entv1.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, entv1.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, entv1.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m entv1.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m entv1.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,94 +102,94 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m entv1.Mutation) error return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, entv1.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, entv1.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m entv1.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m entv1.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v entv1.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q entv1.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m entv1.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m entv1.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, entv1.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, entv1.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, entv1.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, entv1.Mutation) error { return f.err } -// The CarReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type CarReadRuleFunc func(context.Context, *entv1.Car) error +// The CarQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type CarQueryRuleFunc func(context.Context, *entv1.CarQuery) error -// EvalRead calls f(ctx, v). -func (f CarReadRuleFunc) EvalRead(ctx context.Context, v entv1.Value) error { - if v, ok := v.(*entv1.Car); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f CarQueryRuleFunc) EvalQuery(ctx context.Context, q entv1.Query) error { + if q, ok := q.(*entv1.CarQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *entv1.Car", v) + return Denyf("ent/privacy: unexpected query type %T, expect *entv1.CarQuery", q) } -// The CarWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type CarWriteRuleFunc func(context.Context, *entv1.CarMutation) error +// The CarMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type CarMutationRuleFunc func(context.Context, *entv1.CarMutation) error -// EvalWrite calls f(ctx, m). -func (f CarWriteRuleFunc) EvalWrite(ctx context.Context, m entv1.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f CarMutationRuleFunc) EvalMutation(ctx context.Context, m entv1.Mutation) error { if m, ok := m.(*entv1.CarMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *entv1.CarMutation", m) } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *entv1.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *entv1.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v entv1.Value) error { - if v, ok := v.(*entv1.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q entv1.Query) error { + if q, ok := q.(*entv1.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *entv1.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *entv1.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *entv1.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *entv1.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m entv1.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m entv1.Mutation) error { if m, ok := m.(*entv1.UserMutation); ok { return f(ctx, m) } diff --git a/entc/integration/migrate/entv2/privacy/privacy.go b/entc/integration/migrate/entv2/privacy/privacy.go index bb93b936c..cb22ce294 100644 --- a/entc/integration/migrate/entv2/privacy/privacy.go +++ b/entc/integration/migrate/entv2/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, entv2.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, entv2.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v entv2.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q entv2.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v entv2.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, entv2.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, entv2.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v entv2.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q entv2.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, entv2.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, entv2.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m entv2.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m entv2.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,142 +102,142 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m entv2.Mutation) error return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, entv2.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, entv2.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m entv2.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m entv2.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v entv2.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q entv2.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m entv2.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m entv2.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, entv2.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, entv2.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, entv2.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, entv2.Mutation) error { return f.err } -// The CarReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type CarReadRuleFunc func(context.Context, *entv2.Car) error +// The CarQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type CarQueryRuleFunc func(context.Context, *entv2.CarQuery) error -// EvalRead calls f(ctx, v). -func (f CarReadRuleFunc) EvalRead(ctx context.Context, v entv2.Value) error { - if v, ok := v.(*entv2.Car); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f CarQueryRuleFunc) EvalQuery(ctx context.Context, q entv2.Query) error { + if q, ok := q.(*entv2.CarQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *entv2.Car", v) + return Denyf("ent/privacy: unexpected query type %T, expect *entv2.CarQuery", q) } -// The CarWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type CarWriteRuleFunc func(context.Context, *entv2.CarMutation) error +// The CarMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type CarMutationRuleFunc func(context.Context, *entv2.CarMutation) error -// EvalWrite calls f(ctx, m). -func (f CarWriteRuleFunc) EvalWrite(ctx context.Context, m entv2.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f CarMutationRuleFunc) EvalMutation(ctx context.Context, m entv2.Mutation) error { if m, ok := m.(*entv2.CarMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *entv2.CarMutation", m) } -// The GroupReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type GroupReadRuleFunc func(context.Context, *entv2.Group) error +// The GroupQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type GroupQueryRuleFunc func(context.Context, *entv2.GroupQuery) error -// EvalRead calls f(ctx, v). -func (f GroupReadRuleFunc) EvalRead(ctx context.Context, v entv2.Value) error { - if v, ok := v.(*entv2.Group); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f GroupQueryRuleFunc) EvalQuery(ctx context.Context, q entv2.Query) error { + if q, ok := q.(*entv2.GroupQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *entv2.Group", v) + return Denyf("ent/privacy: unexpected query type %T, expect *entv2.GroupQuery", q) } -// The GroupWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type GroupWriteRuleFunc func(context.Context, *entv2.GroupMutation) error +// The GroupMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type GroupMutationRuleFunc func(context.Context, *entv2.GroupMutation) error -// EvalWrite calls f(ctx, m). -func (f GroupWriteRuleFunc) EvalWrite(ctx context.Context, m entv2.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f GroupMutationRuleFunc) EvalMutation(ctx context.Context, m entv2.Mutation) error { if m, ok := m.(*entv2.GroupMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *entv2.GroupMutation", m) } -// The PetReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type PetReadRuleFunc func(context.Context, *entv2.Pet) error +// The PetQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type PetQueryRuleFunc func(context.Context, *entv2.PetQuery) error -// EvalRead calls f(ctx, v). -func (f PetReadRuleFunc) EvalRead(ctx context.Context, v entv2.Value) error { - if v, ok := v.(*entv2.Pet); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f PetQueryRuleFunc) EvalQuery(ctx context.Context, q entv2.Query) error { + if q, ok := q.(*entv2.PetQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *entv2.Pet", v) + return Denyf("ent/privacy: unexpected query type %T, expect *entv2.PetQuery", q) } -// The PetWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type PetWriteRuleFunc func(context.Context, *entv2.PetMutation) error +// The PetMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type PetMutationRuleFunc func(context.Context, *entv2.PetMutation) error -// EvalWrite calls f(ctx, m). -func (f PetWriteRuleFunc) EvalWrite(ctx context.Context, m entv2.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f PetMutationRuleFunc) EvalMutation(ctx context.Context, m entv2.Mutation) error { if m, ok := m.(*entv2.PetMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *entv2.PetMutation", m) } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *entv2.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *entv2.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v entv2.Value) error { - if v, ok := v.(*entv2.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q entv2.Query) error { + if q, ok := q.(*entv2.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *entv2.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *entv2.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *entv2.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *entv2.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m entv2.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m entv2.Mutation) error { if m, ok := m.(*entv2.UserMutation); ok { return f(ctx, m) } diff --git a/entc/integration/privacy/ent/privacy/privacy.go b/entc/integration/privacy/ent/privacy/privacy.go index cc9219a8b..d0ac3d88b 100644 --- a/entc/integration/privacy/ent/privacy/privacy.go +++ b/entc/integration/privacy/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,70 +102,70 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The PlanetReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type PlanetReadRuleFunc func(context.Context, *ent.Planet) error +// The PlanetQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type PlanetQueryRuleFunc func(context.Context, *ent.PlanetQuery) error -// EvalRead calls f(ctx, v). -func (f PlanetReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Planet); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f PlanetQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.PlanetQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Planet", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.PlanetQuery", q) } -// The PlanetWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type PlanetWriteRuleFunc func(context.Context, *ent.PlanetMutation) error +// The PlanetMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type PlanetMutationRuleFunc func(context.Context, *ent.PlanetMutation) error -// EvalWrite calls f(ctx, m). -func (f PlanetWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f PlanetMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.PlanetMutation); ok { return f(ctx, m) } diff --git a/entc/integration/privacy/ent/runtime/runtime.go b/entc/integration/privacy/ent/runtime/runtime.go index 53c8247f3..fec443953 100644 --- a/entc/integration/privacy/ent/runtime/runtime.go +++ b/entc/integration/privacy/ent/runtime/runtime.go @@ -22,7 +22,7 @@ func init() { policy := schema.Planet{}.Policy() planet.Hooks[0] = func(next ent.Mutator) ent.Mutator { return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if err := policy.EvalWrite(ctx, m); err != nil { + if err := policy.EvalMutation(ctx, m); err != nil { return nil, err } return next.Mutate(ctx, m) diff --git a/entc/integration/privacy/ent/schema/planet.go b/entc/integration/privacy/ent/schema/planet.go index 4e71d2551..8ceddffb8 100644 --- a/entc/integration/privacy/ent/schema/planet.go +++ b/entc/integration/privacy/ent/schema/planet.go @@ -38,12 +38,12 @@ func (Planet) Hooks() []ent.Hook { func (Planet) Policy() ent.Policy { return privacy.Policy{ - Write: privacy.WritePolicy{ + Mutation: privacy.MutationPolicy{ rule.DenyUpdateRule(), rule.DenyPlanetSelfLinkRule(), privacy.AlwaysAllowRule(), }, - Read: privacy.ReadPolicy{ + Query: privacy.QueryPolicy{ privacy.AlwaysAllowRule(), }, } diff --git a/entc/integration/privacy/rule/rule.go b/entc/integration/privacy/rule/rule.go index 952d70295..c6aa7e18a 100644 --- a/entc/integration/privacy/rule/rule.go +++ b/entc/integration/privacy/rule/rule.go @@ -10,8 +10,8 @@ import ( ) // DenyUpdateRule is a write rule rule that denies update many operations. -func DenyUpdateRule() privacy.WriteRule { - return privacy.WriteRuleFunc(func(_ context.Context, m ent.Mutation) error { +func DenyUpdateRule() privacy.MutationRule { + return privacy.MutationRuleFunc(func(_ context.Context, m ent.Mutation) error { if m.Op() == ent.OpUpdate { return privacy.Denyf("ent/privacy: update operation not allowed") } @@ -20,8 +20,8 @@ func DenyUpdateRule() privacy.WriteRule { } // DenyPlanetSelfLinkRule is a write rule rule that prevents rule self link via neighbor edge. -func DenyPlanetSelfLinkRule() privacy.WriteRule { - return privacy.PlanetWriteRuleFunc(func(ctx context.Context, m *ent.PlanetMutation) error { +func DenyPlanetSelfLinkRule() privacy.MutationRule { + return privacy.PlanetMutationRuleFunc(func(ctx context.Context, m *ent.PlanetMutation) error { if !m.Op().Is(ent.OpUpdateOne) { return privacy.Skip } diff --git a/entc/integration/template/ent/privacy/privacy.go b/entc/integration/template/ent/privacy/privacy.go index ea20c39f6..b73eab850 100644 --- a/entc/integration/template/ent/privacy/privacy.go +++ b/entc/integration/template/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,118 +102,118 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The GroupReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type GroupReadRuleFunc func(context.Context, *ent.Group) error +// The GroupQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type GroupQueryRuleFunc func(context.Context, *ent.GroupQuery) error -// EvalRead calls f(ctx, v). -func (f GroupReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Group); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f GroupQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.GroupQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Group", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.GroupQuery", q) } -// The GroupWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type GroupWriteRuleFunc func(context.Context, *ent.GroupMutation) error +// The GroupMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type GroupMutationRuleFunc func(context.Context, *ent.GroupMutation) error -// EvalWrite calls f(ctx, m). -func (f GroupWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f GroupMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.GroupMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.GroupMutation", m) } -// The PetReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type PetReadRuleFunc func(context.Context, *ent.Pet) error +// The PetQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type PetQueryRuleFunc func(context.Context, *ent.PetQuery) error -// EvalRead calls f(ctx, v). -func (f PetReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Pet); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f PetQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.PetQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Pet", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.PetQuery", q) } -// The PetWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type PetWriteRuleFunc func(context.Context, *ent.PetMutation) error +// The PetMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type PetMutationRuleFunc func(context.Context, *ent.PetMutation) error -// EvalWrite calls f(ctx, m). -func (f PetWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f PetMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.PetMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.PetMutation", m) } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) } diff --git a/examples/edgeindex/ent/privacy/privacy.go b/examples/edgeindex/ent/privacy/privacy.go index 04c05d0c3..92282823d 100644 --- a/examples/edgeindex/ent/privacy/privacy.go +++ b/examples/edgeindex/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,94 +102,94 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The CityReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type CityReadRuleFunc func(context.Context, *ent.City) error +// The CityQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type CityQueryRuleFunc func(context.Context, *ent.CityQuery) error -// EvalRead calls f(ctx, v). -func (f CityReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.City); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f CityQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.CityQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.City", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.CityQuery", q) } -// The CityWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type CityWriteRuleFunc func(context.Context, *ent.CityMutation) error +// The CityMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type CityMutationRuleFunc func(context.Context, *ent.CityMutation) error -// EvalWrite calls f(ctx, m). -func (f CityWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f CityMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.CityMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CityMutation", m) } -// The StreetReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type StreetReadRuleFunc func(context.Context, *ent.Street) error +// The StreetQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type StreetQueryRuleFunc func(context.Context, *ent.StreetQuery) error -// EvalRead calls f(ctx, v). -func (f StreetReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Street); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f StreetQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.StreetQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Street", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.StreetQuery", q) } -// The StreetWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type StreetWriteRuleFunc func(context.Context, *ent.StreetMutation) error +// The StreetMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type StreetMutationRuleFunc func(context.Context, *ent.StreetMutation) error -// EvalWrite calls f(ctx, m). -func (f StreetWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f StreetMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.StreetMutation); ok { return f(ctx, m) } diff --git a/examples/entcpkg/ent/privacy/privacy.go b/examples/entcpkg/ent/privacy/privacy.go index f6085f7a8..f6bdba5c6 100644 --- a/examples/entcpkg/ent/privacy/privacy.go +++ b/examples/entcpkg/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,70 +102,70 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) } diff --git a/examples/m2m2types/ent/privacy/privacy.go b/examples/m2m2types/ent/privacy/privacy.go index 8fe06b324..83ecb77c0 100644 --- a/examples/m2m2types/ent/privacy/privacy.go +++ b/examples/m2m2types/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,94 +102,94 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The GroupReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type GroupReadRuleFunc func(context.Context, *ent.Group) error +// The GroupQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type GroupQueryRuleFunc func(context.Context, *ent.GroupQuery) error -// EvalRead calls f(ctx, v). -func (f GroupReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Group); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f GroupQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.GroupQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Group", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.GroupQuery", q) } -// The GroupWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type GroupWriteRuleFunc func(context.Context, *ent.GroupMutation) error +// The GroupMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type GroupMutationRuleFunc func(context.Context, *ent.GroupMutation) error -// EvalWrite calls f(ctx, m). -func (f GroupWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f GroupMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.GroupMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.GroupMutation", m) } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) } diff --git a/examples/m2mbidi/ent/privacy/privacy.go b/examples/m2mbidi/ent/privacy/privacy.go index ecea900c9..809abd6cc 100644 --- a/examples/m2mbidi/ent/privacy/privacy.go +++ b/examples/m2mbidi/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,70 +102,70 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) } diff --git a/examples/m2mrecur/ent/privacy/privacy.go b/examples/m2mrecur/ent/privacy/privacy.go index 82089606e..40f597ad2 100644 --- a/examples/m2mrecur/ent/privacy/privacy.go +++ b/examples/m2mrecur/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,70 +102,70 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) } diff --git a/examples/o2m2types/ent/privacy/privacy.go b/examples/o2m2types/ent/privacy/privacy.go index 0b4dd1a6d..ec598e9a5 100644 --- a/examples/o2m2types/ent/privacy/privacy.go +++ b/examples/o2m2types/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,94 +102,94 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The PetReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type PetReadRuleFunc func(context.Context, *ent.Pet) error +// The PetQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type PetQueryRuleFunc func(context.Context, *ent.PetQuery) error -// EvalRead calls f(ctx, v). -func (f PetReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Pet); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f PetQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.PetQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Pet", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.PetQuery", q) } -// The PetWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type PetWriteRuleFunc func(context.Context, *ent.PetMutation) error +// The PetMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type PetMutationRuleFunc func(context.Context, *ent.PetMutation) error -// EvalWrite calls f(ctx, m). -func (f PetWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f PetMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.PetMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.PetMutation", m) } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) } diff --git a/examples/o2mrecur/ent/privacy/privacy.go b/examples/o2mrecur/ent/privacy/privacy.go index 7331ad58a..b53755065 100644 --- a/examples/o2mrecur/ent/privacy/privacy.go +++ b/examples/o2mrecur/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,70 +102,70 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The NodeReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type NodeReadRuleFunc func(context.Context, *ent.Node) error +// The NodeQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type NodeQueryRuleFunc func(context.Context, *ent.NodeQuery) error -// EvalRead calls f(ctx, v). -func (f NodeReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Node); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f NodeQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.NodeQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Node", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.NodeQuery", q) } -// The NodeWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type NodeWriteRuleFunc func(context.Context, *ent.NodeMutation) error +// The NodeMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type NodeMutationRuleFunc func(context.Context, *ent.NodeMutation) error -// EvalWrite calls f(ctx, m). -func (f NodeWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f NodeMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.NodeMutation); ok { return f(ctx, m) } diff --git a/examples/o2o2types/ent/privacy/privacy.go b/examples/o2o2types/ent/privacy/privacy.go index ea1a0e8a9..e6e228348 100644 --- a/examples/o2o2types/ent/privacy/privacy.go +++ b/examples/o2o2types/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,94 +102,94 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The CardReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type CardReadRuleFunc func(context.Context, *ent.Card) error +// The CardQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type CardQueryRuleFunc func(context.Context, *ent.CardQuery) error -// EvalRead calls f(ctx, v). -func (f CardReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Card); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f CardQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.CardQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Card", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.CardQuery", q) } -// The CardWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type CardWriteRuleFunc func(context.Context, *ent.CardMutation) error +// The CardMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type CardMutationRuleFunc func(context.Context, *ent.CardMutation) error -// EvalWrite calls f(ctx, m). -func (f CardWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f CardMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.CardMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CardMutation", m) } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) } diff --git a/examples/o2obidi/ent/privacy/privacy.go b/examples/o2obidi/ent/privacy/privacy.go index 51c7ff92f..60f689d38 100644 --- a/examples/o2obidi/ent/privacy/privacy.go +++ b/examples/o2obidi/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,70 +102,70 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) } diff --git a/examples/o2orecur/ent/privacy/privacy.go b/examples/o2orecur/ent/privacy/privacy.go index 56bf35e8e..7cb311500 100644 --- a/examples/o2orecur/ent/privacy/privacy.go +++ b/examples/o2orecur/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,70 +102,70 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The NodeReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type NodeReadRuleFunc func(context.Context, *ent.Node) error +// The NodeQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type NodeQueryRuleFunc func(context.Context, *ent.NodeQuery) error -// EvalRead calls f(ctx, v). -func (f NodeReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Node); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f NodeQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.NodeQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Node", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.NodeQuery", q) } -// The NodeWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type NodeWriteRuleFunc func(context.Context, *ent.NodeMutation) error +// The NodeMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type NodeMutationRuleFunc func(context.Context, *ent.NodeMutation) error -// EvalWrite calls f(ctx, m). -func (f NodeWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f NodeMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.NodeMutation); ok { return f(ctx, m) } diff --git a/examples/start/ent/privacy/privacy.go b/examples/start/ent/privacy/privacy.go index d89909e46..3c3873531 100644 --- a/examples/start/ent/privacy/privacy.go +++ b/examples/start/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,118 +102,118 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The CarReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type CarReadRuleFunc func(context.Context, *ent.Car) error +// The CarQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type CarQueryRuleFunc func(context.Context, *ent.CarQuery) error -// EvalRead calls f(ctx, v). -func (f CarReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Car); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f CarQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.CarQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Car", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.CarQuery", q) } -// The CarWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type CarWriteRuleFunc func(context.Context, *ent.CarMutation) error +// The CarMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type CarMutationRuleFunc func(context.Context, *ent.CarMutation) error -// EvalWrite calls f(ctx, m). -func (f CarWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f CarMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.CarMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.CarMutation", m) } -// The GroupReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type GroupReadRuleFunc func(context.Context, *ent.Group) error +// The GroupQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type GroupQueryRuleFunc func(context.Context, *ent.GroupQuery) error -// EvalRead calls f(ctx, v). -func (f GroupReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Group); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f GroupQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.GroupQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Group", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.GroupQuery", q) } -// The GroupWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type GroupWriteRuleFunc func(context.Context, *ent.GroupMutation) error +// The GroupMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type GroupMutationRuleFunc func(context.Context, *ent.GroupMutation) error -// EvalWrite calls f(ctx, m). -func (f GroupWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f GroupMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.GroupMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.GroupMutation", m) } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) } diff --git a/examples/traversal/ent/privacy/privacy.go b/examples/traversal/ent/privacy/privacy.go index 967185bd9..548303364 100644 --- a/examples/traversal/ent/privacy/privacy.go +++ b/examples/traversal/ent/privacy/privacy.go @@ -15,15 +15,15 @@ import ( ) var ( - // Allow may be returned by read/write rules to indicate that the policy + // Allow may be returned by rules to indicate that the policy // evaluation should terminate with an allow decision. Allow = errors.New("ent/privacy: allow rule") - // Deny may be returned by read/write rules to indicate that the policy + // Deny may be returned by rules to indicate that the policy // evaluation should terminate with an deny decision. Deny = errors.New("ent/privacy: deny rule") - // Skip may be returned by read/write rules to indicate that the policy + // Skip may be returned by rules to indicate that the policy // evaluation should continue to the next rule. Skip = errors.New("ent/privacy: skip rule") ) @@ -44,19 +44,20 @@ func Skipf(format string, a ...interface{}) error { } type ( - // ReadPolicy combines multiple read rules into a single policy. - ReadPolicy []ReadRule + // QueryPolicy combines multiple query rules into a single policy. + QueryPolicy []QueryRule - // ReadRule defines the interface deciding whether a read is allowed. - ReadRule interface { - EvalRead(context.Context, ent.Value) error + // QueryRule defines the interface deciding whether a + // query is allowed and optionally modify it. + QueryRule interface { + EvalQuery(context.Context, ent.Query) error } ) -// EvalRead evaluates a load against a read policy. -func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { +// EvalQuery evaluates a query against a query policy. +func (policy QueryPolicy) EvalQuery(ctx context.Context, q ent.Query) error { for _, rule := range policy { - switch err := rule.EvalRead(ctx, v); { + switch err := rule.EvalQuery(ctx, q); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -67,29 +68,30 @@ func (policy ReadPolicy) EvalRead(ctx context.Context, v ent.Value) error { return nil } -// ReadRuleFunc type is an adapter to allow the use of -// ordinary functions as read rules. -type ReadRuleFunc func(context.Context, ent.Value) error +// QueryRuleFunc type is an adapter to allow the use of +// ordinary functions as query rules. +type QueryRuleFunc func(context.Context, ent.Query) error -// Eval calls f(ctx, v). -func (f ReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - return f(ctx, v) +// Eval returns f(ctx, q). +func (f QueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + return f(ctx, q) } type ( - // WritePolicy combines multiple write rules into a single policy. - WritePolicy []WriteRule + // MutationPolicy combines multiple mutation rules into a single policy. + MutationPolicy []MutationRule - // WriteRule defines the interface deciding whether a write is allowed. - WriteRule interface { - EvalWrite(context.Context, ent.Mutation) error + // MutationRule defines the interface deciding whether a + // mutation is allowed and optionally modify it. + MutationRule interface { + EvalMutation(context.Context, ent.Mutation) error } ) -// EvalWrite evaluates a mutation against a write policy. -func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation evaluates a mutation against a mutation policy. +func (policy MutationPolicy) EvalMutation(ctx context.Context, m ent.Mutation) error { for _, rule := range policy { - switch err := rule.EvalWrite(ctx, m); { + switch err := rule.EvalMutation(ctx, m); { case err == nil || errors.Is(err, Skip): case errors.Is(err, Allow): return nil @@ -100,118 +102,118 @@ func (policy WritePolicy) EvalWrite(ctx context.Context, m ent.Mutation) error { return nil } -// WriteRuleFunc type is an adapter to allow the use of -// ordinary functions as write rules. -type WriteRuleFunc func(context.Context, ent.Mutation) error +// MutationRuleFunc type is an adapter to allow the use of +// ordinary functions as mutation rules. +type MutationRuleFunc func(context.Context, ent.Mutation) error -// Eval calls f(ctx, m). -func (f WriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation returns f(ctx, m). +func (f MutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { return f(ctx, m) } -// Policy groups read and write policies. +// Policy groups query and mutation policies. type Policy struct { - Read ReadPolicy - Write WritePolicy + Query QueryPolicy + Mutation MutationPolicy } -// EvalRead forwards evaluation to read policy. -func (policy Policy) EvalRead(ctx context.Context, v ent.Value) error { - return policy.Read.EvalRead(ctx, v) +// EvalQuery forwards evaluation to query policy. +func (policy Policy) EvalQuery(ctx context.Context, q ent.Query) error { + return policy.Query.EvalQuery(ctx, q) } -// EvalWrite forwards evaluation to write policy. -func (policy Policy) EvalWrite(ctx context.Context, m ent.Mutation) error { - return policy.Write.EvalWrite(ctx, m) +// EvalMutation forwards evaluation to mutation policy. +func (policy Policy) EvalMutation(ctx context.Context, m ent.Mutation) error { + return policy.Mutation.EvalMutation(ctx, m) } -// ReadWriteRule is the interface that groups read and write rules. -type ReadWriteRule interface { - ReadRule - WriteRule +// QueryMutationRule is the interface that groups query and mutation rules. +type QueryMutationRule interface { + QueryRule + MutationRule } -// AlwaysAllowRule returns a read/write rule that returns an allow decision. -func AlwaysAllowRule() ReadWriteRule { +// AlwaysAllowRule returns a rule that returns an allow decision. +func AlwaysAllowRule() QueryMutationRule { return fixedDecisionRule{Allow} } -// AlwaysDenyRule returns a read/write rule that returns a deny decision. -func AlwaysDenyRule() ReadWriteRule { +// AlwaysDenyRule returns a rule that returns a deny decision. +func AlwaysDenyRule() QueryMutationRule { return fixedDecisionRule{Deny} } type fixedDecisionRule struct{ err error } -func (f fixedDecisionRule) EvalRead(context.Context, ent.Value) error { return f.err } -func (f fixedDecisionRule) EvalWrite(context.Context, ent.Mutation) error { return f.err } +func (f fixedDecisionRule) EvalQuery(context.Context, ent.Query) error { return f.err } +func (f fixedDecisionRule) EvalMutation(context.Context, ent.Mutation) error { return f.err } -// The GroupReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type GroupReadRuleFunc func(context.Context, *ent.Group) error +// The GroupQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type GroupQueryRuleFunc func(context.Context, *ent.GroupQuery) error -// EvalRead calls f(ctx, v). -func (f GroupReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Group); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f GroupQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.GroupQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Group", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.GroupQuery", q) } -// The GroupWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type GroupWriteRuleFunc func(context.Context, *ent.GroupMutation) error +// The GroupMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type GroupMutationRuleFunc func(context.Context, *ent.GroupMutation) error -// EvalWrite calls f(ctx, m). -func (f GroupWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f GroupMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.GroupMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.GroupMutation", m) } -// The PetReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type PetReadRuleFunc func(context.Context, *ent.Pet) error +// The PetQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type PetQueryRuleFunc func(context.Context, *ent.PetQuery) error -// EvalRead calls f(ctx, v). -func (f PetReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.Pet); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f PetQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.PetQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.Pet", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.PetQuery", q) } -// The PetWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type PetWriteRuleFunc func(context.Context, *ent.PetMutation) error +// The PetMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type PetMutationRuleFunc func(context.Context, *ent.PetMutation) error -// EvalWrite calls f(ctx, m). -func (f PetWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f PetMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.PetMutation); ok { return f(ctx, m) } return Denyf("ent/privacy: unexpected mutation type %T, expect *ent.PetMutation", m) } -// The UserReadRuleFunc type is an adapter to allow the use of ordinary -// functions as a read rule. -type UserReadRuleFunc func(context.Context, *ent.User) error +// The UserQueryRuleFunc type is an adapter to allow the use of ordinary +// functions as a query rule. +type UserQueryRuleFunc func(context.Context, *ent.UserQuery) error -// EvalRead calls f(ctx, v). -func (f UserReadRuleFunc) EvalRead(ctx context.Context, v ent.Value) error { - if v, ok := v.(*ent.User); ok { - return f(ctx, v) +// EvalQuery return f(ctx, q). +func (f UserQueryRuleFunc) EvalQuery(ctx context.Context, q ent.Query) error { + if q, ok := q.(*ent.UserQuery); ok { + return f(ctx, q) } - return Denyf("ent/privacy: unexpected value type %T, expect *ent.User", v) + return Denyf("ent/privacy: unexpected query type %T, expect *ent.UserQuery", q) } -// The UserWriteRuleFunc type is an adapter to allow the use of ordinary -// functions as a write rule. -type UserWriteRuleFunc func(context.Context, *ent.UserMutation) error +// The UserMutationRuleFunc type is an adapter to allow the use of ordinary +// functions as a mutation rule. +type UserMutationRuleFunc func(context.Context, *ent.UserMutation) error -// EvalWrite calls f(ctx, m). -func (f UserWriteRuleFunc) EvalWrite(ctx context.Context, m ent.Mutation) error { +// EvalMutation calls f(ctx, m). +func (f UserMutationRuleFunc) EvalMutation(ctx context.Context, m ent.Mutation) error { if m, ok := m.(*ent.UserMutation); ok { return f(ctx, m) }