amazon-web-services - 如何允许属于“Store”模型的“editor”字段的用户编辑其他模型中的数据
问题描述
我在放大 graphql 模式中创建了一个名为“Store”的模型,如下所示。
type Store
@model(timestamps: {createdAt: "createdAt", updatedAt: "updatedAt"})
@auth(
rules: [
{allow: owner}
{allow: owner, ownerField: "employees", operations: [read, update]}
{allow: private, operations: [read]}
]
) {
id: ID!
name: String
email: String
phone: String
address: String
state: Int!
employees: [String]
@auth(rules: [{allow: owner, operations: [create, update, read, delete]}])
products: [Product]
@connection(keyName: "byStoreToProduct", fields: ["id"])
@auth(
rules: [
{allow: owner}
{allow: owner, ownerField: "employees"}
{allow: private, operations: [read]}
]
)
}
我想通过模型中的“manager”字段来设置用户管理店铺的权限,并创建一个如下图的“Product”模型,这样就可以注册产品了。
type Product
@model(timestamps: {createdAt: "createdAt", updatedAt: "updatedAt"})
@key(name: "byStoreToProduct", fields: ["storeID", "id"]) {
id: ID!
name: String
storeID: ID!
state: Int!
}
这种情况下,只有“Store”模型的“manager”字段对应的用户才能编辑“Product”模型中的数据,一般用户只能查到值。
解决方案
推荐阅读
- prolog - 用序言消除列表元素的连续重复
- excel - 用条件求时间差的公式
- flutter - 如何实现这张图片的下拉刷新和上拉加载更多功能?
- c - CMake 忽略自定义工具链文件。(缓存被清理)
- java - 如何在改造中处理错误空体?
- python-3.x - 在三重高斯拟合期间,初始猜测值和高卡方值相差很大
- json - 斯威夫特,无法读取数据,因为它的格式不正确
- linux - 在 WSL2 openSUSE-Leap-15.2 环境中,为 xrdp 和 systemd-modules-load / auditd 正确设置 sudoers 用户/会话失败
- relational-database - Loopback 4删除关系
- python-3.x - python 3 if..elif 不会打印