涉及 .getPriority() 的 Firebase 安全规则有问题 [英] Trouble with Firebase security rule involving .getPriority()

查看:26
本文介绍了涉及 .getPriority() 的 Firebase 安全规则有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让用户使用ref.setPriority(priority);"设置项目的优先级但我也想确保他们不能将其设置为小于current_priority -10".

I'm trying to let user set the priority of an item with "ref.setPriority(priority);" but I also want to make sure they can't set it to less than "current_priority -10".

但是这个表达:

".write": "data.getPriority() - newData.getPriority() > 10"

给我一个错误表达式:左操作数不是数字".

is giving me an error "expression: left operand is not a number".

然而:

data.getPriority().length - newData.getPriority().length >=1

某种工作(保存时没有错误,但在我尝试设置优先级时给了我权限被拒绝")

Sort of works (no errors on saving but gives me 'permission denied' when I try to set the priority)

Firebase 是否假定优先级不是数字?如果是这样,有没有办法解决这个问题?

Does Firebase assume the priority is not a number? If so, is there a way to get around that?

我将从 Firebase 添加一个项目的实际 JSON:

I'll add the actual JSON from Firebase for one item:

"http_www_latimes_com_local_lanow_la_me_ln_two_police_officers_shot_in_inglewood_20131127_0_1591070_story_track_rss" : {
  ".priority" : 4458.0,
  "date" : 1385616825,
  "url" : "http://www.latimes.com/local/lanow/la-me-ln-two-police-officers-shot-in-inglewood-20131127,0,1591070.story",
  "discuss" : "http://www.reddit.com/r/news/comments/1rlmzy/two_inglewood_police_officers_shot_active_shooter/",
  "small_image" : "http://i.embed.ly/1/display/resize?height=168.75&width=300&url=http%3A%2F%2Fwww.trbimg.com%2Fimg-529660a6%2Fturbine%2Fla-me-ln-two-police-officers-shot-in-inglewood-20131127%2F400%2F16x9&key=6b62489a749d11e1b62e4040d3dc5c07",
  "title" : "Two Inglewood police officers shot; active shooter in area",
  "height" : 168.75,
  "desc" : "Two Inglewood police officers were shot Wednesday afternoon and taken to a local hospital, Inglewood police officials said.",
  "width" : 300,
  "id" : "http_www_latimes_com_local_lanow_la_me_ln_two_police_officers_shot_in_inglewood_20131127_0_1591070_story_track_rss"
},

所以也许它应该是root.getPriority()",我不确定.

so maybe it should be 'root.getPriority()', I'm not sure.

推荐答案

看起来我们的规则验证中存在错误.您尝试的表达式 ("data.getPriority() - newData.getPriority() > 10") 应该是合法的并且可以执行您想要的操作,但目前它被错误地拒绝了.我们已经进行了修复,但要到下周某个时候才会投入生产.给您带来不便敬请谅解!

Looks like there's a bug in our rules validation. The expression you tried ("data.getPriority() - newData.getPriority() > 10") should be legal and do what you want, but it's currently being incorrectly rejected. We've made a fix, but it won't go live to production until sometime next week. Sorry for the inconvenience!

这篇关于涉及 .getPriority() 的 Firebase 安全规则有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆