Hi Christop,
 

>  But if I am not mistaken it doesn't handle removal of users because the 
> already removed user and his channel don't get overwritten once the user is 
> removed. We could identify the removed users as a difference of old doc and 
> doc but then we cannot remove access of the other users of that channel?
>

Yes, this is indeed a problem. I have spoken about a possible solution in a 
similar setting at a Couchbase meetup in London 
(https://spraed.net/spraeds/0029b75c84b8, starting from slide 35, 
https://www.youtube.com/watch?v=T2wl7363hws). Maybe this is already helpful 
to you.

Otherwise, I might have a possible solution for your problem which I will 
briefly outline below. Maybe there is a better way of doing it, but I have 
none for the moment :

When a new user is added to a project, you create for every user and every 
other user of the project a new document with content 

{

type : 'user-doc' 

userId1 : 'xxx',

userId2 : 'yyy',

delete : false

}

When you create this document, the sync function will give userId1 access 
to the channel of userId2:

function(doc) {

case 'user-doc':

channel('user_'+doc. <http://doc.id/>userId1); //add the user-doc to the 
channel of the first user

if (!doc.delete) {

access(doc. <http://doc.id/>userId1,[ 'user_'+doc. <http://doc.id/>userId2 ]); 
//give the user access to the channel of the other user 

}

break; 

}

This means that the user-doc decides which user has access to which other 
user profiles. So if there are 3 user in a project, you need to create 
3x2=6 user-docs in total.

Now, when you remove a user from a project, you update the corresponding 
delete-property in all user-docs which are concerned:

{

type : 'user-doc' 

userId1 : 'xxx',

userId2 : 'yyy',

delete : true 

}

The Sync function will now remove the channel containing the profile of 
user 2 from the list of user1's channels.
However, you still have the profile of user2 in user1's CBLite instance. 
Therefore, you will need to listen for this document change in your app and 
manually remove the profile from CBLite,

In other words, you use the user-doc to signal to your app that a profile 
should be deleted. 


However, a problem with this solution is that (i) the user-doc gets 
replicated although it is not needed anymore and (ii) the solution does not 
work when a user is logged in on multiple devices. To solve (i) you could 
let the app or (your server) delete the user-doc after the user profile was 
deleted. Solving (ii) requires some more effort.

Rather than just having a delete property in the document, you could have 
an array describing which Sync Gateway Session of a user has deleted the 
profile already, e.g.

{

type : 'user-doc' 

userId1 : 'xxx',

userId2 : 'yyy',

delete : true,

 sessions : [

{ sessionId : '1', removed : true}, { sessionId : '2', removed : false}

]

}

When an app removes a user profile, it will validate the sessions entry 
corresponding to its sessionId (e.g., its Sync Gateway Session Cookie). 
Only when all sessionIds in the array are validated. Sync Gateway will 
remove the user-doc from the user channel and you could deleted it from the 
data base.


I know this is a bit complicated but it should work. Let me know if 
anything is unclear with this solution or if you have an idea of how to 
improve it.

Another option could be to have document for every user which simply 
contains a list of all user profiles to which the user access. The Sync 
function would then use this document to give a user access to the channels 
containing the profiles. When a user is deleted from the list, the sync 
function revokes access to the channel. However, to delete it from CBLite, 
you needed to listen do changes in this document and remove the profile 
locally.

Cheers,

Jakob




-- 
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/ff001768-2c5e-4a41-9ab2-a6b8507e4ae9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to