Hi,

One option would be to create a channel for every user to which he/she gets 
access.
The channel name is a simple function of the user id, e.g. 'user_'+id. The 
profile document of a user is the only document in this channel

The project document contains an array of the user ids participating in the 
project, e.g. userList. The sync function will give then every user access 
to all other user channels as well as to the channel to the project it 
self..

The sync function could possible look like something like this:

function (doc) {

switch (doc.type) {

case 'profile':

channel('user_'+doc.id); //add the profile to the user channel

access(doc.id,[ 'user_'+doc.id ]); //give the user access to his/her own 
channel

break; 


case 'project':

channel('project_'+doc.id); //create a channel for the project

           for (var i=0; i<doc.userList.length;i++) {

access(doc.userList[i],['project_'+doc.id]); //give each user access to the 
project channel

for (var j=0; j<doc.userList.length;j++) {

if (j !=i ) {

access(doc.userList[i],['user_'+doc.userList[j]]); //give each user access 
to the user channels of all other users 

}  

}

 } 

break;

} 

}


Is this any helpful?

Cheers,

Jakob


On Thursday, April 2, 2015 at 8:46:24 PM UTC+2, Christoph Berlin wrote:
>
> Hi everyone,
>
> we are struggling a bit a little bit with finding a suitable channel 
> structure for our project. Here are the requirements:
>
> 1) Each user has a profile document (first name, last name, user ID, etc.) 
> Those profile documents are initially accessible by the owner only
> 2) A user can create a project (represented by a project document that has 
> a name, members, etc.)
> 3) The owner of the document can invite other users to join the project, 
> in this case the members of the projects get added to the project channel
>
> So that works, the users have access to the project file but how would we 
> enable access to each user profile document so that users can see each 
> other's information?  It seems easy but its not (for us at least)...
>
> Another way to look at it, is the couchbase labs chat app. Instead of 
> having all profile be accessible by everyone, how could we limit exposure 
> by adding the chat profiles into a channel. New members would have to be 
> added via email address...
>
> Attempts: 
> 1) We initially thought that we add those profile documents to the project 
> channel but that doesn't work because the profile document is not aware of 
> all the projects the owner has access. The project file has a member array 
> but the profile documents don't. We could maintain a manual configuration 
> within the profile document (for example memberships) but that seems kind 
> of backwards and hard to maintain.
>
> 2) Another idea was to have the sync function take care of it but that 
> doesn't work because the sync function works on a document basis - meaning 
> only when a document changes it triggers a change. We cannot update a 
> different document than the one who triggered the change. 
>
> 3) Being tired of it we thought about just ignoring the fact of protecting 
> the profile account and making them public but then they all get synced to 
> each device...and that doesn't seem to make sense as well if you have a 
> million profiles...
>
> Does anyone have any ideas how to accomplish this? Any pointer is much 
> appreciated it.
> Christoph
>
> Again: 
>
>
> Project document -> creates project channel with members being able to 
> access
> Profile documents -> profile channel with owner access
>
> How to enable sync for all profile documents of the members in the project.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/32a6308b-f363-4656-8d59-2d22f7b0455f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to