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

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

问题描述

我试图让用户用ref.setPriority(priority)来设置一个项目的优先级,但是我也想确保它们不能设置成小于current_priority -10。

但是这个表达式:

pre $ 。write:data.getPriority() - newData.getPriority()> 10

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

然而:

$ p $ data $ get_priority()。length - newData .getPriority()。length> = 1

当我尝试设置优先级时,权限被拒绝)

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



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

 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,
讨论: 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-两个警察人员 - 射中 - 英格伍德-20131127%2F400%2F16x9和放大器; key = 6b62489a749d11e1b62e4040d3dc5c07,
title:两名英格尔伍德警察枪杀,主动射手在地区,
身高:168.75,
desc:被星期三击中英格伍德警方官员说:
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()',我不确定。

解决方案

看起来像我们的规则验证有一个错误。你试过的表达式(data.getPriority() - newData.getPriority()> 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".

But this expression:

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

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

However:

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)

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

EDIT: 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"
},

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

解决方案

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!

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

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