【发布时间】:2020-06-20 19:14:11
【问题描述】:
我正在开发一个需要对特定表具有自定义权限的应用。我有以下数据结构:
Users
-> id
-> name
Accounts
-> id
-> name
UserAccounts
-> userId
-> accountId
-> permissionLevel
permissionLevel 是一个枚举,可以是:Owner、ReadAndWrite 或 ReadOnly。
我想要的是:
1) 如果您是UserAccount 的Owner,您可以邀请其他用户。
2)如果你想创建一个新的Account,你将在UserAccounts中获得Owner的权限。
3) 当您不是上述Account 的Owner 时,您不能将自己添加到UserAccounts。
我遇到的问题是我不确定如何在 Hasura 中解决这个问题。我尝试了以下 Hasura 权限(但我缺少扩展 where 子句的选项(见下文)):
{
"_or": [
{
"_and": [
{
"accountId": {
"_is_null": false
}
},
{
"Account": {
"UserAccounts": {
"_and": [
{
"userId": {
"_eq": "X-Hasura-User-Id"
}
},
{
"permissionLevel": {
"_eq": "Owner"
}
}
]
}
}
}
]
},
{
"_not": {
"_exists": {
"_table": {
"name": "Account",
"schema": "public"
},
"_where": {
"UserAccounts": {
"accountId": {
"_eq": "$accountIdFromQuery" // <-- this does not exist AFAIK
}
}
}
}
}
}
]
}
所以我不知道该往哪个方向走。也许我只是遗漏了一些东西,也许我需要使用自定义 view 或者我需要尝试自定义 postgresql 函数。非常感谢任何帮助!
【问题讨论】:
标签: permissions hasura