Cloud Firestore安全规则 - 文档中的单个受保护字段

k0f*_*f33 5 firebase firebase-security google-cloud-firestore

我想suspendedProfile在一个user文档中调用一个只读属性,其中所有其他属性都具有当前登录用户的读/写访问权限.有没有办法用简单的安全规则来做到这一点?

我想到了两个解决方案:

  1. 禁止写入修改属性,如 allow write: if request.resource.data.suspendedProfile == null;
  2. 一个/secure与集合allow read;内部user文件

我认为第一个选项是更好的所有与用户相关的属性都在一个单独的文件中,但我很想听听你的想法.有没有其他更简单的方法来实现这一目标?

k0f*_*f33 6

我想我设法使用Firebase文档为我自己的答案找到了解决方案.

// A user can update a product reviews, but they can't change
// the headline.
// Also, they should only be able up update their own product review,
// and they still have to list themselves as an author
allow update: if request.resource.data.headline == resource.data.headline
                    && resource.data.authorID == request.auth.userID
                    && request.resource.data.authorID == request.auth.userID;
Run Code Online (Sandbox Code Playgroud)

所以在我的情况下,我会 allow update: if request.resource.data.suspendedProfile == resource.data.suspendedProfile