问题
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.
回答1:
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!
来源:https://stackoverflow.com/questions/20255224/trouble-with-firebase-security-rule-involving-getpriority