Hi,
I'm just digging in to rules for the first time, and I'll say up front that I have a bad feeling that the answer to my question here is going to be "you have to re-structure your data", but I'm going to ask it anyway.
We have an app where data is shared between teacher and students. We want a teacher to be able to create a shared classroom, add course content to that classroom, and then allow students to add responses to the classroom. So, imagine a structure like this:
"classrooms": {
"classroom1": {
"teacherId": "asdfg",
"content": {
},
"responses": {
}
}
}
So imagine that I want a teacher to be able to create an empty "classroom1" node, but then I want the teacher to be able to write to "content", and teacher and students to be able to write to "responses". So for the content node, the rule would be something like (some pseudo-code below to keep things simple):
".write": "auth.uid === ${teacherId}"
...and then the responses node would be something like:
".write": "auth !== null"
That by itself seems, at least in theory, relatively simple, but then I'm stuck about what to do at the root level of "classrooms". I understand that rules cascade, with shallower ones taking precedence over deeper ones, but I have to define *some* kind of rule at the root level of "classrooms", or no data would be writeable at that node or any child nodes. What I want to say in general is something like "write a new classroom if none exists, but only if you're authenticated (assuming authenticated means you are a teacher for now), and once a classroom is written, then observe new write rules for the children". Is this even possible, or do I have to re-structure my data?
Thanks in advance for any advice!
Ben