简体   繁体   English

如何设置我的 hasura 权限以仅查看与用户对应的表行?

[英]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那么,我想要

  • a user with rex permission to see all the orders table's rows具有查看所有orders表行的rex权限的用户
  • a user with 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM