[英]How do I set my hasura permission to only see the rows of my table corresponding to a user?
Here's the thing.事情就是这样。 I have the 3 tables depicted here:我在这里描述了 3 个表:
People on my application can place orders.我的应用程序上的人可以下订单。 Then, I want那么,我想要
rex
permission to see all the orders
table's rows具有查看所有orders
表行的rex
权限的用户delivery
permission to only see the rows of the orders
table that have the zip
column set to the delivery
user's zip
具有delivery
权限的用户只能查看orders
表中zip
列设置为delivery
用户的zip
的行From the orders
table, I can get for each order a zip
.从orders
表中,我可以为每个订单获取一个zip
。 With the table zip_user
, I can get a user_id
out of a zip
.使用表zip_user
,我可以从zip
中获取user_id
。 Out of that user_id
, I can get the delivery user from the users
table.从那个user_id
中,我可以从users
表中获取交付用户。
While it is trivial to get the rex
to see all of the orders
table, I have not yet been able to configure the permissions for the delivery
user.虽然让rex
查看所有orders
表很简单,但我还不能为delivery
用户配置权限。 What do I need to do?我需要做什么?
In other words, given the user performing a select on the orders
table has x-hasura-user-id
set to some user id and x-hasura-role
set to delivery
, how does that user get only the rows from the orders
table that match with the zip
s associated with that user's user_id
?换句话说,假设用户在orders
表上执行 select 将x-hasura-user-id
设置为某个用户 id 并将x-hasura-role
设置为delivery
,那么该用户如何仅从orders
表中获取那些与与该用户的user_id
关联的zip
匹配?
Hasura has the concept of relations. Hasura 有关系的概念。 If you have foreign keys, it makes the relations automatically, if not you can make them yourself in the UI.如果你有外键,它会自动建立关系,如果没有,你可以在 UI 中自己建立。 Once the relationships have been set up, you will be able to set deep permissions, so on the orders
table, you'll be able to use users.id
.建立关系后,您将能够设置深度权限,因此在orders
表上,您将能够使用users.id
。
Start here: https://hasura.io/docs/1.0/graphql/manual/schema/relationships/index.html从这里开始: https://hasura.io/docs/1.0/graphql/manual/schema/relationships/index.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.