Sharing data between users

595 views
Skip to first unread message

Michael Cadelago

unread,
Feb 20, 2016, 5:01:16 AM2/20/16
to Firebase Google Group
I searched through previous posts but couldn't find something that quite answered my question. Sorry if this has been covered before.

I'm trying to understand the best way to design my firebase in order to allow users to share and collaborate on sets of data. Let me use a ToDo type example (think Wunderlist) to explain what I'm trying to wrap my head around:

1. a user can authenticate and create a todo list
2. they can add and remove tasks from the list
3. they can add other users to those lists so they can all collaborate together
4. a user can see a list of users who are collaborators on the list

Here's how I would imagine I would set it up

1. create a users location with read/write permissions defined on the $user key so users can only see their own user object.
2. create a /lists location that will store all lists
3. include an array of owned list keys in the user object so the authenticated user can grab all the lists their a member of (because I don't want to add read permissions to the entire /lists location)
4. access to each $list key would be based on matching the user's ID to some sort of owner property on the list object (basically like an array of owners since there would be multiple?)

There are a couple issues that I'm having trouble getting around:

1. without true pk/fk style mapping between tables, how do I deal with a situation where user 1 and user 2 are both members of the same list and user 1 deletes the list? Would I need to handle the cleanup client side for all the other users?
2. is it even possible for me to define my read/write access based on whether an "array" contains the current user's ID? Would I need to basically stringify the owners array and use regex in my security config to handle read/write access?
3. This design just feels messy

I'm brand new to firebase so maybe I'm just totally missing some simple solution.



Jay

unread,
Feb 22, 2016, 3:22:38 PM2/22/16
to Firebase Google Group
(conceptual structure)

users
   uid_0
      name: Pete
   uid_1
      name: Ralph
   uid_2
      name: Dave

todo
     id_0
        name: To Do List 0
        owner: uid_0
        peeps:
            uid_1: true
            uid_2: true
     id_1
        name: To Do List 1
        owner: uid_1
        peeps:
           uid_2: true
     id_2
        name: To do List 2
        owner: uid_2

I assumed each todo would have an owner so I added that node

In the above structure, a rule could be put into place that would allow the owner to read/write/delete

An rule could also allow users in the todo/id_x/peeps node to read and write but not delete (or any combination)

In the case the rule is in place that would allow folks in the peeps node to delete, if they delete the node, then it deletes everything in the node so no cleanup is necessary. You app would be observing the todo parent node so when the change occurs, the app is notified so it can remove that node from the client.

Reply all
Reply to author
Forward
0 new messages