On Mar 25, 2014, at 8:39 AM, Frederic Yesid Peña Sánchez 
<fredericp...@gmail.com> wrote:

> We need to deploy certain documents for all users on "pmsync_todos" channel, 
> and other documents on a per user basis on each "pmsync_USER" channel.
> Trying to understand the sync function, how could i authorize "pmsync_todosl" 
> channel for all users?

One approach is to use server-side code to add it to the user's admin_channels 
when you register the account.

>                 for(var i = 0; i < doc.pmsync_channels.length; i++){
>                         if(doc.pmsync_usuarios)
>                                 for(var j = 0; j < 
> doc.pmsync_usuarios.lenght; j++)
>                                         
> access(doc.pmsync_channels[i],doc.pmsync_usuarios[j]);
>                         if(doc.pmsync_usuario)
>                                 access(doc.pmsync_channels[i], 
> doc.pmsync_usuario);
>                 }

You can actually simplify this entire block down to
        access(doc.pmsync_channels, doc.pmsync_usuarios);
since the 'access' function allows either parameter to be an array of strings 
and will iterate over them.

> My current approach for enabling access to all users for channel is to create 
> a document for each user, using the "pmsync_todos" channel.
> {
>       "pmsync_channels":["pmsync-todos"],
>       "pmsync_usuario":"pmsync-rafael"
> }

That will work. The app can create such a document on the first launch and then 
push it to the server.

Just be aware that this approach allows anyone to give anyone access to any 
channel, so it doesn't allow you to use channels for access control. If you 
need that, you'll have to add validation to the sync function so documents 
can't set up illegal access.

--Jens

-- 
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 mobile-couchbase+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/6CAD1B5D-C988-4516-A255-2908C87217E1%40couchbase.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to