【发布时间】:2018-08-21 00:56:21
【问题描述】:
我正在尝试根据request.time 创建安全规则,如AngularFirebase website 上的示例中给出的那样。
我的功能是
function isThrottled() {
return request.time < resource.data.lastUpdate + duration.value(1, 'm')
}
我正在尝试allow update: if isThrottled() == false
但是,当我尝试使用此规则更新文档时,由于未在对象上定义 时间 而失败。
错误:simulator.rules 行 [169],列 [12]。属性时间是 对象上未定义。
不应该每个请求都附加一个time 或TimeStamp 吗?这与我初始化 Cloud Functions 或客户端应用程序的方式有关吗?
以下截图:
编辑
其余更新安全规则的 sn-p 是:
service cloud.firestore {
match /databases/{db}/documents {
match /users/{userId} {
match /username/{id} {
allow update: if isSelf(userId)
&& usernameAvailable(incomingData().username)
&& incomingData().username is string
&& incomingData().username.size() <= 25
&& incomingFields().size() == 1
&& isThrottled() == false;
}
}
function incomingData() {
return request.resource.data
}
function isThrottled() {
return request.time < resource.data.lastUpdate + duration.value(1, 'm')
}
function incomingFields() {
return incomingData().keys()
}
function isSelf(userId) {
return userId == currentUser().uid;
}
function usernameAvailable(username) {
return !exists(/databases/$(db)/documents/usernames/$(username));
}
}
}
username 集合是每个user 文档下的子集合(在users 根集合中。每个username 文档只有一个名为username 的字段供用户更新)。
【问题讨论】:
-
请编辑问题以显示存在此问题的整个最小规则集(不仅仅是屏幕截图,请将它们粘贴到问题中)。
-
我更新了我的问题,向您展示了我对这个特定更新检查的规则
标签: google-cloud-firestore firebase-security